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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
NicholasJackson
Frequent Visitor

Creating Reusable Date Filters

I have a simple measure that gets the total sales for the given year: 

Total Sales (YTD) = CALCULATE(SUM([Sales Amount]), DATESYTD('Calendar'[Date]))

I have another measure where I would like to use the same date calculation, but instead use a different calculation: 

Total Orders (YTD) = CALCULATE(COUNTROWS('Sales'), DATESYTD('Calendar'[Date]))

In this case, the filter calculation is quite simple as DATESYTD takes care of the heavy lifting. Copy/pasting the DATESYTD calcuation between measures isn't difficult or cumbersome. However, I have other date filters that are much more complex and need to be used in multiple measures. 

 

How can I create a reusable (date) filter to use on multiple measures? 

 

Few ideas: 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @NicholasJackson 

I would recommend using Calculation Groups here.

Calculation Groups can be used to apply common modifications to multiple measures, with time intelligence being a common example.

 

The nice thing about Calculation Groups is that they can be applied either by a filter in the report, or by applying a filter in a DAX expression.

 

In your case, you could create a Calculation Group with a Calculation Item for each date filter. You can then apply a particular date filter to a calculation by filtering on the Calcualation Item by name, avoiding having to rewrite the DAX each time.

 

Here is an example of a calculation group (using DAX Script from Tabular Editor) with 5 Calculation Items:

 

-----------------------------------------------------
-- Calculation Group: 'Date Filter Calculation Group'
-----------------------------------------------------
CALCULATIONGROUP 'Date Filter Calculation Group'[Date Filter]

    CALCULATIONITEM "Default" = SELECTEDMEASURE ()
        Ordinal = 0

    CALCULATIONITEM "YTD" = 
        CALCULATE (
            SELECTEDMEASURE (),
            DATESYTD ( 'Date'[Date] )
        )
        Ordinal = 1

    CALCULATIONITEM "Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
        )
        Ordinal = 2

    CALCULATIONITEM "Previous Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PREVIOUSYEAR ( 'Date'[Date] )
        )
        Ordinal = 3

    CALCULATIONITEM "YTD as at TODAY" = 
        CALCULATE (
            SELECTEDMEASURE (),
            CALCULATETABLE (
                DATESYTD ( 'Date'[Date] ),
                'Date'[Date] = TODAY ()
            )
        )
        Ordinal = 4

 

Having created this Calculation Group, you can then apply a Calculation Item within a measure such as:

 

Sales Quantity YTD = 
CALCULATE (
    [Sales Quantity],
    'Date Filter Calculation Group'[Date Filter] = "YTD"
)

 

You can also filter on a particular Calculation Item in the report to apply it to multiple measures at a report/page/visual level.

 

For general background on Calculation Groups, there are various articles such as:

https://www.sqlbi.com/calculation-groups/

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @NicholasJackson 

I would recommend using Calculation Groups here.

Calculation Groups can be used to apply common modifications to multiple measures, with time intelligence being a common example.

 

The nice thing about Calculation Groups is that they can be applied either by a filter in the report, or by applying a filter in a DAX expression.

 

In your case, you could create a Calculation Group with a Calculation Item for each date filter. You can then apply a particular date filter to a calculation by filtering on the Calcualation Item by name, avoiding having to rewrite the DAX each time.

 

Here is an example of a calculation group (using DAX Script from Tabular Editor) with 5 Calculation Items:

 

-----------------------------------------------------
-- Calculation Group: 'Date Filter Calculation Group'
-----------------------------------------------------
CALCULATIONGROUP 'Date Filter Calculation Group'[Date Filter]

    CALCULATIONITEM "Default" = SELECTEDMEASURE ()
        Ordinal = 0

    CALCULATIONITEM "YTD" = 
        CALCULATE (
            SELECTEDMEASURE (),
            DATESYTD ( 'Date'[Date] )
        )
        Ordinal = 1

    CALCULATIONITEM "Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
        )
        Ordinal = 2

    CALCULATIONITEM "Previous Full Year" = 
        CALCULATE (
            SELECTEDMEASURE (),
            PREVIOUSYEAR ( 'Date'[Date] )
        )
        Ordinal = 3

    CALCULATIONITEM "YTD as at TODAY" = 
        CALCULATE (
            SELECTEDMEASURE (),
            CALCULATETABLE (
                DATESYTD ( 'Date'[Date] ),
                'Date'[Date] = TODAY ()
            )
        )
        Ordinal = 4

 

Having created this Calculation Group, you can then apply a Calculation Item within a measure such as:

 

Sales Quantity YTD = 
CALCULATE (
    [Sales Quantity],
    'Date Filter Calculation Group'[Date Filter] = "YTD"
)

 

You can also filter on a particular Calculation Item in the report to apply it to multiple measures at a report/page/visual level.

 

For general background on Calculation Groups, there are various articles such as:

https://www.sqlbi.com/calculation-groups/

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

This is exactly what I was looking for, thank you so much! 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.