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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
azakir
Resolver I
Resolver I

Show previous days based on date selected

Hi Guys. Got a question in regards to displaying data based on dates. 

So on a line graph, I would like to show data based on number of days leading up to the date selected. 

For example, if selected date is 01/07/2022 - 15/07/2022, I would like to show the data 15/06/2022 - 30/06/2022. 

Similiarly if dates are selected 01/03/2022 - 25/04/2022, a total of 56 days, I would like to show previous 56 days worth of data i.e. 03/01/2022 - 28/02/2022 (56 Days). 

Any help would be appreciated

1 ACCEPTED SOLUTION

Hi, @azakir 

Please modified the formula as below:

You need to add 1 day to the  variable  'datediff1'.

veasonfmsft_0-1659691800281.png

 

Best Regards,
Community Support Team _ Eason

View solution in original post

5 REPLIES 5
azakir
Resolver I
Resolver I

hi @amitchandak 

I worked out the formula: 

azakir_0-1659482383812.png

 

But it's not giving me the correct number. 

For example, between 01/01/2022 - 31/01/2022, a total of 31 days, we had 273 Tyres.

By using this formula, if I now choose 01/02/2022 - 03/03/2022 (31 days), the formula "Last Period" should give 273 tyres, but it's showing 278: 

 

azakir_1-1659482612505.png

 

azakir_2-1659482649275.png

 

Hi, @azakir 

Please modified the formula as below:

You need to add 1 day to the  variable  'datediff1'.

veasonfmsft_0-1659691800281.png

 

Best Regards,
Community Support Team _ Eason

Thanks for your and @amitchandak help. this did the trck. 

amitchandak
Super User
Super User

@azakir , Try a measure like

 


same period based on date range
Last Period =
var _max =maxx(allseleceted(date),date[date])
var _min =maxx(allseleceted(date),date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))

Hi @amitchandak 

Thanks for your help. Can I please request if you could kindly check the calculate formula, there are some errors with the formula which I am getting using that. 

 

azakir_0-1659427971025.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.