Forum Discussion

RichardMo's avatar
RichardMo
Frequent Visitor
3 years ago
Solved

Table structure/modelling issue - cannot get table structure right

I have a fact table like this:    And I want to end up with a matrix visual like this: But I can't figure out how to do it.   I can't unpivot the fact table as some of the date colum...
  • v-yueyunzh-msft's avatar
    3 years ago

    HI , RichardMo 

    According to your description, you want to group by your column , but your columns contains the calculated columns and can not be unpivoted.

    For your need, i think the best way is used dax to unpivot your table.

    My test data is like this:

     

    We can click "New Table" and enter this:

    Table 2 = UNION( SELECTCOLUMNS('Table',"Person ID",[Person ID] , "City",[City] , "Category" , [Category] , "Date", [Booking date] , "Type", "Booking"),
    SELECTCOLUMNS('Table',"Person ID",[Person ID] , "City",[City] , "Category" , [Category] , "Date", [Session 1] , "Type", "Session1")   ,
    SELECTCOLUMNS('Table',"Person ID",[Person ID] , "City",[City] , "Category" , [Category] , "Date", [Session 2] , "Type", "Session2")   ,
    SELECTCOLUMNS('Table',"Person ID",[Person ID] , "City",[City] , "Category" , [Category] , "Date", [Test] , "Type", "Test") ,
    SELECTCOLUMNS('Table',"Person ID",[Person ID] , "City",[City] , "Category" , [Category] , "Date", [Results] , "Type", "Results")
      )
     
     
    Then we can get the result as follows and you can create some visual in your logic need:

     

    For more information, you can refer to :
    powerbi - Is it possible to unpivot in Power BI using DAX? - Stack Overflow

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly