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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
sarahomar955
Regular Visitor

Visual is loading very slowly due to DAX Query taking very very long time

Can you help me optimize this? 

Here we want to get the amount of the non selected (ch, ch3,mc, brand)

DAX: notselected_customers =
    var qq = (Quantity[Quantity Value] / 100)
    return CALCULATE(
        CALCULATE([UNIT] * SUM('SBI Actuals Agg (x100)'[QTY_USED])) +
        CALCULATE([UNIT] * SUM('SBI Actuals Agg (x100)'[QTY_USED]) * qq),
        FILTER(
            ALL('SBI Actuals Agg (x100)'[ch], 'SBI Actuals Agg (x100)'[mc], 'SBI Actuals Agg (x100)'[brand], 'SBI Actuals Agg (x100)'[ch3]),
            NOT (
                'SBI Actuals Agg (x100)'[ch] IN VALUES('SBI Actuals Agg (x100)'[ch]) &&
                'SBI Actuals Agg (x100)'[mc] IN VALUES('SBI Actuals Agg (x100)'[mc]) &&
                'SBI Actuals Agg (x100)'[brand] IN VALUES('SBI Actuals Agg (x100)'[brand]) &&
                'SBI Actuals Agg (x100)'[ch3] IN VALUES('SBI Actuals Agg (x100)'[ch3])
            )
        )
    )
1 ACCEPTED SOLUTION
saud968
Super User
Super User

Simplified the FILTER Logic:

The original query used multiple IN VALUES checks within the FILTER function. This can be inefficient.
The revised query keeps the same logic but aims to streamline it. However, further optimization could involve using EXCEPT to filter out selected values more efficiently.
Combined Calculations:

The original query had nested CALCULATE functions, which can be resource-intensive.
The revised query combines the calculations into a single CALCULATE function. This reduces the complexity and potentially improves performance.
Simplified Multiplication:

The original query had separate CALCULATE functions for different parts of the multiplication.
The revised query combines these into a single multiplication operation: [UNIT] * SUM('SBI Actuals Agg (x100)'[QTY_USED]) * (1 + qq).
Here's the revised query again for reference:

notselected_customers =
VAR qq = (Quantity[Quantity Value] / 100)
RETURN
CALCULATE(
[UNIT] * SUM('SBI Actuals Agg (x100)'[QTY_USED]) * (1 + qq),
FILTER(
ALL('SBI Actuals Agg (x100)'[ch], 'SBI Actuals Agg (x100)'[mc], 'SBI Actuals Agg (x100)'[brand], 'SBI Actuals Agg (x100)'[ch3]),
NOT (
'SBI Actuals Agg (x100)'[ch] IN VALUES('SBI Actuals Agg (x100)'[ch]) &&
'SBI Actuals Agg (x100)'[mc] IN VALUES('SBI Actuals Agg (x100)'[mc]) &&
'SBI Actuals Agg (x100)'[brand] IN VALUES('SBI Actuals Agg (x100)'[brand]) &&
'SBI Actuals Agg (x100)'[ch3] IN VALUES('SBI Actuals Agg (x100)'[ch3])
)
)
)
These changes should help improve the performance of your DAX query.

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

View solution in original post

2 REPLIES 2
sarahomar955
Regular Visitor

Amazing thank you!

saud968
Super User
Super User

Simplified the FILTER Logic:

The original query used multiple IN VALUES checks within the FILTER function. This can be inefficient.
The revised query keeps the same logic but aims to streamline it. However, further optimization could involve using EXCEPT to filter out selected values more efficiently.
Combined Calculations:

The original query had nested CALCULATE functions, which can be resource-intensive.
The revised query combines the calculations into a single CALCULATE function. This reduces the complexity and potentially improves performance.
Simplified Multiplication:

The original query had separate CALCULATE functions for different parts of the multiplication.
The revised query combines these into a single multiplication operation: [UNIT] * SUM('SBI Actuals Agg (x100)'[QTY_USED]) * (1 + qq).
Here's the revised query again for reference:

notselected_customers =
VAR qq = (Quantity[Quantity Value] / 100)
RETURN
CALCULATE(
[UNIT] * SUM('SBI Actuals Agg (x100)'[QTY_USED]) * (1 + qq),
FILTER(
ALL('SBI Actuals Agg (x100)'[ch], 'SBI Actuals Agg (x100)'[mc], 'SBI Actuals Agg (x100)'[brand], 'SBI Actuals Agg (x100)'[ch3]),
NOT (
'SBI Actuals Agg (x100)'[ch] IN VALUES('SBI Actuals Agg (x100)'[ch]) &&
'SBI Actuals Agg (x100)'[mc] IN VALUES('SBI Actuals Agg (x100)'[mc]) &&
'SBI Actuals Agg (x100)'[brand] IN VALUES('SBI Actuals Agg (x100)'[brand]) &&
'SBI Actuals Agg (x100)'[ch3] IN VALUES('SBI Actuals Agg (x100)'[ch3])
)
)
)
These changes should help improve the performance of your DAX query.

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.