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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Columns to Rows.

I have the following data:

 

 name    --   january   --   february --  and so on...

  Foo      --    10          --     72.2      --         ....

  Bar       --     89.1      --     108.4    --         ...

 

 

But, I want to change it to this:

  name  --   month    --    value

    Foo   --   january   --     10     

    Foo   --  february  --     72.2 

          ... all next months

    Bar   --   january    --     89.1

    Bar   --   february  --    108.4

 

 

I want to learn how can I do that using DAX and M? One example using only M and the other using only Dax. 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi caarlos

in Power Query (M) use unpivot other columns.

I never use DAX to solve this as I prefer M

und täglich grüsse das Murmeltier.gif

View solution in original post

Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

Here is a DAX based solution.  I reckon PQ is the better way to go but this is what it might look like in DAX.  I've assumed your table is called Table and the columns are as per your sample

 

Table = 
Var TableMonths = DataTable(
                "MonthName", STRING,{  
                        {"January"},{"February"},{"March"},{"April"},{"May"},{"June"},{"July"},{"August"},{"September"},{"October"},{"November"},{"December"}    
                        }  
                    ) 
Var CrossJoined = CROSSJOIN(Table1,TableMonths)                    
Return    SELECTCOLUMNS( CrossJoined , 
            "Name" , [Name] , 
            "Month" , [MonthName] , 
            "Value" , SWITCH([MonthName] , 
                "January" , [January] ,
                "February" , [February] ,
                "March" , [March] ,
                "April" , [April] ,   
                "May" , [May] ,
                "June" , [June] ,
                "July" , [July] ,
                "August" , [August] ,
                "September" , [September] ,
                "October" , [October] ,
                "November" , [November] ,
                "December" , [December] ,
                BLANK())                )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

Here is a DAX based solution.  I reckon PQ is the better way to go but this is what it might look like in DAX.  I've assumed your table is called Table and the columns are as per your sample

 

Table = 
Var TableMonths = DataTable(
                "MonthName", STRING,{  
                        {"January"},{"February"},{"March"},{"April"},{"May"},{"June"},{"July"},{"August"},{"September"},{"October"},{"November"},{"December"}    
                        }  
                    ) 
Var CrossJoined = CROSSJOIN(Table1,TableMonths)                    
Return    SELECTCOLUMNS( CrossJoined , 
            "Name" , [Name] , 
            "Month" , [MonthName] , 
            "Value" , SWITCH([MonthName] , 
                "January" , [January] ,
                "February" , [February] ,
                "March" , [March] ,
                "April" , [April] ,   
                "May" , [May] ,
                "June" , [June] ,
                "July" , [July] ,
                "August" , [August] ,
                "September" , [September] ,
                "October" , [October] ,
                "November" , [November] ,
                "December" , [December] ,
                BLANK())                )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank you so much for this. It is really helpful and I used this to solve a work problem!!

Anonymous
Not applicable

Thank you, @Phil_Seamark and @Anonymous, both examples worked!

Anonymous
Not applicable

Thank you, @Phil_Seamark and @Anonymous, both examples worked!

Anonymous
Not applicable

Hi caarlos

in Power Query (M) use unpivot other columns.

I never use DAX to solve this as I prefer M

und täglich grüsse das Murmeltier.gif

Anonymous
Not applicable

Thanks to share it. I really appreciated your help.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.