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

Summary Error with IF Statement

Hello,

 

I'm having issues with an IF and/or SUMX formula. I essentially need the calculation done at every line level & then aggregated. With my first attempt using IF, the results are correct at the line level but don't sum up properly. It should show $21K, not $35K.

 

I assume I really need to be using SUMX, but that doesn't seem to be calcing at the line level correctly. Can anyone help pinpoint what I'm doing wrong? Here are my measures:

 

 

08.a Expired Release via Scrap = IF([01. Expired PQ] < [07. Gross Scrap] , [01. Expired PQ] , [07. Gross Scrap] ) * -1

 

08.a2 Expired Release via Scrap = CALCULATE(SUMX(EEORE, IF([01. Expired PQ] < [07. Gross Scrap] , [01. Expired PQ] , [07. Gross Scrap]) * -1 ))

 

 

Example.PNG

 

 

Thanks! 

J

 

11 REPLIES 11
v-ljerr-msft
Employee
Employee

Hi @aminw0u,

 

According to your descriptions above, you may need to firstly summarize your data at [Generic SKU Name] level, then use SUMX to get the correct total in your scenario. The formula below is for your reference. Smiley Happy

08.a Expired Release via Scrap =
SUMX (
    SUMMARIZE (
        EEORE,
        EEORE[Generic SKU Name],
        "abc", IF ( [01. Expired PQ] < [07. Gross Scrap], [01. Expired PQ], [07. Gross Scrap] )
            * -1
    ),
    [abc]
)

 

Regards

I think it makes sense to summarize, but when I do that, it gives me an answer that is even more incorrect than before unfortunately. Smiley Sad The 08.3 column is the one that includes the summarize formula.

 

08.e Expired Release via Scrap =
SUMX (
SUMMARIZE (
EEORE,
EEORE[Generic SKU Name],
"abc", IF ( [01. Expired PQ] < [07. Gross Scrap], [01. Expired PQ], [07. Gross Scrap] )
* -1
),
[abc]
)

 

 

Summarize.PNG

Phil_Seamark
Employee
Employee

Hi @aminw0u

 

Are the lines in your matrix an exact match to the lines in your source data?  Or are these aggregated values?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

They are aggregated on some level. I have a data set with 34 columns & I only pulled 7 of those into my filter to drill down through before I got to what you see here.

So for SKU Name 87 you have a values of $71 and $88

 

Are these values based on multiple rows that have been aggretated to this single line?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Yes, there are several lines which make up that particular row. If it helps, my data is inventory data so it goes down to the SKU, manufacturing site & current branch.

 

BranchCode.PNG

Are the detail lines from the same EEORE table or from a related table?  I think we are getting close to the issue.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Everything is pulling from the same table (which is the original data load).

 

I'm using the latest version that was released Nov 7th.

Possibly but this seems like it should be pretty straight forward.  What version of Power BI Desktop are you using?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Here is a cut down model using your exact formula showing it working ok

 

https://1drv.ms/u/s!AtDlC2rep7a-oB-2n_WxkVzte_RD

 

So just trying to work out the differences.  Are you using calculated measures or calculated columns?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks. I'm using measures. The Expired PQ & Gross Scrap are measures as well. I had tried calculated columns earlier & got  circular references, so that didn't seem like the way to go.

 

Is it possible that this is just a bug? I would have expected my formula to work the same as what you have in your file, and I've had several instances of formulas not working when they should have (including while at a DIAD training with Microsoft instructors looking over my shoulder wondering why it wasn't working).

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.