Forum Discussion
Flexible Month Calculation
Hi. I'm trying to do MTD/YTD/YTD LY calculations and the calculations need to be flexible based on a month filter. Here is how I wanted to do it.
1. YTD = CALCULATE(Sum(GL[AMOUNT]),'Invoked Function'[YEAR]=2025)
2. YTD LY =CALCULATE(Sum(GL[AMOUNT]),SAMEPERIODLASTYEAR('Invoked Function'[Date]))
I think these should be pretty easy. The challenging part is MTD since I need to filter to the latest month and I'll have multiple months. Here is what I did.
This eliminates the error but doesn't return a value. I feel like the answer is simple but I can't think of it.
Hi, if your Date table is already properly marked as a Date table in Power BI I'd suggest using time intelligence function instead of comparing the date text.So for your MTD it would be
MTD =
VAR MaxSelectedDate = MAX('Invoked Function'[Date])
RETURN
CALCULATE(
SUM(GL[AMOUNT]),
DATESMTD('Invoked Function'[Date]),
'Invoked Function'[Date] <= MaxSelectedDate
)
3 Replies
- MasonMASuper User
Hi, if your Date table is already properly marked as a Date table in Power BI I'd suggest using time intelligence function instead of comparing the date text.So for your MTD it would be
MTD =
VAR MaxSelectedDate = MAX('Invoked Function'[Date])
RETURN
CALCULATE(
SUM(GL[AMOUNT]),
DATESMTD('Invoked Function'[Date]),
'Invoked Function'[Date] <= MaxSelectedDate
) - dyee4613v1Frequent Visitor
I'm an idiot. I was trying calculate table and all this nonsense. The normal MTD calculation does everything I need. Thank you Mason!
- MasonMASuper User
Happy to see it works:)