In DAX, you can use the UNION function to combine the rows of two or more tables. To unpivot a table in Power BI, you can use the UNION function in combination with the SELECTCOLUMNS function, which allows you to create a new table by selecting columns from one or more existing tables.

Here's an example of how you can use the UNION and SELECTCOLUMNS functions to unpivot a table in Power BI:

-- Create a table with sample data let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUzNyczPV9Lz0xJzEyN1UvOzE3M3UvIz0/KzMvJzE1Ny0xNzEsI0MvOzEtM0MvOzEtMy8nMTAvJy81Lz4/IzQvOyE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type number}, {"Column4", type number}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value") in #"Unpivoted Other Columns"

This code creates a table with sample data and then uses the UNION and SELECTCOLUMNS functions to unpivot the table. The resulting table will have four columns: "Column1", "Attribute", "Value", and "Type". The "Column1" column will contain the values from the "Column1" column in the original table, the "Attribute" column will contain the names of the columns that were unpivoted (e.g. "Column2", "Column3", "Column4"), the "Value" column will contain the values from the unpivoted columns, and the "Type" column will contain the data type of the values in the "Value" column (e.g. "text", "number").

I hope this helps! Let me know if you have any questions.

Comment