Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
fmouhcine
Frequent Visitor

DAX : how to convert multiple columns into 2 columns

Dear Community,

 

Will that be possible, using dax, to convert multiple columns in 1 table to only 2 columns ?

 

Example:

I do have a table with the monthly product volume per country, where I do have 1 column per product ID as below:

PeriodCountryProduct_1Product_2Product_3Product_4Product_5
1/1/2023France03560
1/1/2023UK36109
1/1/2023South Africa11370
2/1/2023South Africa00000
3/1/2023South Africa00200

 

and what I want to have is: have 1 column for the product ID & 1 column for the volume - as below:

 

PeriodCountryProductVolume
1/1/2023FranceProduct_10
1/1/2023FranceProduct_23
1/1/2023FranceProduct_35
1/1/2023FranceProduct_46
1/1/2023FranceProduct_50
1/1/2023UKProduct_13
1/1/2023UKProduct_26
1/1/2023UKProduct_31
1/1/2023UKProduct_40
1/1/2023UKProduct_59
1/1/2023South AfricaProduct_11
1/1/2023South AfricaProduct_21
1/1/2023South AfricaProduct_33
1/1/2023South AfricaProduct_47
1/1/2023South AfricaProduct_50
2/1/2023South AfricaProduct_11
2/1/2023South AfricaProduct_21
2/1/2023South AfricaProduct_33
2/1/2023South AfricaProduct_47
2/1/2023South AfricaProduct_50
3/1/2023South AfricaProduct_10
3/1/2023South AfricaProduct_20
3/1/2023South AfricaProduct_32
3/1/2023South AfricaProduct_40
3/1/2023South AfricaProduct_50

 

Thanks in advance for your support

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@fmouhcine , In power query Unpivot columns

 

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

Learn Power BI: Power Query Table.Unpivot, Table.UnpivotOtherColumns: https://youtu.be/0FEGEAz9UMw

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
sevenhills
Super User
Super User

You can try like this

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJW0lFyK0rMS04FMgyAGCRgCsRmYH6sDorKUG+oCpCsIVSHJbqq4PzSkgwFx7SizOREqDpDqD5zuKlGONUbYGCQemOC6o0Q6mMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Period = _t, Country = _t, Product_1 = _t, Product_2 = _t, Product_3 = _t, Product_4 = _t, Product_5 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Period", type date}, {"Country", type text}, {"Product_1", Int64.Type}, {"Product_2", Int64.Type}, {"Product_3", Int64.Type}, {"Product_4", Int64.Type}, {"Product_5", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Period", "Country"}, "Attribute", "Value")
in
    #"Unpivoted Other Columns"

 

Step: Select "Period", "Country" and click Pivot other columns....

 

Output:

sevenhills_0-1696352007256.png

 

 

amitchandak
Super User
Super User

@fmouhcine , In power query Unpivot columns

 

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

Learn Power BI: Power Query Table.Unpivot, Table.UnpivotOtherColumns: https://youtu.be/0FEGEAz9UMw

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak ,

 

Many thanks for the tips ! that's exaclty what I was looking for

Learning from you (dear community) day after day ...

 

Thanks

Mouhcine

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors