Forum Discussion

azakir's avatar
azakir
Icon for Resolver I rankResolver I
4 years ago
Solved

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

  • Hi, azakir 

    Please modified the formula as below:

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

     

    Best Regards,
    Community Support Team _ Eason

5 Replies

  • 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)))

    • azakir's avatar
      azakir
      Icon for Resolver I rankResolver I

      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. 

       

       

  • hi amitchandak 

    I worked out the formula: 

     

    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: 

     

     

     

    • v-easonf-msft's avatar
      v-easonf-msft
      Icon for Community Support rankCommunity Support

      Hi, azakir 

      Please modified the formula as below:

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

       

      Best Regards,
      Community Support Team _ Eason