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

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

Reply
Anonymous
Not applicable

Unusual SUMX behaviour

Hello, I am working on a measure that needs to sum up the number of instances where the inventory of a product goes below a specified minimum quantity. This needs to be done over multiple days and for multiple store locations. 

I have managed to do this but my measure is too slow. I am close to figuring out a faster measure that works but I need some assistance. 

 

The measure that works but is too slow is:

 

Less Than Min - Slow = 
    VAR LessThanMin =
    SUMX(
        SUMMARIZE(
            'Calendar',
            'Calendar'[Date],
            "Available", 
            COUNTROWS (
                FILTER (
                    ADDCOLUMNS (
                        CROSSJOIN (
                            VALUES ( 'Product'[Product_No] ),
                            VALUES ( 'Location'[Store Name] )
                        ),
                        "Quantity on Hand", [Quantity on Hand]
                    ),
                    [Quantity on Hand] <= [Min Qty] 
                        && NOT ( ISBLANK ( [Quantity on Hand] ) )
                )
            )
        ),
        [Available]
    )

    Return 
        LessThanMin

 

 

The measure that is faster but not quite working is:

 

Less Than Min - Not Working = 
    
    VAR CrossjoinTable = 
        FILTER(
            ADDCOLUMNS (
                CROSSJOIN (
                    VALUES ( 'Product'[Product_No] ),
                    VALUES ( 'Location'[Store Name] )
                ),
                "Quantity on Hand", [Quantity on Hand]
            ),
            NOT ( ISBLANK ( [Quantity on Hand] ) )
        )

    VAR LessThanMin =
        SUMX(
            SUMMARIZE(
                'Calendar',
                'Calendar'[Date],
                "Available", 
                COUNTROWS (
                    FILTER (
                        CrossjoinTable,
                        [Quantity on Hand] <= [Min Qty] 
                    )
                )
            ),
            [Available]
        )

    Return
        LessThanMin

 


On the image here below you can see an example of one product at one location.
The inventory goes below the minimum quantity for 15 days during the period.
You can see that the measure that is not quite working is identifying the right days but does not sum up the days (Column total is blank) 

Arni_Thor_Jakob_0-1621442821216.png

 

The only difference in the two measures is that the crossjoin table has been made a variable in the second measure, which is why I don't understand why SUMX behaves in a different manner. 

 

Any assistance would be greatly appreciated!

 

Best regards, 
Arni Thor

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



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...

View solution in original post

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@Anonymous This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



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
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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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