Forum Discussion
Dynamic filter on This Month vs Last Month Cost Measure
I'm using a simple data source with with Cost and YearMonth in number format "20191, 20192, 20193". I want a dynamic "Cost This Month" and "Cost Last Month" measure that updates every month.
I have created two measures "This Month" and "Previous Month":
This Month = MAX(Sheet1[YearMonth])
- Anonymous7 years ago
Thanks guys, it was as easy as this:
Cost This Month =CALCULATE([Cost],FILTER('Calendar','Calendar'[YearMonth] = MAX('Calendar'[YearMonth])))
4 Replies
- v-piga-msft
Resident Rockstar
Hi Anonymous ,
Assuming that you have the data sample like below.
Then you could create the measure below. You could modify the measure based on your actual requirement.
Measure = CALCULATE ( SUM ( 'Table1'[Cost] ), FILTER ( 'Table1', 'Table1'[YearMonth] = MAX ( 'Table1'[YearMonth] ) ) ) Measure 2 = CALCULATE ( SUM ( Table1[Cost] ), FILTER ( ALLSELECTED ( 'Table1' ), 'Table1'[YearMonth] = IF ( RIGHT ( FORMAT ( MAX ( 'Table1'[YearMonth] ), "" ), 1 ) = "1", BLANK (), MAX ( 'Table1'[YearMonth] ) - 1 ) ) )Here is the output.
Best Regards,
Cherry
- Ashish_Mathur
Super User
Hi,
We will have to create a Date column from the Year Month column. We will then create a Calendar Table and build a relationship from the Date column of your base data sheet to the Date column of your Calendar Table. In the Calendar Table, we will then write calculated column formulas to extract the Year and Month. Once this is done, we can write simple measures to get your desired result.
- AnonymousNot applicable
Thanks guys, it was as easy as this:
Cost This Month =CALCULATE([Cost],FILTER('Calendar','Calendar'[YearMonth] = MAX('Calendar'[YearMonth]))) - AnonymousNot applicable
and
Cost Last Month =CALCULATE([Cost],FILTER('Calendar','Calendar'[YearMonth] = MAX('Calendar'[YearMonth])-1))