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
atult
Advocate I
Advocate I

Calculate Sum of Column 1 only if Column 2 is not blank

Hello Experts,
Data:

 

atult_3-1661176199533.png

 

Expected Result:
- Calculate sum of Sales only if Units is not blank
- Sales Sum = 10 + 20 + 40 = 70; Sales = 30 for XYZ is skipped since Units is blank for it

 

I'm using below dax in calculated measure but it is not working:

Total Sales = IF(SUM('Sales_Table'[Units]) = BLANK(),BLANK(),SUM('Sales_Table'[Sales]))
2 ACCEPTED SOLUTIONS

@atult 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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Anand24
Super User
Super User

Hi @atult ,
Try below dax:

Total Sales = 
CALCULATE(
    SUM('Sales_Table'[Sales]),
    'Sales_Table'[Units] <> BLANK()
)

For ease of Filtered Measure DAX, you can directly go to quick measure -> filtered value and then change your dax accordingly. 

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

View solution in original post

6 REPLIES 6
Anand24
Super User
Super User

Hi @atult ,
Try below dax:

Total Sales = 
CALCULATE(
    SUM('Sales_Table'[Sales]),
    'Sales_Table'[Units] <> BLANK()
)

For ease of Filtered Measure DAX, you can directly go to quick measure -> filtered value and then change your dax accordingly. 

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

Greg_Deckler
Super User
Super User

@atult Perhaps try this:

Total Sales = IF(SUM('Sales_Table'[Units]) <= 0,BLANK(),SUM('F_ORDERED Sales_Table'[Sales]))

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,
The total for Total Sales is still considering Sales value of XYZ:

atult_0-1661176895640.png

 

@atult 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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler ,
Tried the below but not helping:

Total Sales = 
IF(
    HASONEFILTER(Sales_Table[Category]),
    IF(
        SUM(Sales_Table[Units]) = BLANK(),0,SUM(Sales_Table[Sales])
        ),
        SUMX(
            FILTER(Sales_Table,
            [Units]>1000
            ),
        [Sales]
        )
)

@atult Keep your original measure. Create a new measure:

Total Sales = 
IF(
    HASONEFILTER(Sales_Table[Category]),
    [Original Measure],
    SUMX(SUMMARIZE('Table',[Category],"__Sales",[Original Measure]),[__Sales])
)

For Measure Totals to work, you have to summarize or summarizecolumns or groupby your data exactly as it is in the visual and then use an X aggregator across that summarized table.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.