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
Ttaylor9870
Helper III
Helper III

Should be easy fix I am just baffled, DAX to change values from negative to zeros

Hi All,

I have this measure...

Free Stock Value =
Sum('ABC'[Quantity]) - Sum('DEF'[Outstanding Quantity])
 
Any way I can get this measure to change negative values returned into 0's?
 
I've used...
 
IF(Free Stock Value < 0, 0, Free Stock Value) 


And it works fine but the total stays the exact same and doesn't add up properly it still assumes there is negative values present.
 
Any help would be greatly appricated!
 
Manuy Thanks,
 
Taylor
1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

I recommend reading this article by sqlbi to understand what is going on here: Obtaining accurate totals in DAX - SQLBI

Basically the totals work in mysterious ways and even if your measure would work on a row level it will not work at total level. E.g. 

ValtteriN_1-1674646986553.png

Measure 36 = IF(SELECTEDVALUE('Table (20)'[Column1])<0,0, SUM('Table (20)'[Column1]))
^^ won't work


Measure 37 = SUMX(FILTER('Table (20)', 'Table (20)'[Column1] >= 0), 'Table (20)'[Column1])
^^ will work
ValtteriN_2-1674647585424.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/






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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @Ttaylor9870 

when you say negative Free Stock Value, negative under what context?

Hi @FreemanZ,

 

Negative e.g. I subtract the 2 values away from eachother. Both numbers in the columns are always going to be positive so the new number in the measure column could possible be negative and I want those negatives to display zero instead of displaying as the negative number.

 

I am trying to work out free stock so....

 

Quantity = Stock currently sitting

Outstanding = Stock sold

 

 

 

 

 

 

 

 

ValtteriN
Super User
Super User

Hi,

I recommend reading this article by sqlbi to understand what is going on here: Obtaining accurate totals in DAX - SQLBI

Basically the totals work in mysterious ways and even if your measure would work on a row level it will not work at total level. E.g. 

ValtteriN_1-1674646986553.png

Measure 36 = IF(SELECTEDVALUE('Table (20)'[Column1])<0,0, SUM('Table (20)'[Column1]))
^^ won't work


Measure 37 = SUMX(FILTER('Table (20)', 'Table (20)'[Column1] >= 0), 'Table (20)'[Column1])
^^ will work
ValtteriN_2-1674647585424.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/






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

Proud to be a Super User!




Nice @ValtteriN I will give it a read! Many Thanks!

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.

Top Solution Authors