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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jimbob2285
Advocate II
Advocate II

SUMX to total a measure

Hi

 

I've created a measure in my Purchase Order (PO) table that sums the value of receipts from the receipt table:

  • This is a meausre, so that it's reactive to a slicer on the page
  • because it's a meausres, it doesn't show the correct total in the table visual
  • which I've achieved with a second SUMX measure, but there must be a way to do this all with a single measure
  • My two measure are:

 

ReceiptValue = 
CALCULATE(
    SUM(Receipt[Value]),
    FILTER(
        Receipt,
        Receipt[PONumber] = MAX(PO[PONumber]) && 
        [_SelectedMonth_CUM_R] = 1
    )
)
ReceiptValue_X = 
SUMX(
    VALUES(PO),
    PO[ReceiptValue]
)

 

Could anyone help condense these two measures into a single measure please

 

Cheers

Jim

2 ACCEPTED SOLUTIONS
v-huijiey-msft
Community Support
Community Support

Hi @jimbob2285 ,

 

Thank you for your interest in this case.

 

The reason for the error is that this measure is not calculated correctly, and since there is no relationship between the two tables, slicer does not affect this value, and MAX(Receipt[Date]) always returns 1/12/2024.

vhuijieymsft_0-1737011953875.png

vhuijieymsft_0-1737012093285.png

 

The solution is to create a Measure:

 

Measure =
VAR MyFilterTable =
    SUMMARIZE (
        FILTER (
            ALL ( 'CalendarFilter' ),
            'CalendarFilter'[Date] <= SELECTEDVALUE ( 'CalendarFilter'[EOMonth] )
        ),
        'CalendarFilter'[Date]
    )
VAR _vtable =
    SELECTCOLUMNS (
        'Receipt',
        'Receipt'[PONumber],
        "_Value", IF ( 'Receipt'[Date] IN MyFilterTable, 1 )
    )
RETURN
    IF (
        ISINSCOPE ( PO[PONumber] ),
        SUMX (
            FILTER ( _vtable, [PONumber] = SELECTEDVALUE ( PO[PONumber] ) ),
            [_Value]
        ),
        SUMX ( _vtable, [_Value] )
    )

 

 

The final page visualization is shown below:

vhuijieymsft_2-1737011953885.png

 

The pbix file is attached for your reference.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

BIswajit_Das
Super User
Super User

Hello @jimbob2285 
As per your requirement you can check the below DAX

ReceiptValue =
SUMX(SUMMARIZE('PO','PO'[PONumber],"RESULT",
CALCULATE(
    SUM(Receipt[Value]),
    FILTER(
        Receipt,
        Receipt[PONumber] = MAX(PO[PONumber]) &&
        [_SelectedMonth_CUM_R] = 1
    )
)
),[RESULT])

Thanks & Regards

View solution in original post

8 REPLIES 8
BIswajit_Das
Super User
Super User

Hello @jimbob2285 
As per your requirement you can check the below DAX

ReceiptValue =
SUMX(SUMMARIZE('PO','PO'[PONumber],"RESULT",
CALCULATE(
    SUM(Receipt[Value]),
    FILTER(
        Receipt,
        Receipt[PONumber] = MAX(PO[PONumber]) &&
        [_SelectedMonth_CUM_R] = 1
    )
)
),[RESULT])

Thanks & Regards
v-huijiey-msft
Community Support
Community Support

Hi @jimbob2285 ,

 

Thank you for your interest in this case.

 

The reason for the error is that this measure is not calculated correctly, and since there is no relationship between the two tables, slicer does not affect this value, and MAX(Receipt[Date]) always returns 1/12/2024.

vhuijieymsft_0-1737011953875.png

vhuijieymsft_0-1737012093285.png

 

The solution is to create a Measure:

 

Measure =
VAR MyFilterTable =
    SUMMARIZE (
        FILTER (
            ALL ( 'CalendarFilter' ),
            'CalendarFilter'[Date] <= SELECTEDVALUE ( 'CalendarFilter'[EOMonth] )
        ),
        'CalendarFilter'[Date]
    )
VAR _vtable =
    SELECTCOLUMNS (
        'Receipt',
        'Receipt'[PONumber],
        "_Value", IF ( 'Receipt'[Date] IN MyFilterTable, 1 )
    )
RETURN
    IF (
        ISINSCOPE ( PO[PONumber] ),
        SUMX (
            FILTER ( _vtable, [PONumber] = SELECTEDVALUE ( PO[PONumber] ) ),
            [_Value]
        ),
        SUMX ( _vtable, [_Value] )
    )

 

 

The final page visualization is shown below:

vhuijieymsft_2-1737011953885.png

 

The pbix file is attached for your reference.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

jimbob2285
Advocate II
Advocate II

Hi

 

I've applied new measures from both the code solutions that were kindly provided in:

  • Example PBIX
  • Both seem to be the same solution, it's just that one of them is wrapped in another Calculate
  • However, both lose their total when I select an earlier month in the slicer
  • My orignal secondary measure (ReceptValue_X) is the only one that retains the total when an earlier month is selected

What am I doing wrong?

 

Cheers

Jim

Greg_Deckler
Super User
Super User

@jimbob2285 Posting this to vote for the idea. First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

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

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
anmolmalviya05
Super User
Super User

Hi , hope you are doing good!
You can consolidate the logic into a single measure to calculate the correct total directly in the table visual without needing a second measure. Here's the improved single-measure approach:

ReceiptValue =
SUMX(
VALUES(PO[PONumber]),
CALCULATE(
SUM(Receipt[Value]),
FILTER(
Receipt,
Receipt[PONumber] = MAX(PO[PONumber]) &&
[_SelectedMonth_CUM_R] = 1
)
)
)

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

 

Let's Connect on LinkedIn: https://www.linkedin.com/in/anmol-malviya/?originalSubdomain=in

 

Subscribe my youtube channel for Microsoft Fabric and Power BI updates: https://www.youtube.com/@AnmolPowerBICorner



@jimbob2285

Hi

 

Thanks, I've applied your code as a measure:

  • In Example PBIX
  • However, it loses the total when I select an earlier month in the slicer
  • But my orignal secondary measure (ReceptValue_X) seems to retain the total 

What am I doing wrong?

 

Cheers

Jim

bhanu_gautam
Super User
Super User

@jimbob2285 , Use SUMX within calculate like

 

ReceiptValue_Combined =
CALCULATE(
SUMX(
VALUES(PO[PONumber]),
CALCULATE(
SUM(Receipt[Value]),
FILTER(
Receipt,
Receipt[PONumber] = MAX(PO[PONumber]) &&
[_SelectedMonth_CUM_R] = 1
)
)
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi

 

Thanks, I've applied your code as a measure:

  • In Example PBIX
  • Which seems to be the same solution as anmolmalviya05's but yours is wrapped in an additional calcuate
  • However, it loses the total when I select an earlier month in the slicer
  • But my orignal secondary measure (ReceptValue_X) seems to retain the total 

What am I doing wrong?

 

Cheers

Jim

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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