Forum Discussion

yaudje's avatar
yaudje
Frequent Visitor
3 years ago
Solved

Transpose a table

Hi Folks,

 

Im having a hard time transposing the table. Just need the Dax for the  Output Table basis the Source table. Your response will be a big help.

 

Thanks in advance.

  • Hi yaudje ,

     

    This is better done on Power Query using the Unpivot option however in dax you can use the following code:

     

    Table 2 = UNION(
        SELECTCOLUMNS('Table', "Sales", 'Table'[Sales],"Area", 'Table'[Area], "Year", 2019, "value", 'Table'[2019]), 
        SELECTCOLUMNS('Table',"Sales", 'Table'[Sales],"Area", 'Table'[Area], "Year", 2020, "value", 'Table'[2020]),
       SELECTCOLUMNS('Table',"Sales", 'Table'[Sales],"Area", 'Table'[Area], "Year", 2021, "value", 'Table'[2021]))

     

     

     

     

3 Replies

  • Hi yaudje ,

     

    This is better done on Power Query using the Unpivot option however in dax you can use the following code:

     

    Table 2 = UNION(
        SELECTCOLUMNS('Table', "Sales", 'Table'[Sales],"Area", 'Table'[Area], "Year", 2019, "value", 'Table'[2019]), 
        SELECTCOLUMNS('Table',"Sales", 'Table'[Sales],"Area", 'Table'[Area], "Year", 2020, "value", 'Table'[2020]),
       SELECTCOLUMNS('Table',"Sales", 'Table'[Sales],"Area", 'Table'[Area], "Year", 2021, "value", 'Table'[2021]))

     

     

     

     

    • yaudje's avatar
      yaudje
      Frequent Visitor

      SUper thanks. This one works:-) Cheers mate/

      • MFelix's avatar
        MFelix
        Super User

        Don't forget to accept the correct answer so it can help others