Forum Discussion

ChadPortman's avatar
ChadPortman
Frequent Visitor
5 years ago
Solved

Group by Measure in a Matrix

I have been searching for answers on this and have found several things that might work but I don't understand how to use them. Hoping someone can help me understand.   I will try to explain what a...
  • ChadPortman's avatar
    5 years ago

    For anyone else that finds this later. I was able to get this to work and here's how. I used Summarize Columns, with a switch function inside for the segments, I could not figure out how to use a measure or a variable inside the summarize columns function so I just typed the calculation each time. I wrapped the whole thing in a Calculate Table function to add a filter. Below is the code

    CALCULATETABLE(
    SUMMARIZECOLUMNS(
    	 UCS[GuestID]
    	,UCS
    	,"ADTBand"
    	,SWITCH(TRUE(),
    	Sum(UCS[Orders]) = 0,"0-14",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<15,"0-14",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=15&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<25,"15-24",
    	CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=25&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<40,"25-39",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=40&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<75,"40-74",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=75&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<100,"75-99",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=100&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<150,"100-149",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=150&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<225,"150-224",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=225&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<300,"225-299",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=300&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<400,"300-399",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=400&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<500,"400-499",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=500&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<750,"500-749",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=750&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<1000,"750-999",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=1000&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<1250,"1000-1249",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=1250&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<1500,"1250-1499",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=1500&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<2000,"1500-1999",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=2000&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<2500,"2000-2499",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=2500&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<3000,"2500-2999",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=3000&&CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))<3500,"3000-3499",
        CALCULATE(Sum(UCS[TotalSpend])/CALCULATE(DistinctCount(UCS[Date]),UCS[Orders] = 1))>=3500,"3500+"
    ))
    ,not( UPI[TierID] in {9,10}))