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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
qianqianat007
Regular Visitor

Calculate sum of distinct category plus value of each blank category

Dear community, I am looking for a way to calculate sum of a column ("Value" colume in the table shown below). Appreciate any help you can provide. Thanks.

 

 Category 1Value
  50
  40
 A30
 A30
 B20
 C10
 C10
Expected result50+40+30+20+10150
1 ACCEPTED SOLUTION

@qianqianat007 
Please refer to attached sample file

1.png

Sum = 
SUMX (
    VALUES ( 'Table'[Category] ),
    IF (
        'Table'[Category] = BLANK (),
        SUMX ( CALCULATETABLE ( 'Table' ), 'Table'[Value] ),
        SUMX ( CALCULATETABLE ( VALUES ( 'Table'[Value] ) ), 'Table'[Value] )
    )
)

View solution in original post

13 REPLIES 13
tamerj1
Super User
Super User

Hi @qianqianat007 

please try

Sum =
SUMX (
VALUES ( 'Table'[Category] ),
IF (
'Table'[Category] = BLANK (),
SUMX ( CALCULATETABLE ( 'Table' ), 'Table'[Value] ),
SUMX ( CALCULATETABLE ( VALUES ( 'Table'[Value] ) ), 'Table'[Value] )
)
)

Dear @tamerj1 thanks for sharing your idea! I tried it and get 240 as result (expect 200).

@qianqianat007 

Can you please paste the code that you have tried?

@qianqianat007 

Can you please paste the code that you have tried?

Dear @tamerj1 I tried your this code and got 240 as result (expect 200).

 

Sum =
SUMX (
VALUES ( 'Table'[Category] ),
IF (
'Table'[Category] = BLANK (),
SUMX ( CALCULATETABLE ( 'Table' ), 'Table'[Value] ),
SUMX ( CALCULATETABLE ( VALUES ( 'Table'[Value] ) ), 'Table'[Value] )
)
)

@qianqianat007 
Please refer to attached sample file

1.png

Sum = 
SUMX (
    VALUES ( 'Table'[Category] ),
    IF (
        'Table'[Category] = BLANK (),
        SUMX ( CALCULATETABLE ( 'Table' ), 'Table'[Value] ),
        SUMX ( CALCULATETABLE ( VALUES ( 'Table'[Value] ) ), 'Table'[Value] )
    )
)

wow it works! thanks @tamerj1 

qianqianat007
Regular Visitor

Dear community, I am looking for a way to calculate sum of a column ("Value" colume in the table shown below). Appreciate any help you can provide. Thanks.

 

 Category 1Value
  50
  40
 A30
 A30
 B20
 C10
 C10
Expected result: 50+40+30+20+10=150

@Greg_DecklerIt works very well for this data sample, thank you! But in my real data, empty category rows can sometimes have same value (see below, expected result is 200). Any idea how can I solve this?

CategoryValue
 50
 40
 50
A30
A30
B20
C10
C10

@qianqianat007 I'm not quite clear as to the logic of what is supposed to be summed and what is not supposed to be summed. What is supposed to be summed in this latest example in order to get you to 200?



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

Dear @Greg_Deckler, in the latest example, for rows where Category is empty (row 1, 2, 3), each Value should be counted (50 + 50 + 40); for rows where Category is not empty (row 5 to 9), only distinct value should be counted (30 + 20 + 10).  Hope that's clear now.. Thanks!

 

CategoryValue   
 50   
 50   
 40   
A30   
A30   
B20   
C10   
C10   
expected result: 50 + 50 + 40 + 30 + 20 + 10 = 200

a small correction: row 5 to 9 --> row 4 to 8

@qianqianat007 Maybe something like SUMX(DISTINCT('Table'[Value]), [Value]) ?



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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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