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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PBIlomiddze
New Member

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

View solution in original post

2 REPLIES 2
PBIlomiddze
New Member

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.