Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PBIlomiddze
Regular Visitor

Same period last month filter is not working with period/date/month slicer

Hi, I have to compare the previous month's sales with the current month's sales.

 

I have two formulas:

 

MTD Current month = 
          TOTALMTD([sales],sales_aggregated[Date]) - shows correct number

 

MTD Last Month  =
         CALCULATE(
    [Sales],
    DATEADD(   FILTER(   DATESMTDsales_aggregated[date]),sales_aggregated[date]<MAX(sales_aggregated[date])),-1,MONTH)
        )  Shows the Correct number for the previous month. 


and they both work in the divide formula as well - as a result, they show change %.

But I want to select month, and show the "MTD" vs "MTD Prev month", for example if now is 05.2023, I want to select 03.2023 and formula should show 03.2023 and other 02.2023 but as the slicer is filtering the whole table on dates only for 03.2023, 02.2023 is filtered out and MTD Last month is blank. how can i prevent a blank value on the previous month?


 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@PBIlomiddze , Make sure you are using date table, try measure like

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))


last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
PBIlomiddze
Regular Visitor

The main part of the solution was to use Calendar as a filter. more or less the implemented formulas were working - in the end: the solution looks like this. 

MTD_Revenue_Total = CALCULATE([Revenue],DATESMTD('Z_Calender'[Date]))

MTD_LM_Revenue_Total =
CALCULATE(
    [Revenue],
    DATEADD(FILTER(DATESMTD(Z_Calender[Date]),Z_Calender[Date]<TODAY()),-1,MONTH)
    )   -   Calendar <  today - I have included this part to filter the current month on the dates that are passed - to not compare the latest month with the whole previous month. for other months it will be comparing the whole month to the whole month. 

MTD_VS_MTD_LM_Revenue_Total =
IF([1_KPI_MTD_LM_Revenue_Total]=0,BLANK(),
DIVIDE([1_KPI_MTD_Revenue_Total],[1_KPI_MTD_LM_Revenue_Total],0)-1
)
amitchandak
Super User
Super User

@PBIlomiddze , Make sure you are using date table, try measure like

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))


last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.