Forum Discussion
Variable not working correctly in measure
- 6 years ago
HI dphillips
For your case, it likes measure totals problem. Very common. See this post about it
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376or
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907In your case, you want to use the total of ResultGroupNumber as a variable in the measure,
but for different rowcontext in the visual, it won't use the total of ResultGroupNumber,
so for your case, you could adjust the formula as below:
LPAveLongTerm =
var ResultGroupNumber = calculate(max('Result Group Table'[Sort Order]),all('Result Group Table'))
RETURN
calculate(AVERAGE(uncRedshift_Studentresults[LPResult]),filter(all('Result Group Table'),'Result Group Table'[Sort Order] < ResultGroupNumber),allexcept(uncRedshift_Studentresults,uncRedshift_Studentresults[NameNum],uncRedshift_Studentresults[ResultType]))or
LPAveLongTerm =
var ResultGroupNumber = calculate(max('Result Group Table'[Sort Order]),allselected('Result Group Table'))
RETURN
calculate(AVERAGE(uncRedshift_Studentresults[LPResult]),filter(all('Result Group Table'),'Result Group Table'[Sort Order] < ResultGroupNumber),allexcept(uncRedshift_Studentresults,uncRedshift_Studentresults[NameNum],uncRedshift_Studentresults[ResultType]))Regards,
Lin
Yep - I did test that the variable was correct by using the formula for the variable on its own like you have done. I put this measure in a card and it gives me a whole number which represents the result group I am looking for. When I change the slicer, the variable also changes so that seems to be all correct.