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
nanci
Helper II
Helper II

Filter data in previous period

I have 2 donut charts.
The one on the left shows data in the specified period the users chooses. This period is selected using a date filter in the filter pane that affects all visuals in the same page.

The chart on the right should show the previous period of the first chart. For example, if the user selected the last week, then this second chart shows data for 2 weeks ago, if the user selects March 2020 then the chart should show data for February 2020...

 

I''ve been trying to get the 2 dates selected by the user: end and begin; calculate the number of days in between; and then trying to substract those days from the begin day and filter that data but so far this is not working.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@nanci , you need to combine few calculations like for month, qtr , year like

 

Rolling 2 = CALCULATE(distinctcount(Transation[Month-Year]),DATESINPERIOD('Date'[Date],today(),-2,MONTH))

 

for week

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

How to handle the condition

https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @nanci

 

Create a slicer table as below:

Table 2 = VALUES('Table'[Date])

Then create 2 measures as below:

Measure = 
var _myslicer=CALCULATETABLE(VALUES('Table 2'[Date]),FILTER('Table 2','Table 2'[Date] in FILTERS('Table 2'[Date])))
var _mindate=MINX(_myslicer,'Table 2'[Date])
var _maxdate=MAXX(_myslicer,'Table 2'[Date])
Return
CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Date]>=_mindate&&'Table'[Date]<=_maxdate))
Measure 2 = 
var _myslicer=CALCULATETABLE(VALUES('Table 2'[Date]),FILTER('Table 2','Table 2'[Date] in FILTERS('Table 2'[Date])))
var _mindate=MINX(_myslicer,'Table 2'[Date])
var _maxdate=MAXX(_myslicer,'Table 2'[Date])
Return
CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Date]>=_mindate-14&&'Table'[Date]<=_maxdate-14))

And you will see:

Annotation 2020-08-17 174206.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User

@nanci , you need to combine few calculations like for month, qtr , year like

 

Rolling 2 = CALCULATE(distinctcount(Transation[Month-Year]),DATESINPERIOD('Date'[Date],today(),-2,MONTH))

 

for week

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

How to handle the condition

https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.