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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Bokazoit
Post Patron
Post Patron

Is there a better way to handle this date control in my measure?

Before I created my memberbase on historical subscriptions per member. That was a small table consisting of 250.000 rows and this measure to show historical development over time worked well:

 

Memberships= 

Var MaxDate = MAX ( DimDate[Date] )

RETURN

CALCULATE( 
    CALCULATE (
        COUNT ( FactDonor[#Donornummer] ),
        FILTER (
            FactDonor,
                    (
                    FactDonor[CreateDate] <= MaxDate
                    && FactDonor[EndDate] > MaxDate
                    )
                ),
        ALL ( DimDate )
    ),
    CROSSFILTER ( FactDonor[CreateDate], DimDate[DateKey], NONE )
)

 

Now I had to add more change to members, so that I for each row look at membership date as well as changes to other parts such as adress and member-specific things. That means that I have to create lines with change date within the membership dates. It only for added a little over 100.000 rows and my measure now looks like this:

 

Membership = 

Var MaxDate = MAX ( DimDate[Date] )

RETURN

CALCULATE( 
    CALCULATE (
        DISTINCTCOUNT ( FactDonor[#Donornummer] ),
        FILTER (
            FactDonor,
                    (
                    FactDonor[CreateDate] <= MaxDate
                    && FactDonor[EndDate] > MaxDate
                    )
                ),
         FILTER (
            FactDonor,
                    (
                    MaxDate >= FactDonor[ChangeStartingDate]
                    && MaxDate <= FactDonor[ChangeEndingDate]
                    )
                ),
        ALL ( DimDate )
    ),
    CROSSFILTER ( FactDonor[CreateDate], DimDate[DateKey], NONE )
)

 

My main issue is that the measure is way slower, when creating a chart with memberships per month since january 2021. So is the new measure written correctly or would You handle the change part differently?

2 REPLIES 2
johnt75
Super User
Super User

There's a couple of things you could clean up. As you're already using ALL(DimDate) there is no need to set the cross filter direction to none as no filters are being applied.

You're also filtering the entire fact table, its better to just filter the columns you need.

You can try

Membership =
VAR MaxDate =
    MAX ( DimDate[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( FactDonor[#Donornummer] ),
        FactDonor[CreateDate] <= MaxDate
            && FactDonor[EndDate] > MaxDate
            && MaxDate >= FactDonor[ChangeStartingDate]
            && MaxDate <= FactDonor[ChangeEndingDate],
        ALL ( DimDate )
    )

It may also be worth comparing the performance of this measure with a version where the filters are applied individually, so rather than using && to combine them you simply use commas to separate them into different clauses.

Thank You so much!!!! You made my day better 😉

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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