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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

slow measure and need help

hello I need help with a measure that i am using in a coumn.  i have 120 GB available and it runs out of memory.  there is 20 million rows in the table 

here is the measure 

HLC =
VAR Active =
CALCULATE (
SUM ( Full_FACT_SALES[if active] ),
FILTER (
ALLEXCEPT ( Full_FACT_SALES, Full_FACT_SALES[Customer_ID] ),
Full_FACT_SALES[Transaction_DateTime]
<= MAX ( Full_FACT_SALES[Transaction_DateTime] )
)
)
VAR New =
CALCULATE (
SUM ( Full_FACT_SALES[if new] ),
FILTER (
ALLEXCEPT ( Full_FACT_SALES, Full_FACT_SALES[Customer_ID] ),
Full_FACT_SALES[Transaction_DateTime]
<= MAX ( Full_FACT_SALES[Transaction_DateTime] )
)
)
VAR Reactivated =
CALCULATE (
SUM ( Full_FACT_SALES[if Reactivated] ),
FILTER (
ALLEXCEPT ( Full_FACT_SALES, Full_FACT_SALES[Customer_ID] ),
Full_FACT_SALES[Transaction_DateTime]
<= MAX ( Full_FACT_SALES[Transaction_DateTime] )
)
)
VAR Risk =
CALCULATE (
SUM ( Full_FACT_SALES[if Risk] ),
FILTER (
ALLEXCEPT ( Full_FACT_SALES, Full_FACT_SALES[Customer_ID] ),
Full_FACT_SALES[Transaction_DateTime]
<= MAX ( Full_FACT_SALES[Transaction_DateTime] )
)
)
VAR Lapsed =
CALCULATE (
SUM ( Full_FACT_SALES[if Lapsed] ),
FILTER (
ALLEXCEPT ( Full_FACT_SALES, Full_FACT_SALES[Customer_ID] ),
Full_FACT_SALES[Transaction_DateTime]
<= MAX ( Full_FACT_SALES[Transaction_DateTime] )
)
)
RETURN
IF (
Active > 0,
"Active",
IF (
New > 0
&& Active = 0
&& Risk = 0
&& Lapsed = 0,
"New",
IF (
Risk > 0
&& New = 0
&& Active = 0,
"Risk",
IF (
Lapsed > 0
&& New = 0
&& Active = 0
&& Risk = 0,
"Lapsed",
IF (
New > 0
&& Lapsed > 0
&& Active = 0
&& Risk > 0,
"Reactivated",
IF (
New > 0
&& Lapsed > 0
&& Active = 0
&& Risk = 0,
"Reactivated",
IF ( New > 0 && Lapsed = 0 && Active = 0 && Risk > 0, "Reactivated", "" )
)
)
)
)
)
)
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Try formula as below:

HLC =
VAR T_DT =
    MAX ( Full_FACT_SALES[Transaction_DateTime] )
VAR Active =
    CALCULATE (
        SUM ( Full_FACT_SALES[if active] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR New =
    CALCULATE (
        SUM ( Full_FACT_SALES[if new] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR Reactivated =
    CALCULATE (
        SUM ( Full_FACT_SALES[if Reactivated] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR Risk =
    CALCULATE (
        SUM ( Full_FACT_SALES[if Risk] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR Lapsed =
    CALCULATE (
        SUM ( Full_FACT_SALES[if Lapsed] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
RETURN
    IF (
        Active > 0,
        "Active",
        SWITCH (
            TRUE (),
            New > 0
                && Active = 0
                && Risk = 0
                && Lapsed = 0, "Risk",
            Lapsed > 0
                && New = 0
                && Active = 0
                && Risk = 0, "Lapsed",
            New > 0
                && Lapsed > 0
                && Active = 0
                && Risk > 0, "Reactivated",
            New > 0
                && Lapsed > 0
                && Active = 0
                && Risk = 0, "Reactivated",
            New > 0
                && Lapsed = 0
                && Active = 0
                && Risk > 0, "Reactivated",
            ""
        )
    )

 

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Try formula as below:

HLC =
VAR T_DT =
    MAX ( Full_FACT_SALES[Transaction_DateTime] )
VAR Active =
    CALCULATE (
        SUM ( Full_FACT_SALES[if active] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR New =
    CALCULATE (
        SUM ( Full_FACT_SALES[if new] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR Reactivated =
    CALCULATE (
        SUM ( Full_FACT_SALES[if Reactivated] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR Risk =
    CALCULATE (
        SUM ( Full_FACT_SALES[if Risk] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
VAR Lapsed =
    CALCULATE (
        SUM ( Full_FACT_SALES[if Lapsed] ),
        ALL ( Full_FACT_SALES[Transaction_DateTime] ),
        Full_FACT_SALES[Transaction_DateTime] <= T_DT
    )
RETURN
    IF (
        Active > 0,
        "Active",
        SWITCH (
            TRUE (),
            New > 0
                && Active = 0
                && Risk = 0
                && Lapsed = 0, "Risk",
            Lapsed > 0
                && New = 0
                && Active = 0
                && Risk = 0, "Lapsed",
            New > 0
                && Lapsed > 0
                && Active = 0
                && Risk > 0, "Reactivated",
            New > 0
                && Lapsed > 0
                && Active = 0
                && Risk = 0, "Reactivated",
            New > 0
                && Lapsed = 0
                && Active = 0
                && Risk > 0, "Reactivated",
            ""
        )
    )

 

Best Regards,
Community Support Team _ Eason

Anonymous
Not applicable

Switch is a good suggestion i will try that now.  

Greg_Deckler
Community Champion
Community Champion

Yeah, you should check out my Performance Tuning DAX series (4 parts) here: https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275

 

Performance Tuning DAX is no joke, it is involved and not sure I can really help without having access to the data and being able to experiment. Your nested IF statements should be replaced with a SWITCH statement. Logic can likely be improved. You have a lot of repeated code that you should use variables for. You use the same FILTER over and over again, store that FILTER in a table variable and do a SUMX across it for each of your New, etc. variables.

 

Just a few thoughts.

 
 
 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors