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
vickyd
Helper V
Helper V

SUMX Performance issue.. looking for an alternative

 

Is there a better performing DAX formula that can do the same thing this does. 

 

Missing Hrs:=SUMX(VALUES('Employee'[Employee ID]), IF([Expected Hrs] < [Submitted Hrs] , 0, [Expected Hrs] - [Submitted Hrs]))

I basically want to take each employee and if their Submitted Hours is less then their Expected Hours I want to know how much they are missing. If Submitted Hours is more than or equal to Expected Hours then Missing Hours should be 0 or blank.  

 

This does the job but is pretty slow. Is there a better way to do this?

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@vickyd

As a first suggestion, use the MAX function to avoid repeated calculation of the two measures:

 

Missing Hrs :=
SUMX (
    VALUES ( 'Employee'[Employee ID] ),
    MAX ( 0, [Expected Hrs] - [Submitted Hrs] )
)

If you could give details of the [Expected Hrs] or [Submitted Hrs] measures or the data model structure, there might be further improvements possible.

 

BTW - your original measure seemed to have the inequality the opposite way from what I expected, but the above measure should match your description.


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

View solution in original post

4 REPLIES 4
elif3028
New Member

Thank you."Max" perfect solution.

v-shex-msft
Community Support
Community Support

Hi @vickyd,

 

I'd like more information to help clarify your scenario.

How to Get Your Question Answered Quickly

 

You can also take a look at following blog told about optimizing nested measures performance.

Optimizing DAX expressions involving multiple measures

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
OwenAuger
Super User
Super User

@vickyd

As a first suggestion, use the MAX function to avoid repeated calculation of the two measures:

 

Missing Hrs :=
SUMX (
    VALUES ( 'Employee'[Employee ID] ),
    MAX ( 0, [Expected Hrs] - [Submitted Hrs] )
)

If you could give details of the [Expected Hrs] or [Submitted Hrs] measures or the data model structure, there might be further improvements possible.

 

BTW - your original measure seemed to have the inequality the opposite way from what I expected, but the above measure should match your description.


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


@OwenAuger wrote:

@vickyd

As a first suggestion, use the MAX function to avoid repeated calculation of the two measures:

 

Missing Hrs :=
SUMX (
    VALUES ( 'Employee'[Employee ID] ),
    MAX ( 0, [Expected Hrs] - [Submitted Hrs] )
)

If you could give details of the [Expected Hrs] or [Submitted Hrs] measures or the data model structure, there might be further improvements possible.

 

BTW - your original measure seemed to have the inequality the opposite way from what I expected, but the above measure should match your description.


This helped cut down the time to about half of what it was. For some reason didn't bother checking for MAX in DAX but that is exactly what I was looking for. Expected Hours and Submitted Hours are straight sums and work fast so don't think much to do there in terms of optimization.

 

Another option I tried was to use variables to avoid the the measures from being calculated twice. That had a similar effect too but above is just simpler.  

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.