Forum Discussion
DAX average score
- Anonymous2 years ago
Hi AnthNC ,
Thanks for the reply from belvoir99 , please allow me to provide another insight:
You can change the expression for ScoreBelvoir99 to
ScoreBelvoir99 = VAR SumMark = SUM(Marks[weighted mark]) VAR SumMaxMark = SUM(Marks[max weighted mark]) VAR SumMarkAllShops = CALCULATE( SUM(Marks[weighted mark]), REMOVEFILTERS(Marks[shop]) ) VAR SumMaxMarkAllShops = CALCULATE( SUM(Marks[max weighted mark]), REMOVEFILTERS(Marks[shop]) ) RETURN IF(ISINSCOPE(Marks[subitem]), DIVIDE( SumMark. SumMaxMark ), IF IF(ISINSCOPE(Marks[evaluated item]) && SELECTEDVALUE(Marks[country])="Country 1" && SELECTEDVALUE(Marks[evaluated item])="Phone skills", DIVIDE( SumMarkAllShops, SumMaxMarkAllShops ), DIVIDE( DIVIDE( SumMark, SumMaxMarkAllShops ), DIVIDE( SumMaxMark ) ) )
You can also change Score3 toScore3 = VAR SumMark = SUM(Marks[weighted mark]) VAR SumMaxMark = SUM(Marks[max weighted mark]) VAR SumMarkAllShops = CALCULATE( SUM(Marks[weighted mark]), REMOVEFILTERS(Marks[shop]) ) VAR SumMaxMarkAllShops = CALCULATE( SUM(Marks[max weighted mark]), REMOVEFILTERS(Marks[shop])) VAR IsScopeSpecific = SELECTEDVALUE(Marks[country])="Country 1" && SELECTEDVALUE(Marks[evaluated item])="Phone skills" && NOT ISINSCOPE(Marks [subitem]) RETURN IF(IsScopeSpecific. DIVIDE(SumMarkAllShops, SumMaxMarkAllShops, SumMarkAllShops) SumMaxMarkAllShops ), DIVIDE( SumMark, SumMaxMarkAllShops ), DIVIDE( SumMaxMark ) )If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- 2 years ago
Thanks for the PBIX file.
You are correct re ISINSCOPE. If you look at my code carefully you will see that there is a bracket after the column name e.g.IF( ISINSCOPE(Marks[evaluated item]),ISINSCOPE takes a column name as an argument i.e. Marks[evaluated item] and then returns a True or False value therefore your code returns an data type error as it is comparing a True/False value with a string value 'Country 1':
VAR IsScopeSpecific = ISINSCOPE(Marks[country])= "Country 1"It looks like, in Score3, we have the correct calculation at the 'Phone skills' level but, at the 'evaluated item' level we want to revert back to the standard average.
I've tweaked my DAX measure a little bit - it's probably similar to or identical to Clara Gong's Anonymous calculation - and now returns the correct calculation:ScoreBelvoir99 = VAR SumMark = SUM(Marks[weighted mark]) VAR SumMaxMark = SUM(Marks[max weighted mark]) VAR SumMarkAllShops = CALCULATE( SUM(Marks[weighted mark]), REMOVEFILTERS(Marks[shop]) ) VAR SumMaxMarkAllShops = CALCULATE( SUM(Marks[max weighted mark]), REMOVEFILTERS(Marks[shop]) ) VAR StandardAverage = DIVIDE( SumMark, SumMaxMark ) VAR AllShopsAverage = DIVIDE( SumMarkAllShops, SumMaxMarkAllShops ) RETURN IF( SELECTEDVALUE(Marks[country]) = "Country 1" && SELECTEDVALUE(Marks[evaluated item]) = "Phone Skills", IF( ISINSCOPE(Marks[subitem]), StandardAverage, AllShopsAverage ), StandardAverage )Note use of indentation to make it more readable and also use of VAR.
Some things about VAR:- it's a constant not a variable
- StandardAverage is calculated once not twice (which it would be if the DIVIDE formula was repeated).
- it makes the code easier to read
- 2 years ago
Glad I could help and that you got there. I too have learnt some stuff about ISINSCOPE and hierarchies.
If you want, you can give me a 'thumbs up' and/or Accept as Solution!
So my understanding is you want to show the AVERAGE of all shops at the [evaluated item] level but below that level just the AVERAGE for each shop x subitem combination.
You might want to try out ISINSCOPE function - see - https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/ - to switch calculation according to the hierarchical level
e.g.
Score =
VAR SumMark = SUM(Marks[weighted mark])
VAR SumMaxMark = SUM(Marks[max weighted mark])
VAR SumMarkAllShops =
CALCULATE(
SUM(Marks[weighted mark]),
REMOVEFILTERS(Marks[shop])
)
VAR SumMaxMarkAllShops =
CALCULATE(
SUM(Marks[max weighted mark]),
REMOVEFILTERS(Marks[shop])
)
RETURN
IF( ISINSCOPE(Marks[evaluated item]),
DIVIDE(
SumMarkAllShops,
SumMaxMarkAllShops
),
DIVIDE(
SumMark,
SumMaxMark
),
)I can't test this without some data but hopefully it might give you a way forward.
- AnthNC2 years agoHelper II
Thanks belvoir99!
Here are the results :
Here's what i'm trying to do only for Country 1 and the evaluated item "Phone skills" (not subitems) for Shops 1, 2 and 3:
The logic i'm trying to formulate is :
If ISINSCOPE([country]="Country 1") AND ISINSCOPE([evaluated item]="Phone skills")
Then AVERAGE the scores of Shop 1, 2 and 3 for the evaluated item "Phone skills"
Else CALCULATE normal scores
Would you know how to translate that in DAX ?
I tried to put a download link to the pbix but it says "spam" on my message
How can i upload the pbix file ?
Thank you