Forum Discussion

Marianna's avatar
Marianna
Frequent Visitor
3 years ago
Solved

DAX: If date not found, return next available date

Hello, I have large datasets for my pipeline and I want to compare the value of specific ID 6 months ago based on Date slicer where I filter the date, i.e. if I pick 1 Sep 23 in the date slicer, I want my dax to return the value 6 months ago based on my "Date" column in the dataset (1 Mar 23).

 

The problem is that I don't have daily data, so I need the dax measure to provide me with the value of the closest next available date, which could be 3 March 2023, or 4 Mar 2023, etc.  

 

I currently have this measure

CALCULATE([OpenPipeline],PARALLELPERIOD('Rolling Calendar'[date],-6,MONTH))

 

Any ideas on how to tweak it? Appreciate any suggestions!!

Notes on data infrastrucutre: I have a calendar table linked to all my tables via "Date" column

 

Example of dates 

 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Marianna 

    You can refer to the following solution.

    Sample data 

    Date table

    e.g 

    Measure = var a=CALCULATE(MAX('Table'[Column1]),DATEADD('Table 2'[Date],-6,MONTH))
    var _date=CALCULATE(MIN('Table'[Date]),'Table'[Date]>(EOMONTH(SELECTEDVALUE('Table 2'[Date]),-7)+DAY(SELECTEDVALUE('Table 2'[Date]))),CROSSFILTER('Table 2'[Date],'Table'[Date],None)) 
    return IF(a=BLANK(),CALCULATE(MINX(FILTER('Table',[Date]=_date),[Column1]),CROSSFILTER('Table'[Date],'Table 2'[Date],None)),a)

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

3 Replies

  • JoeBarry's avatar
    JoeBarry
    Icon for Solution Sage rankSolution Sage

    Hi Marianna 

     

    Adapt your your measure to 

     

    CALCULATE([OpenPipeline],DATEADD('Rolling Calendar'[date],-6,MONTH))

     

    PARALLELPERIOD will get the value for the whole month whereas DATEADD is date specific. Add the Date from the Date table in the slicer as this will show all dates. If you scroll to March 3rd then you will see data from Sept 3rd

     

    Thanks

    Joe

    If this post helps, then please Accept it as the solution

     

     

    • Marianna7's avatar
      Marianna7
      New Member

      Hi JoeBarry thank you for the suggestion!!! But what if I do not have data on March 3rd? 

      If I select September 3rd, and I do not have data for March 3rd date (backwards 6 months), I need to see the next date that I have, which might be March 5

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Marianna 

    You can refer to the following solution.

    Sample data 

    Date table

    e.g 

    Measure = var a=CALCULATE(MAX('Table'[Column1]),DATEADD('Table 2'[Date],-6,MONTH))
    var _date=CALCULATE(MIN('Table'[Date]),'Table'[Date]>(EOMONTH(SELECTEDVALUE('Table 2'[Date]),-7)+DAY(SELECTEDVALUE('Table 2'[Date]))),CROSSFILTER('Table 2'[Date],'Table'[Date],None)) 
    return IF(a=BLANK(),CALCULATE(MINX(FILTER('Table',[Date]=_date),[Column1]),CROSSFILTER('Table'[Date],'Table 2'[Date],None)),a)

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.