Forum Discussion

Elango's avatar
Elango
New Member
1 year ago
Solved

Power BI

Hello everyone, I have a table that contains Start Date and End Date, and I’d like to display the years between these dates in a slicer. I also have a separate slicer for Customer, and based on the ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for the reply from danextian and saud968, please allow me to provide another insight.
    Hi Elango ,

    I am not sure how your source data table is designed, below is my sample.
    Create a table for creating a year slicer with years derived from the years between Start Date and End Date.

    Year_Slicer = 
    VAR _calendar =
        CALENDAR ( MIN ( 'Table'[Start Date] ), MAX ( 'Table'[End Date] ) )
    RETURN
        DISTINCT ( SELECTCOLUMNS ( _calendar, "Year", YEAR ( [Date] ) ) )

     

    Creates a measure to return a range of years for the selected user

    Year range = 
    IF (
        SELECTEDVALUE ( 'Table'[Customer] ) <> BLANK (),
        FILTER (
            'Year_Slicer',
            'Year_Slicer'[Year] >= YEAR ( MIN ( 'Table'[Start Date] ) )
                && 'Year_Slicer'[Year] <= YEAR ( MAX ( 'Table'[End Date] ) )
        ),
        1
    )

    Add this measure to the visual level filter of the year slicer.


    The final result is as follows, hopefully it will meet your needs.


    Please see tha attached pbix for reference.

    Best Regards,
    Dengliang Li

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