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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
DanielS_Waves
Frequent Visitor

Need a help in creating a dynamic "previous period" measure

Hi all,

 

I need to create previous period measures for all of my sales measures and they should behave in a different way depending on the situation:

  1. When selecting a non-continuous period no comparison should be made, show no data (not “blank” or “N/A”, just no data)
  2. When selecting a continuous period containing the current period, compared to the parallel period TD as follows:
    1. Today is 15/07 and the selected period is July/2023 – previous period should be 01-15/06/2023
    2. Today is 15/07 and the selected period is June-July/2023 - previous period should be 01/04/2023-15/05/2023
    3. Today is 15/07 and the selected period is 08/07/2023-15/07/2023 – previous period should be 08/06/2023-15/06/2023
  3. When selecting a continuous period not containing the current period, compared to previous months as follows:
    1. Selected period is June/2023 – previous period should be May/2023
    2. Selected period is May-June/2023 – previous period should be March-April/2023
    3. selected period is 08/06/2023-15/06/2023 – previous period should be 08/05/2023-15/05/2023

 

Any suggestion on how to write this DAX formula?

Any help will be much appreciated! 🙏

2 REPLIES 2
amitchandak
Super User
Super User

@DanielS_Waves , Try trailing month or datesmtd with date table

 

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

 

Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))

 

LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

Much appreciate the help!
How can I implement all the requests in one formula?
and about the non-continuous period, not sure how to check it and how to apply it...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.