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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Deevo_
Resolver I
Resolver I

How to OPTIMISE SUMX and CROSSJOIN Measure

Hi All,

I have this measure which is used to sum up only the positive numbers that are a result from a measure.

How can I improve this formula below?

 

SUMX (
    CROSSJOIN ( VALUES('WBS Codes'[PSCode]), VALUES( 'Teams'[Division]), VALUES('Teams'[Branch]), VALUES('RoleNames'[RoleName]), VALUES(SpecialisationList[SpecialisationName])
    ),
    IF ( [Required Project Effort (Hrs)] - [Assignment (Hrs)] > 0, [Required Project Effort (Hrs)] - [Assignment (Hrs)], BLANK () )
)
 
Additional info:
  • All the 'VALUES()' in the crossjoin are all the different Tables and fields used in my matrix visual.
  • This formula is used to find the difference (either positive or negative values) 
    • Required Project Effort (Hrs)] - [Assignment (Hrs)]

Thanks in advance

1 ACCEPTED SOLUTION

Hi @Deevo_ 
To be honest, I've never encountered the very same situation. This is a bit different as 2 fact tables are involved and unless I do some testing I won't be able to provide a concrete conclusion. It is dificult in some cases to anticipate the shape of the query plan that would be generated out of the DAX code feed to the engine.
The following code might be evaluated at two stages where the storage engine is able to generate the crossjoin combinations that produces positive values then this list is fed up to the next query which will compute the expression again but only for these combinations. In this case if the number of relevant combinations is too low that could work fine. Otherwise the performance would be worse. 
The other possibility is that the storage engine produces an internal batch and computes everything internally while sending the final result only to the formula engine.

 

Formula =
SUMX (
    FILTER (
        CROSSJOIN (
            VALUES ( 'WBS Codes'[PSCode] ),
            VALUES ( 'Teams'[Division] ),
            VALUES ( 'Teams'[Branch] ),
            VALUES ( 'RoleNames'[RoleName] ),
            VALUES ( SpecialisationList[SpecialisationName] )
        ),
        [Required Project Effort (Hrs)] - [Assignment (Hrs)] > 0
    ),
    [Required Project Effort (Hrs)] - [Assignment (Hrs)]
)

 

View solution in original post

4 REPLIES 4
Deevo_
Resolver I
Resolver I

Thanks @tamerj1 for your help with this one! I believe i will have to rethink the requirements for this matrix visual because it is still quite slow to process when all values are selected from the slicer. I have tried to remove a couple of the columns in the matrix and instantly this renders the visual alot more quicker. 

 

I really appreciate your help and time!

tamerj1
Super User
Super User

Hi @Deevo_ 
Not much can be done without at least an overview of the data model, the report visual and the DAX of the nested measures. However, we may try to avoid an expensive callback and rather try to push the calculation back to the storage engine.

 

Formula =
VAR FinalResult =
    SUMX (
        CROSSJOIN (
            VALUES ( 'WBS Codes'[PSCode] ),
            VALUES ( 'Teams'[Division] ),
            VALUES ( 'Teams'[Branch] ),
            VALUES ( 'RoleNames'[RoleName] ),
            VALUES ( SpecialisationList[SpecialisationName] )
        ),
        VAR Result = [Required Project Effort (Hrs)] - [Assignment (Hrs)]
        RETURN
            Result * ( Result > 0 )
    )
RETURN
    IF ( FinalResult > 0, FinalResult )

 

Hi Tamerj1,

Thank you for replying. Your changes works a treat. I am using this with a slicer for Project Code, If i select all codes in the slicer, i receive an error "There not enough memory to complete this operation. Please try again later when there may be more memory available". I believe this is because I have 5 columns in the CROSSJOIN from different tables and this creates results for all the different combinations.

 

Can you think of another way to modify the measure to allow correct summation of the positive numbers only and not take up so much memory?

 

I can post some screenshots with the fields blanked out. I hope this helps!

The DAX of the nested measures are:

  • [Required Project Effort (Hrs)] = SUM('Required Project Effort'[Effort Hours per day])
  • [Assignment (Hrs)] = SUM('Assignments'[Effort Hours per day])

Datamodel:

Deevo__0-1713335492217.png

Matrix Table:

Deevo__0-1713336156807.png

 

Hi @Deevo_ 
To be honest, I've never encountered the very same situation. This is a bit different as 2 fact tables are involved and unless I do some testing I won't be able to provide a concrete conclusion. It is dificult in some cases to anticipate the shape of the query plan that would be generated out of the DAX code feed to the engine.
The following code might be evaluated at two stages where the storage engine is able to generate the crossjoin combinations that produces positive values then this list is fed up to the next query which will compute the expression again but only for these combinations. In this case if the number of relevant combinations is too low that could work fine. Otherwise the performance would be worse. 
The other possibility is that the storage engine produces an internal batch and computes everything internally while sending the final result only to the formula engine.

 

Formula =
SUMX (
    FILTER (
        CROSSJOIN (
            VALUES ( 'WBS Codes'[PSCode] ),
            VALUES ( 'Teams'[Division] ),
            VALUES ( 'Teams'[Branch] ),
            VALUES ( 'RoleNames'[RoleName] ),
            VALUES ( SpecialisationList[SpecialisationName] )
        ),
        [Required Project Effort (Hrs)] - [Assignment (Hrs)] > 0
    ),
    [Required Project Effort (Hrs)] - [Assignment (Hrs)]
)

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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