Forum Discussion
No CALCULATE Challenge -- Round #2
- 3 years ago
AlexisOlson and All,
I was completely convinced that No CALCULATE solution wasn't possible for such kind of problems. My belief is that filter context manipulation is exclusively CALCULATE branded. Yesterday while handling a DAX issue, AlexisOlson No CALCULATE challenge popped up in my mind. With a probable solution, I decided to try the first thing in the morning and seems it covers all the requirements.
Sales Benchmark Ratio 2 = VAR _BenchmarkSales = SUMX ( ALLSELECTED ( Geography[RegionCountryName] ), SUMX ( CROSSJOIN ( TREATAS ( { "North America" }, Geography[ContinentName] ), TREATAS ( { "Store" }, Channel[ChannelName] ) ), [Sales Amount] ) ) VAR _Ratio = DIVIDE ( [Sales Amount], _BenchmarkSales ) RETURN _Ratio
AlexisOlson and All,
I was completely convinced that No CALCULATE solution wasn't possible for such kind of problems. My belief is that filter context manipulation is exclusively CALCULATE branded. Yesterday while handling a DAX issue, AlexisOlson No CALCULATE challenge popped up in my mind. With a probable solution, I decided to try the first thing in the morning and seems it covers all the requirements.
Sales Benchmark Ratio 2 =
VAR _BenchmarkSales =
SUMX (
ALLSELECTED ( Geography[RegionCountryName] ),
SUMX (
CROSSJOIN (
TREATAS ( { "North America" }, Geography[ContinentName] ),
TREATAS ( { "Store" }, Channel[ChannelName] )
),
[Sales Amount]
)
)
VAR _Ratio =
DIVIDE ( [Sales Amount], _BenchmarkSales )
RETURN
_Ratio- AlexisOlson3 years ago
Super User
tamerj1 Nice work! This does appear to satisfy the requirements, so I'll accept it. The trick here is using the implicit CALCULATE context transition that comes from referencing another measure, [Sales Amount].
For an extra challenge, can anyone modify this so that it works as a standalone measure? Maybe using SUMMARIZE since that can also do a context transition.
- tamerj13 years ago
Community Champion
AlexisOlson
Yes sure, I thought about that already but it does not look so niceSales Benchmark Ratio 2 = VAR _BenchmarkSales = SUMX ( SUMMARIZE ( CROSSJOIN ( ALLSELECTED ( Geography[RegionCountryName] ), CROSSJOIN ( TREATAS ( { "North America" }, Geography[ContinentName] ), TREATAS ( { "Store" }, Channel[ChannelName] ) ) ), Geography[RegionCountryName], Geography[ContinentName], Channel[ChannelName], "@Amt", SUM ( Sales[SalesAmount] ) ), [@Amt] ) VAR _Ratio = DIVIDE ( [Sales Amount], _BenchmarkSales ) RETURN _Ratio
- Greg_Deckler3 years ago
Community Champion
tamerj1 Brilliant! Nice one Tamer. Going to add that one to my pattern of No CALCULATE tricks.
- tamerj13 years ago
Community Champion
Shall we expect a new one of your brilliant videos? Tag me if you do 😉