cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted

Previous Dynamic Period DAX Calculation

I've followed the guide on https://radacad.com/previous-dynamic-period-dax-calculation for creating a dynamic previous period. So if I select a date range for the current period of;

 

  • 01/06/2019 to 01/06/2019 the previous period is 31/05/2019 to 31/05/2019
  • 01/06/2019 to 02/06/2019 the previous period is 30/05/2019 to 31/05/2019
  • 01/06/2019 to 07/06/2019 the previous period is 25/05/2019 to 31/05/2019
  • 01/06/2019 to 30/06/2019 the previous period is 02/05/2019 to 31/05/2019
  • 01/04/2019 to 30/06/2019 the previous period is 31/12/2019 to 31/03/2019

 

However the StartOfPreviousPeriod measure is not ideal for me. For example, selecting a date range of 01/06/2019 to 30/06/2019 for the current period means that the StartOfPreviousPeriod is 02/05/2019, as in the example above.

 

StartOfPreviousPeriod =
FIRSTDATE (
    PREVIOUSDAY (
        DATEADD ( CalendarCombined[Date], -1 * [DaysInCurrentPeriod], DAY )
    )
)

However what I would like to do is have the date show as 01/05/2019 but I cannot figure out a way without breaking the dynamic elements of it. For clarity, using the examples supplied above if I select a date range for the current period of;

 

  • 01/06/2019 to 01/06/2019 the previous period should be 31/05/2019 to 31/05/2019
  • 01/06/2019 to 02/06/2019 the previous period should be 30/05/2019 to 31/05/2019
  • 01/06/2019 to 07/06/2019 the previous period should be 25/05/2019 to 31/05/2019
  • 01/06/2019 to 30/06/2019 the previous period should be 01/05/2019 to 31/05/2019
  • 01/04/2019 to 30/06/2019 the previous period should be 01/01/2019 to 31/03/2019

Any assistance would be greatly appreciated.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Previous Dynamic Period DAX Calculation

@mark_carlisle seems like you have two logic going on, and you want if selection is full month then use full previous month.

 

so you can build a logic like, if first selected date is first date of the month and last selected date is last date of the month, full month is selected and then use this in if condition with PreviousMonth DAX function.






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





Re: Previous Dynamic Period DAX Calculation

Yeah I figured that was going to be the case, was hoping there was going to be some time intelligence DAX function I might have missed. The following is what I've went with;

 

StartOfPreviousPeriod =
IF (
    AND (
        FIRSTDATE ( CalendarCombined[Date] ) = STARTOFMONTH ( CalendarCombined[Date] ),
        LASTDATE ( CalendarCombined[Date] ) = ENDOFMONTH ( CalendarCombined[Date] )
    ),
    FIRSTDATE (
        PREVIOUSMONTH (
            DATEADD ( CalendarCombined[Date], -1 * [MonthsInCurrentPeriod], MONTH )
        )
    ),
    FIRSTDATE (
        PREVIOUSDAY (
            DATEADD ( CalendarCombined[Date], -1 * [DaysInCurrentPeriod], DAY )
        )
    )
)
2 REPLIES 2
Super User
Super User

Re: Previous Dynamic Period DAX Calculation

@mark_carlisle seems like you have two logic going on, and you want if selection is full month then use full previous month.

 

so you can build a logic like, if first selected date is first date of the month and last selected date is last date of the month, full month is selected and then use this in if condition with PreviousMonth DAX function.






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





Re: Previous Dynamic Period DAX Calculation

Yeah I figured that was going to be the case, was hoping there was going to be some time intelligence DAX function I might have missed. The following is what I've went with;

 

StartOfPreviousPeriod =
IF (
    AND (
        FIRSTDATE ( CalendarCombined[Date] ) = STARTOFMONTH ( CalendarCombined[Date] ),
        LASTDATE ( CalendarCombined[Date] ) = ENDOFMONTH ( CalendarCombined[Date] )
    ),
    FIRSTDATE (
        PREVIOUSMONTH (
            DATEADD ( CalendarCombined[Date], -1 * [MonthsInCurrentPeriod], MONTH )
        )
    ),
    FIRSTDATE (
        PREVIOUSDAY (
            DATEADD ( CalendarCombined[Date], -1 * [DaysInCurrentPeriod], DAY )
        )
    )
)

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 40 members 1,132 guests
Please welcome our newest community members: