Forum Discussion

DylanSandry's avatar
DylanSandry
Frequent Visitor
2 years ago

Grouping matrix columns using custom measures

Hello,

 

I've been destroying myself trying to figure this out and I wonder if someone can help.

I have the following table (Simplified to get to the root of my problem):

JobProductPriceSaleDate
1A$10001062024
1B$20001062024
2A$11019062024
3C$30018062024
4A$12001052024

 

I would like to display it as follows:

 Today ThisMonth ThisYear 
ProductTotalPriceTotalCountTotalPriceTotalCountTotalPriceTotalCount
A$1101$2102$3303
B00$2001$2001
C00$3001$2001

 

I can flatten the table and created individual measures for every combination of column (e.g. TodayTotalPrice and TodayTotalCount), but I don't want a flat table. I want the nicely structured matrix that can be collapsed and expanded.

 

If anyone could please help for this simple example that would be great. I'm confident I'll be able to expand it to my larger dataset.

 

Thanks.

2 Replies

  • Daniel29195's avatar
    Daniel29195
    Icon for Community Champion rankCommunity Champion

    DylanSandry 

    do the following : 
    create a custom table :  ( No need for the Column "Column")

     

     
     
    add column1 to the matrix. 
    and now you just need to create 2 measures : 
    TotalPrice
     and 
    TotalCount
     
    for each measure, use the switch statement :
    switch(
    true ( ),
       selectedvalue(table[column1]) =  "Today" , calculate( [total price] , date =  today () ,
    selectedvalue(table[column1]) =  "This Month" , calculate( [total price] , year(sales[order date]) = year ( today() ,  month(sales[order date]) = month( today()) ,
    .........., ,
     
     
     
    let me know if this helps. 
     
  • DylanSandry's avatar
    DylanSandry
    Frequent Visitor

    That's worked perfectly thanks!

     

    Just a follow up question. Is it possible to show and hide certail values based on matrix columns? I want to also add averages after the TotalPrice and TotalCount sections, so it will look like this

     Today ThisMonth ThisYear MonthAverage YearAverage 
    ProductTotalPriceTotalCountTotalPriceTotalCountTotalPriceTotalCountPricePerDayCountPerDayPricePerDayCountPerDay

     

    I can create the second section of matrix columns with a couple new measures and altered switch statements, but how can I hide the values that dont correspond to that section of the table? (Hide TotalPrice, TotalCount from the MonthAverage and YearAverage sections and vice versa).

     

    Cheers.