Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Using a Switch inside a Apply To Each loop produces very incorrect results

I am getting all opportunities and looping through them incrementing variables that essentially count the # of open, won, lost opportunities. I have tried to do one List Items call and applying a Switch within the result but when i do that the results i get are wildly inaccurate. However, when i do 3 GET calls for open, won and lost then loop through those arrays and count the opportunties that are open/won/lost i get correct numbers back..


This is the second time i have tried to use a switch in a loop and had issues. Anyway, wanted to see if anyone experienced this as well. 

Super User III
Super User III


I have had mixed results using a Switch action but nothing like you are experiencing.  In my case, items that should match the particular switch branch just don't match.....  In many cases it works as expected.


That said, I do want to mention that you don't need to loop through the Get Items result to get a count - you just need to use a length expression:


If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Dual Super User II
Dual Super User II

Hi @tcorcor11 , 


I used Switch Case in my flow and it worked perfect. Please have a look at the flow below:



The expression used for the switch value is 


Are you using the same way? 


Hope this helps!


If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Yeah, thats basically the exact same thing i am doing.

Just to confirm, you are creating 3 separate variables right? (one each for Won Lost and Open)?

Correct. Other things happening in the lool happen but updating variables seems to be where i see mixed results

Thanks Scott. This works great for length but have you used an expression to SUM an attribute in an array? Currently, i am incrementing a variable to get the SUM of an item in an array. Thanks again

Helpful resources

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group


Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (76,759)