cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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. 

6 REPLIES 6
Super User III
Super User III

@tcorcor11 

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:

Length.jpg

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

Scott
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:

ftest.png

 

The expression used for the switch value is 

items('Apply_to_each')['_statecode_label']

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

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (12,880)