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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.