Skip to main content
Post

#PowerPlatformTip 100: 'Bypassing Complexity in PowerAutomate'

#PowerPlatformTip 100: 'Bypassing Complexity in PowerAutomate'

TL;DR: For a lookup table with known keys, store options in a JSON object in a Compose action and access a key with outputs('Compose')?[variables('InputValue')].

💡 Challenge

Standard use of Switch or Condition in Power Automate can often be bypassed for more streamlined processes. A Switch with a dozen cases, or worse, nested Conditions three levels deep, is slow to read, slow to extend (every new case means editing the flow’s structure), and turns a simple “look up a value by key” need into a maintenance burden.

✅ Solution

Pass a simple identifier to Power Automate. Use a dynamic formula to retrieve corresponding data, avoiding complex structures.

🔧 How It’s Done

Here’s how to do it:

  1. Add a Compose action in Power Automate with a structured JSON object.
    🔸 Use a JSON object with keys “A”, “B” and “C”.

    🔸 Example:

    🔸 Assume InputValue is a flow variable containing the selected key. To get the Title: outputs('Compose')?[variables('InputValue')]?['Title']. { “A”: { “Title”: “Ok”, “Description”: “Text” }, “B”: { “Title”: “Confirmed”, “Description”: “Approved” 🔸 Wrap the lookup in coalesce(outputs('Compose')?[variables('InputValue')]?['Title'], 'Unknown') so an input value that doesn’t match any key in the object falls back to a sensible default instead of silently passing null downstream, where it can surface much later as a confusing error in an unrelated action. “C”: { “Title”: “Denied”, “Description”: “Rejected” } } ```

  2. Use a dynamic formula to retrieve the desired value.
    🔸 Assume InputValue is a flow variable containing the selected key. To get the Title: outputs('Compose')?[variables('InputValue')]?['Title'].

    🔸 To get the Description: outputs('Compose')?[variables('InputValue')]?['Description']

    🔸 Note the double ?: the first guards against InputValue not existing as a key at all (returns null instead of erroring the whole expression), the second guards against that entry existing but not having a Title property. Drop either ? and an unexpected input value fails the whole action instead of degrading gracefully.

  3. Handle unknown or missing keys explicitly.
    🔸 Wrap the lookup in coalesce(outputs('Compose')?[variables('InputValue')]?['Title'], 'Unknown') so an input value that doesn’t match any key in the object falls back to a sensible default instead of silently passing null downstream, where it can surface much later as a confusing error in an unrelated action.

  4. Nest it one level for environment- or tenant-specific config.
    🔸 The same pattern can extend to a second dimension. If EnvironmentValue and InputValue are flow variables, look up with outputs('Compose')?[variables('EnvironmentValue')]?[variables('InputValue')]?['Title'].

Power Automate real flow run: a JSON lookup object resolves key B to Confirmed/Approved without any Switch or Condition action Real flow run: a 3-key JSON object (A/B/C) plus the runtime key "B" resolves straight to Confirmed, no Switch action anywhere in the flow.

Power Automate real flow run: Code View of the double safe-navigation lookup expression Real flow run: Code View confirms the actual expression, @outputs('Status_Options')?[outputs('Input_Value')]?['Title'], the double ? guards both the missing-key and missing-property case.

🎉 Result

This method allows fetching specific data (‘Title’ or ‘Description’) for different entries (‘A’, ‘B’, ‘C’) without needing complex conditions or switches, and degrades gracefully instead of failing when a new, not-yet-mapped identifier shows up.

🌟 Key Advantages

🔸 Streamlines data retrieval

🔸 Reduces workflow complexity

🔸 Keeps lookup data and key access together in a Compose action

🔸 Extends cleanly to multi-dimensional lookups (e.g. per-environment config) without adding more branching actions

🎥 Video Tutorial

🛠️ FAQ

1. What are the benefits of using a structured JSON object instead of Switch or Condition?

Using structured JSON can reduce branching and simplify maintenance when the lookup is a good fit for a key-value object.

2. Can this approach handle more than three cases?

Yes, you can add as many keys and values to the JSON object as needed.

3. How do I handle missing or invalid input values?

Implement default values or wrap the expression with error handling, e.g. using coalesce or condition checks before accessing the value.

🔸 #PowerPlatformTip 33: ‘Coalesce’ - the fallback function to reach for when a key is missing from the Compose lookup above.

🔸 #PowerPlatformTip 37: ‘Table to JSON’ - build the lookup object itself from tabular data instead of typing it by hand.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.