Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Switch function not calculating total

Not sure if this is a duplicate post.  Submitted before but received an error and I don't see the post anywhere.

Anyway, I have the following SWITCH funtion which gives me the exact result I am looking for:

 

Daily Non-Compliant = SWITCH(
TRUE(),
'Prod Ops'[Prod Shipments]=0 && [Test Shipments] = 0,ROUNDUP(sum('Ops Plan'[Weekly Planned Frequency])/265,0),
0
)
 
However, as you can see from the attached picture, the total for this column displays zero.  Anyone know why?Switch.PNG
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

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



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

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



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you, @Greg_Deckler.  The Final Word solution worked.  

 

I created this measure:

 
Daily Non-Compliant 2 = SWITCH(
TRUE(),
[Total Shipments]=0, ROUNDUP(sum('Ops Plan'[Weekly Planned Frequency])/265,0),
0
)
 
Then I created this measure:
Daily Non-Compliant = 
VAR __table = SUMMARIZE('Ops Plan','Ops Plan'[Carrier SCAC] ,"__value",[Daily Non-Compliant 2])
RETURNIF(HASONEVALUE('Ops Plan'[Carrier SCAC]),[Daily Non-Compliant 2],SUMX(__table,[__value]))


 
The totals now seem to be correct.  
Anonymous
Not applicable

I will delve into this and see if I can come up with a formula that works based on your post.  Any idea why it is showing zero for this particular column?  I double checked the totals for my other measures and they seem to be correct.

Hi @Anonymous,

 

Did you solve it? It could be like this. 

 

Daily Non-Compliant =
SWITCH (
    TRUE (),
    'Prod Ops'[Prod Shipments] = 0
        && [Test Shipments] = 0, ROUNDUP ( SUM ( 'Ops Plan'[Weekly Planned Frequency] ) / 265, 0 ),
    NOT HASONEVALUE ( 'Prod Ops'[Prod Shipments] )
        && NOT HASONEVALUE ( [Test Shipments] ), SUM ( 'Ops Plan'[Weekly Planned Frequency] ),
    0
)

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-jiascu-msft, I'm not sure exactly how the formula is supposed to work, but you can see below that there are errors in the format.

 

Formula Error.PNG

Hi @Anonymous,

 

It seems the 'Prod Ops'[Prod Shipments] is a measure. In short, the newly added step judges the context of the Total and then assign the proper value to the Total before it takes the default value 0. 

What should the 'Prod Ops'[Prod Shipments] be for the Total? Then it could be like below.

'Prod Ops'[Prod Shipments] <> 0, SUM ( 'Ops Plan'[Weekly Planned Frequency] ),

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-jiascu-msft, I may have to try a different approach.  I replaced the measure in the formula you provided with the column I used to get the measure.  When I did this, a total was displayed, however it was the total of the entire Weekly Planned Frequency column.  What I am trying to do is this:

There is a weekly plan with the expected number of shipments.

You are either compliant or non-compliant.

If you have Production Shipments or Test Shipments, you are compliant.  

If you have zero test shipments and zero production, you are non-compliant.

If you are non-compliant, the number of non-compliant shipments is equal to the number we expected (the Weekly Plan)

So, the total in the non-compliant column should only be those carriers with non-compliant shipments.  With the formula you provided, the total seems to be showing the sum of the entire Weekly Planned Frequency column.

The total line evaluates in the context of ALL rows in the table. So, it is likely that one of your criteria for the SWITCH to not return 0 is not true in the context of ALL and thus you get 0 as specified in the formula. 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.