Forum Discussion

Maria_Maria's avatar
Maria_Maria
Icon for Helper II rankHelper II
4 years ago
Solved

help with DAX to filter dates

Hi! I have a data set with a date column, category, and sum. The data is daily sum for each category for the whole year.  I need a measure with the logic like this: if max chosen date on slider ex...
  • v-chenwuz-msft's avatar
    4 years ago

    Hi Maria_Maria ,

     

     if the user chooses May 14, he will see jan 14, Feb14, March 14, April 14 and May 14.

    Measure:

    Measure =
    VAR _s =
        MAX ( 'CALENDAR'[Date] )
    VAR _sy =
        YEAR ( _s )
    VAR _sm =
        MONTH ( _s )
    VAR _sd =
        DAY ( _s )
    VAR _date =
        CALCULATETABLE (
            VALUES ( 'Table'[Date] ),
            FILTER (
                FILTER ( 'table', [Date] < _s ),
                IF (
                    MONTH ( DATE ( _sy, MONTH ( [Date] ), _sd ) ) <> MONTH ( [Date] ),
                    [Date] = EOMONTH ( [Date], 0 ),
                    MONTH ( [Date] ) <= _sm
                        && DAY ( [Date] ) = _sd
                )
            )
        )
    RETURN
        IF ( SELECTEDVALUE ( 'table'[date] ) IN _date, 1, 0 )
    

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

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