Search code examples
sqlpowerbiunpivot

SQL & Power Bi/Query - Turn a column array into columns


sql table

here's some fun. One of our tables has a column, 'Reference Type', which the value is a Variable and the variable's value is in column 'Reference Value'. The key is 'XMLID' and the rest of the columns are associated to that variable.

The problem is we need to supply a value to one Reverence Type in order to get that key, in order to pull all the other variables associated to that key.

I can only query the table, I do not have SQL write privileges, and so am importing the data into Power Bi/Query for manipulation

Is there a way to pivot the Reference Type variables out while keeping all of the associated columns?


Solution

  • The transform you need is called Pivot, eg:

    = Table.Pivot(Source, List.Distinct(Source[ReferenceType]), "ReferenceType", "ReferenceValue")