Forum Discussion
sqldev2017
7 years agoMicrosoft Employee
Help with Simple DAX formula
I am doing something like this - PreviousMonth = FORMAT(CALCULATE(MIN(DimDate[Month]), FILTER(DimDate, DimDate[Month_Year] = [SelectedMonthYear]) ), "String") - Min(DimDate[Month]) ret...
- 7 years ago
Try storing the MEASURE value in a variable first
Revenue = VAR myMEASURE = [MonthYear] RETURN CALCULATE ( SUM ( fact[Revenue] ), FILTER ( fact, fact[fiscalMonth] = myMEASURE ) )
Zubair_Muhammad
7 years agoCommunity Champion
Try storing the MEASURE value in a variable first
Revenue =
VAR myMEASURE = [MonthYear]
RETURN
CALCULATE (
SUM ( fact[Revenue] ),
FILTER ( fact, fact[fiscalMonth] = myMEASURE )
)
sqldev2017
7 years agoMicrosoft Employee
That worked like a Charm.
Thank You.
Honestly, I was trying to do this FORMAT(Measure, "String") , that was not working.
This worked.
- Zubair_Muhammad7 years agoCommunity Champion
Glad it worked.
When you use a MEASURE inside a FILTER function, it is evaluated for each row of the Table inside FILTER function (in your case it is FACT table)
That's why we have to store its value first in a variable
FILTER ( fact, fact[fiscalMonth] = [Measure] ) )