Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
HarryBailey
Helper II
Helper II

Dynamic Date Measures

Hi all,

 

I was looking to see if I can build dynamic date measures that I could use in a slicer. I know how to use dates filters such as YTD within specitic measures themseves, but I want date measures that are overriding for all other measures.

 

The best way to describe this would be quite simply, I have a very simple slicer here based off a seperate financial calendar. When I click week 9, everything in my data returns from WK9, as the dates in my data are linked to the finalcial calendar.

 

query 3.PNG

 

But what I need is the option for, say YTD, or last 4 weeks as options on the slicer above. So I can just click YTD there, without having to do seperate measures for each field.

 

Financial calendar is below FYI.

 

 query 4.PNG

1 ACCEPTED SOLUTION
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please take following steps:

1)Create a new slicer table:

SlicerTable = 
UNION (
    DISTINCT (
        SELECTCOLUMNS ( 'Financial calendar', "_WeekNo", 'Financial calendar'[WeekNo] )
    ),
    DATATABLE ( "YTD", STRING, { { "YTD" } } )
)

2)Try this measure:

Measure = 
IF (
    SELECTEDVALUE ( SlicerTable[WeekNo] ) = "YTD",
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] IN FILTERS ( 'Table'[Year] ) )
    ),
    IF (
        VALUE ( SELECTEDVALUE ( SlicerTable[WeekNo] ) ) = MAX ( 'Table'[WeekNo] ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Financial calendar',
                'Financial calendar'[WeekNo] = VALUE ( SELECTEDVALUE ( SlicerTable[WeekNo] ) )
            )
        )
    )
)

3)When select "YTD" in slicer, the result shows each year's YTD values:

2.PNG

See my attached pbix file.

 

Best Regards,

Giotto

 

View solution in original post

3 REPLIES 3
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please take following steps:

1)Create a new slicer table:

SlicerTable = 
UNION (
    DISTINCT (
        SELECTCOLUMNS ( 'Financial calendar', "_WeekNo", 'Financial calendar'[WeekNo] )
    ),
    DATATABLE ( "YTD", STRING, { { "YTD" } } )
)

2)Try this measure:

Measure = 
IF (
    SELECTEDVALUE ( SlicerTable[WeekNo] ) = "YTD",
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] IN FILTERS ( 'Table'[Year] ) )
    ),
    IF (
        VALUE ( SELECTEDVALUE ( SlicerTable[WeekNo] ) ) = MAX ( 'Table'[WeekNo] ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Financial calendar',
                'Financial calendar'[WeekNo] = VALUE ( SELECTEDVALUE ( SlicerTable[WeekNo] ) )
            )
        )
    )
)

3)When select "YTD" in slicer, the result shows each year's YTD values:

2.PNG

See my attached pbix file.

 

Best Regards,

Giotto

 

Mariusz
Community Champion
Community Champion

Hi @HarryBailey 

 

To achieve this you will need to build the calculation Measures for each time frame that you need ( YTD, last 4 weeks ) and later use the below technique to switch between them.

https://www.youtube.com/watch?v=gYbGNeYD4OY

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

 

amitchandak
Super User
Super User

@HarryBailey , Not very clear, Are you looking for - https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.