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

Wrong Totals Using IF and Values()

Hi, 

 

I am working on getting the amount of new sales and lost sales with regards to sales previous year and sales year to date. I am trying to show this in a table and then filtering that table with a year slicer. 

Below are the formulas that i have used: 

 

SalesPY = CALCULATE(SUM(SalesData[Value]),SAMEPERIODLASTYEAR('Calendar'[DateKey]))

 

SalesYTD = TOTALYTD(SUM(SalesData[Value]), 'Calendar'[DateKey])

 

NewSalesUppdate = SUMX(VALUES(SalesData[CustomerName]),IF([SalesYTD] > 0 && [SalesPY] = 0, [SalesYTD]))

 

LostSalesUppdate = SUMX(VALUES(SalesData[CustomerName]),IF([SalesYTD] = 0 && [SalesPY] > 0, -[SalesPY]))

 

LostSalesOld = IF([SalesPY] > 0 && [SalesYTD] = 0, -[SalesPY])

 

As you can see in the images below, the NewSalesUppdate formula works as it should and sums up correctly. However LostSalesUppdate does not work, deipite having pretty much the opposite formula compared with NewSalesUppdate. It seems like the IF statement never becomes true. That is strange because as you can see the LostSalesOld formula shows the right value, but it does not show the total. 

 

All tips are appreciated!

 

 

 

 

Newsales.png

 

 

Lostsales.png

 

 

3 REPLIES 3
v-ljerr-msft
Employee
Employee

Hi @Derf95,

 

That's a little weird. The logic of your measures seems all right. Could you share a sample pbix file which can reproduce the issue? You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading.Smiley Happy

 

Regards

Hi, @v-ljerr-msft

 

Thanks for your reply!

Here is a link to one drive where i have posted the test file: https://1drv.ms/u/s!AtXhBVThw98Ja07SGd9hSLPNGxo 
There are a few extra measures in the file, but the ones that should be focused on are the ones that i mentioned in the first post. In the report view you may switch from year 2015 to 2016 to see how newSales/lostSales work/Dont work. If you have any tips on changes i can make in order for the lostSales to show and sum up the right values, that would be great. 

 

Best Regards

Derf95
Frequent Visitor

After some more testing i have added the following formula to the table: 

 

CustomerNameCount = COUNTROWS(VALUES(SalesData[CustomerName]))

 

As you can see in the image below, it seems that the Values() method doesn´t work unless there exists a SalesYTD value. 

I just wanted to add that in case it can help someone figure out a solution. CustomerCount.png

 

 

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.