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
Anonymous
Not applicable

Measure and Total Row with Decimals

I've been running into an issue with calculating row values and total values for a measure. The measure includes calculations involving rounding and division by a parameter. Each column value for the measure is rounded appropriately after dividing, but the total row ends up a number or two off since the total row value is rounded for the sum. For the total row, I would like each row value to be rounded individually and then summed - At that point, the total row sum should be correct.

The data goes like this:

Parameter = Customers/Staff Ratio = 125 Customers/Staff

State | Customers | Current Staff | New Staff

New Staff is the measure here. New Staff can't be negative (we don't want to remove staff) - If the calculation is less than 0, then we set it to 0 (no new staff).

I set up the first measure like this:

New Staff =
ROUND((SUM(Customers[CountOfCustomers]) / 'CustomerRatio'[CustomerRatio Value]),0) - SUM(Staffing[CountOfStaff])

The result of this calculation is the calculated New Staff value based on the customer count dividided by the ratio parameter. After that, we subtract the current staff. Before rounding, this would usually be a decimal. This can be a negative or positive number.

For the table visualization, I do another measure to get a non-negative number. If the value is negative, I set it to 0 (no new staff). I am trying the HASONEFILTER method to calculate the row value and total row values separately:

New Staff NN =
IF(
     HASONEFILTER(Staffing[State]),
     IF(
          [New Staff] > 0,
          [New Staff],
          0
     ),
     CALCULATE(
         [New Staff],
         FILTER(Staffing,[New Staff] > 0)
     )

)

The problem is with the CALCULATE function for the total row value. It is coming up 1 or 2 numbers off because of the rounding. If I leave out rounding and have decimals, it matches just fine. However, with staffing, we can't get 0.3 people, so I round

I'm thinking a SUMX is needed here for the total row, but can't seem to figure it out. Any suggestions?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

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

2 REPLIES 2
Greg_Deckler
Super User
Super User

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...
Anonymous
Not applicable

I had read your first post after some searching last night and was trying to do that.

 

The second post did the trick... impressive!  

 

Marking as solution... thanks so much Greg.

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.