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
zylawys
Frequent Visitor

Sum Rows in a Column which was created by a measure Help!

Hello,

 

I have a very simple table:

 

NameCostProjected
Job 11000
Job 2100150

 

I created a measure which will make a new column where if there is a 0 take the cost column, if its greater than 0 that the projected column.

 

Total Projected = IF(SUM(Sheet1[Projected]) = 0, SUM(Sheet1[Cost]), SUM(Sheet1[Projected]))

 

wrongtotals.PNG

 

This works, however the Total is only showing the number in the projected column so my line item is 150 not 250. I see that it is taking the sum of the column, but how can I get it to sum the rows off the condition?

 

Any help would be a lot of help.

6 REPLIES 6
mattbrice
Solution Sage
Solution Sage

Try:

 

=
SUMX (
    VALUES ( Sheet1[Name] ),
    IF (
        CALCULATE ( SUM ( Sheet1[Projected] ) ) = 0,
        CALCULATE ( SUM ( Sheet1[Cost] ) ),
        CALCULATE ( SUM ( Sheet1[Projected] ) )
    )
)

Thanks for the try but I do get the same results.

 

data.PNG

I switched up the data a bit but it still seems to just tally Projected column. not really sure where the 200 and 400 are coming from in the total projected column.

ok - data visualization was different from what your original sample showed.   I assumed you were grouping info by Name.   Only one row for 'Job 1', one row for 'Job 2', etc.

 

In your latest visualization, which are the row values, and which are meaures? 

I guess I should have spcified that. The last column in the picture is the measures. 

 

NameCostProjected
Job 11000
Job 11000
Job 11500
Job 10150
Job 10100
Job 10160
Job 22000
Job 22600
Job 22000
Job 20250
Job 20230
Job 20200

@zylawys

 

In this scenario, since you need to have those calculated values aggregated, you should use calculated column instead of measure. Otherwise, it will always evalulate entire table on Grand Total level. So for your formula:

 

Total Projected = IF(SUM(Sheet1[Projected]) = 0, SUM(Sheet1[Cost]), SUM(Sheet1[Projected]))

It will check the SUM(Sheet1[Projected]) for entire table first, if it's not 0, it will return the SUM(Sheet1[Projected]) of entire table as well.

 

Regards,

 

So you are saying 'Name', 'Cost', and 'Projected' are all NOT measures, but row values?  

 

The reason you are getting results the results you are is keep in mind Dax is an aggregation language.  Totals are not the sum of the rows above it, but rather have their own filter context.  

 

Having said that, I am not sure how your visual below can be.   There should not be rows where the values duplicate on a row basis.  For example, not sure how you got two rows where Name = Job 1, Cost = 100 and Projected = 0.

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.