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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ahjamil
Frequent Visitor

Converting Columns to Rows

Hi, 
I need help converting columns to a single column. I have following Table:

GroupJanFebMar
G110109
G2111411
G3101213
G4121112
G511910

and I need to create a new table like the following:

GroupMonthValue
G1Jan10
G2Jan11
G3Jan10
G4Jan12
G5Jan11
G1Feb10
G2Feb14
G3Feb12
G4Feb11
G5Feb9
G1Mar9
G2Mar11
G3Mar13
G4Mar12
G5Mar10


I need this to create a WaterFall Chart that can provide user a selection of months. Please help with a solution.
Thanks in anticipation.

Ahmad

3 ACCEPTED SOLUTIONS
tackytechtom
Super User
Super User

Hi @ahjamil ,

 

Power Query is a fantastic tool to unpivot columns and solve this issue:

tomfox_3-1651300180049.png

 

 

1) You first need to create a duplicate of your table. Right click on the table in the query list on the left and click duplicate.

tomfox_1-1651300085418.png

 

 

2) Right click on the Group column and choose unpviot other columns:

tomfox_0-1651300045552.png

 

3) Double click on the name of the column (Attribute) and rename it to Month:

tomfox_2-1651300159040.png

 

Here the whole M code that you can use in the advanced editor:

tomfox_4-1651300278511.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjdU0lEyNIARlkqxOkBBIxAfLGMCYYFFjeFKwfLGEFETuIAhhAUWNYUJWEI0xcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Group = _t, Jan = _t, Feb = _t, Mar = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Jan", Int64.Type}, {"Feb", Int64.Type}, {"Mar", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Group"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Month"}})
in
    #"Renamed Columns"

 

Does this help? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

If you can go into Power Query Editor, please select a Group Column, and click Transform tab -> Unpivot Other Columns button.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

tackytechtom
Super User
Super User

Hi @ahjamil ,

 

Since you asked here in the DAX Commands and Tips forum, here a possible solution in DAX. Note, if you have the possibility to do it in Power Query, I'd recommend to do it there since the DAX code is not very sunstainable. For instance, next time a new month is added to your table (i.e. April) you need to rewrite the code...

tomfox_0-1651302319942.png

 

DAX:

Table = 
UNION ( 
    SELECTCOLUMNS(Table, "Group", Table[Group], "Month", "Jan", "Value", Table[Jan] ),
    SELECTCOLUMNS(Table, "Group", Table[Group], "Month", "Feb", "Value", Table[Feb] ),
    SELECTCOLUMNS(Table, "Group", Table[Group], "Month", "Mar", "Value", Table[Mar] )
)

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

5 REPLIES 5
tackytechtom
Super User
Super User

Hi @ahjamil ,

 

Since you asked here in the DAX Commands and Tips forum, here a possible solution in DAX. Note, if you have the possibility to do it in Power Query, I'd recommend to do it there since the DAX code is not very sunstainable. For instance, next time a new month is added to your table (i.e. April) you need to rewrite the code...

tomfox_0-1651302319942.png

 

DAX:

Table = 
UNION ( 
    SELECTCOLUMNS(Table, "Group", Table[Group], "Month", "Jan", "Value", Table[Jan] ),
    SELECTCOLUMNS(Table, "Group", Table[Group], "Month", "Feb", "Value", Table[Feb] ),
    SELECTCOLUMNS(Table, "Group", Table[Group], "Month", "Mar", "Value", Table[Mar] )
)

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

This was extremely helpful Tom.
Thank you. 

Jihwan_Kim
Super User
Super User

Hi,

If you can go into Power Query Editor, please select a Group Column, and click Transform tab -> Unpivot Other Columns button.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
tackytechtom
Super User
Super User

Hi @ahjamil ,

 

Power Query is a fantastic tool to unpivot columns and solve this issue:

tomfox_3-1651300180049.png

 

 

1) You first need to create a duplicate of your table. Right click on the table in the query list on the left and click duplicate.

tomfox_1-1651300085418.png

 

 

2) Right click on the Group column and choose unpviot other columns:

tomfox_0-1651300045552.png

 

3) Double click on the name of the column (Attribute) and rename it to Month:

tomfox_2-1651300159040.png

 

Here the whole M code that you can use in the advanced editor:

tomfox_4-1651300278511.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjdU0lEyNIARlkqxOkBBIxAfLGMCYYFFjeFKwfLGEFETuIAhhAUWNYUJWEI0xcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Group = _t, Jan = _t, Feb = _t, Mar = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Jan", Int64.Type}, {"Feb", Int64.Type}, {"Mar", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Group"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Month"}})
in
    #"Renamed Columns"

 

Does this help? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi Tom, 
Thank you for explaining the Power Query solution as well. I have a question that I get additional data in this table monthly, so would the Power Query table refresh data whenever I will refresh the report?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.