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
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/63376
or
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907
In 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
Thanks v-lili6-msft - that seems to do just what I wanted. Thanks for your help.