Forum Discussion

rel2022's avatar
rel2022
Frequent Visitor
3 years ago
Solved

Nearest date to slicer selection

Hi,   How can I modify this DAX to find the nearest date (can be before or after) to the minimum value the user selects on the date range slicer? This data set doesn't have every possible day in it...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi rel2022 ,

    Since you did not give a specific table, I had to create my own table for testing according to your description, please point out if there are any problems.

    Please try below steps:

    1. below is my test table

    Table:

    Dates:

    Dates =
    CALENDAR (
        FIRSTDATE ( 'Table'[Date Effective] ),
        LASTDATE ( 'Table'[Date Effective] )
    )
    

    2. create a measure and add it to card visual, add a slicer visual with "Dates[Date]" column

    Measure =
    VAR min_date =
        MIN ( Dates[Date] )
    VAR tmp =
        FILTER ( ALL ( 'Table' ), 'Table'[Date Effective] >= min_date )
    VAR ctn =
        COUNTROWS ( tmp )
    RETURN
        IF ( ctn = 0, 0, ctn )
    

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.