Forum Discussion
Measure showing zero when not filtered
I'm looking to show a measure to the same week in the previous fiscal year:
LY Stock (sgls) =
VAR currentFiscalYear =
MAX ( 'Stock & Sales'[fiscal_year] )
VAR currentFiscalWeek =
MAX ( 'Stock & Sales'[fiscal_week_number] )
RETURN
CALCULATE (
Sum('Stock & Sales'[stock_sgls]), ALLSELECTED('Stock & Sales'[bu]),
FILTER (
ALL ( 'Stock & Sales' ),
'Stock & Sales'[fiscal_year]
= currentFiscalYear - 1
&& 'Stock & Sales'[fiscal_week_number] = currentFiscalWeek
),FILTER (
ALL ( 'Stock & Sales' ),'Stock & Sales'[bu] = SELECTEDVALUE( ( 'Stock & Sales'[bu] ))))
However, when it's not filtered, it shows zero. I need it to show the total.
Can someone help, please?
Please try this expression instead. Not sure why you have the ALLSELECTED() in there and then filter it back down again with SELECTEDVALUE. In any case, the SELECTEDVALUE is why you were not seeing anything for total. I replaced it with VALUES. Also note that I updated your ALL to only include the columns being filtered (a good practice).
LY Stock (sgls) =
VAR currentFiscalYear =
MAX ( 'Stock & Sales'[fiscal_year] )
VAR currentFiscalWeek =
MAX ( 'Stock & Sales'[fiscal_week_number] )
RETURN
CALCULATE (
SUM ( 'Stock & Sales'[stock_sgls] ),
ALLSELECTED ( 'Stock & Sales'[bu] ),
FILTER (
ALL (
'Stock & Sales'[fiscal_year],
'Stock & Sales'[fiscal_week_number]
),
'Stock & Sales'[fiscal_year] = currentFiscalYear - 1
&& 'Stock & Sales'[fiscal_week_number] = currentFiscalWeek
),
VALUES ( 'Stock & Sales'[bu] )
)Regards,
Pat
2 Replies
- mahoneypatMicrosoft Employee
Please try this expression instead. Not sure why you have the ALLSELECTED() in there and then filter it back down again with SELECTEDVALUE. In any case, the SELECTEDVALUE is why you were not seeing anything for total. I replaced it with VALUES. Also note that I updated your ALL to only include the columns being filtered (a good practice).
LY Stock (sgls) =
VAR currentFiscalYear =
MAX ( 'Stock & Sales'[fiscal_year] )
VAR currentFiscalWeek =
MAX ( 'Stock & Sales'[fiscal_week_number] )
RETURN
CALCULATE (
SUM ( 'Stock & Sales'[stock_sgls] ),
ALLSELECTED ( 'Stock & Sales'[bu] ),
FILTER (
ALL (
'Stock & Sales'[fiscal_year],
'Stock & Sales'[fiscal_week_number]
),
'Stock & Sales'[fiscal_year] = currentFiscalYear - 1
&& 'Stock & Sales'[fiscal_week_number] = currentFiscalWeek
),
VALUES ( 'Stock & Sales'[bu] )
)Regards,
Pat
- darylmcFrequent Visitor
Excellent! Thank you.
Noted on the ALL requirement.