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!
You're almost there! Try changing the IF(ISINSCOPE( line to:
IF( ISINSCOPE(Marks[evaluated item]) && Marks[country] = "Country 1" && Marks[evaluated item] = "Phone Skills",
DIVIDE(This should then use your 'all shops' calculation only for when the country is Country 1 and the evaluated item is Phone skills. Everything else will calculate in the normal way.
If that doesn't work and you want me to look at the pbix, then post a shared link to OneDrive, Dropbox, Box etc.
Hi belvoir99,
Apparently the ISINSCOPE fx doesn't take a specific variables from a column; i can't input ISINSCOPE(Marks[country])= "Country 1" for example.
I used this formula with ISINSCOPE :
Score2 =
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 = ISINSCOPE(Marks[country])= "Country 1" && ISINSCOPE(Marks[evaluated item])="Phone skills"
RETURN
IF(IsScopeSpecific,
DIVIDE(SumMarkAllShops,
SumMaxMarkAllShops
),
DIVIDE(
SumMark,
SumMaxMark
)
)
I got this error message :
So I tried SELECTEDVALUE instead :
Score3 =
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"
RETURN
IF(IsScopeSpecific,
DIVIDE(SumMarkAllShops,
SumMaxMarkAllShops
),
DIVIDE(
SumMark,
SumMaxMark
)
)
It's very close to what i'm looking for but i don't want the AVERAGE score to apply on a subitem level :
This is what i'm looking for :
Here's the link https://1drv.ms/u/s!Agk0pOMpwO_IoTnnNVVBRWcFyWLi?e=gYts1X
Thanks again
- belvoir992 years agoResolver III
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
- AnthNC2 years agoHelper II
Many thanks!
Sorry again for not uploading the pbix file earlier. I know how to do it now 🙂
I will definitely take into account your recommandations for my next publication on this forum.
- belvoir992 years agoResolver III
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!