Search code examples
jsonpowerbipowerquerypowerbi-desktopm

Extracting Pirmary Key columns from pbit file


In the pbit file of Power BI model, in the DataModelSchema json section, in tables and columns there is property "isKey". I assume it emerges when we create 1->∞ relationships. Nevertheless, the TRUE value of that column does not lead us to a real Primary Key column name, but to some system PK column with name i.e., RowNumber-2662979B-1795-4F74-8F37-6A1BA8059B61 which has the same name across all PK columns in all tables. Strange. How to link TRUE isKey columns with the names of their non-system counterparts?

enter image description here


Solution

  • Why don't you get your set of keys from the relationships section. The section below shows a relationship from Table A[Column1] to table B[Column1] and both columns are listed as keys (to support the relationship of course) elsewhere in the .pbit.

      "relationships": [
          {
            "name": "ef91814a-eb7a-457a-a6cf-8644bee5d2d8",
            "fromTable": "B",
            "fromColumn": "Column1",
            "toTable": "A",
            "toColumn": "Column1",
            "state": "ready"
          }
        ],