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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AndySmith
Helper III
Helper III

Prior Period dependent on Month Slicers

Hi

 

I have a sales table and a Date Table. I am using a Month Year Slicer.

 

Would like to calculate the sum of sales for the prior period based on this slicer. So if I have 1 month selected - I want to see the previous month. If I have 2 months selected, I want to sum sales of the previous 2 months. 3 months selected? Guess what? Yep - I want to see sales for the 3 months prior to the selection.

Example: If Sept, Oct, Nov selected in slicer, I want sum of Jun, July, August

 

Thanks!

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

Something like this
you should have a date table

Measure = 
VAR CounMonth = DISTINCTCOUNT('Calendar'[Month Number])
RETURN
CALCULATE(SUM(yourtable[Sales]), DATEADD('Calendar'[Date],-CounMonth,MONTH))

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Ashish_Mathur_0-1700796124889.pngAshish_Mathur_1-1700796137006.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@AndySmith the solution @Ahmedx provided will work - I missed the dynamic part. 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.

AndySmith
Helper III
Helper III

Thanks!

 

But I need it to be dynamic - there might be 6 months selected, so I want to see the 6 months prior, or 15 months, so I want to see the 15 months prior

Ahmedx
Super User
Super User

Something like this
you should have a date table

Measure = 
VAR CounMonth = DISTINCTCOUNT('Calendar'[Month Number])
RETURN
CALCULATE(SUM(yourtable[Sales]), DATEADD('Calendar'[Date],-CounMonth,MONTH))

This is perfect. Accepting as solution. Many thanks

parry2k
Super User
Super User

@AndySmith simply do this measure:

 

 

Previous Period = 
CALCULATE ( 
   [Your Measure],
   DATEADD ( 'Date Table'[Date], -3, MONTH )
)

 

 

Learn more about DATEADD function here:

 

In depth review of most powerful and flexible DATEADD Time Intelligence function - Part 3 - YouTube 

How PREVIOUS/NEXT (DAY/MONTH/QTR/YEAR) Time Intelligence functions are different from DATEADD-Part 4...



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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.