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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Dynamically calculating Last Period

Hey there,

 

I would like to create a measure for dynamically calculating the last period. I am using this calendar slicer:

 

AndrejBI_0-1610549264909.png

The measure should be something like:

vs Last Period = CALCULATE(SUM(Forms[Ocurrences]), DATEADD('Calendar'[Date],-60,DAY)) 

 Yet, the time period should be dynamic not 60 days before.

To give an example: 

  • When I change the period to Last 1 Year, the measure should do CALCULATE (DATEADD -365 days)
  • When I change the period to Last 1 Month, the measure should do CALCULATE (DATEADD -30 days)
  • When I change the period to Last 1 Week, the measure should do CALCULATE (DATEADD -7 days)

 

Looking forward to any suggestions! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous,

'Table' means the fact table you used to calculate, the 'selector' means the date table you used. For my expression, it is calculated based on selected range day counts. (filter range equal to 'previous N[day count of selected date range] day of current date' to 'current date')

Hope the above helps you to clarify my expression and calculation logic.

Regards,

Xiaoxin Sheng

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous,

You can create a new table to extract the raw table date value and use it as the source of the slicer. (it does not have a relationship to raw table fields)
Then you can use the following measure formula based on selection range to calculate the rolling total on each row:

 

Measure =
VAR currDate =
    MAX ( 'Table'[Date] )
VAR range =
    COUNTROWS ( ALLSELECTED ( 'Selector'[Date] ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Date] >= currDate - range
                && [Date] <= currDate
        )
    )

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

I am not exactly sure what you mean by the first sentence. Could you elaborate a bit? Maybe even show a step-by-step guide? I can't really figure out what you used as Select (Date). Just to double check you used my original date table as Table(Amount), right?

Anonymous
Not applicable

Hi @Anonymous,

'Table' means the fact table you used to calculate, the 'selector' means the date table you used. For my expression, it is calculated based on selected range day counts. (filter range equal to 'previous N[day count of selected date range] day of current date' to 'current date')

Hope the above helps you to clarify my expression and calculation logic.

Regards,

Xiaoxin Sheng

parry2k
Super User
Super User

@Anonymous I think we need to do some trick here to make it work as there is no way to find out what is selected in the relative date filter. Can you share a sample pbix file thru one drive/google drive and will try to work thru some solutions. Cheers!!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors