Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Get the difference between two dates EASY

We have all been there, we need to check the difference between 2 dates, and if you ever had to implement this you would need to use some crazy mathematical equations using the ticks() expression. But now.. I’m not sure when this expression got added, but we can now use dateDifference() expression instead of using … Continue reading "Get the difference between two dates EASY"

image-1

jcook127001

Create easily the condition for Power Automate if(…) expression

“I’d like to use the if(…) expression but I don’t know how to create the condition, is there some trick in the Power Automate designer?”


Recently I published an article on replacing the ‘Condition’ actions with if(…) expressions to simplify a flow. Instead of a bunch of conditions and repeating actions you can have just a single action with if(…) expressions. But creating the right condition inside if(…) is a bit more complicated than using the standard action. How do you “rewrite” the condition? What should you “type in” as the first parameter of the expression?

Use the ‘Filter array’ action to create the condition

As with the trigger conditions, you can use a small trick and let the designer create the condition for you. Add the ‘Filter array’ action into your flow and recreate the condition you want to replace with the if(…) expression.

Click on ‘Edit in advanced mode’ to transform the condition inside ‘Filter array’ into text.

Remove the @ at the beginning and take the rest, that’s the condition to use as the first parameter in if(…).

Power Automate condition if expression

In this example to check whether a value is less than 3 it’d look as below.

if(less(outputs('Compose_-_Value'), 3), <ifTrue>, <ifFalse>)

Repeat the same process for all the ‘Condition’ actions you want to replace and build the whole expression step by step.

Summary

It might be a bit confusing when trying to replace the Power Automate ‘Condition’ with the if(…) expression, but it’s not that hard. If you use the workaround with the ‘Filter array’ action you don’t need to write the whole condition manually. Recreate the condition 1:1 in that action, switch to the text mode, remove the @, and the condition is ready. You can even combine multiple conditions together using this approach, just build it slowly, condition after condition.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Create easily the condition for Power Automate if(…) expression appeared first on Let's POWER Automate.

Replace multiple conditions with single Power Automate expression

“I feel that I’ve got too many conditions to handle basic stuff, can I somehow reduce/replace them to simplify my Power Automate flow?”


Conditions, one of the key building blocks in Power Automate. A simple decision: if “something” is true, do this, otherwise do that. But often it’s not that simple and if a condition is false it leads to another condition, another true or false. And the more potential options there’re, the more conditions you’ll need.

Is that really necessary? Isn’t there an easier way than a tree of conditions?

Replace the conditions with if(…) expressions

The Power Automate if(…) expression is the equivalent of the ‘Condition’ action. Instead of adding the action and then deciding e.g. on a value for some field, you can use the if(…) expression to get the correct value right away.

The basic if(…) expression was already explained in the date-formatting article and looks as below.

if(<condition>, <ifConditionIsTrue>, <ifConditionIsFalse>)

What you maybe didn’t know is that you combine them inside each other. Evaluate the first condition, and if it’s false try another evaluation.

if(<condition>, 
  <ifConditionIsTrue>, 
  if(<condition2>, 
    <ifCondition2IsTrue>, 
    <ifCondition2IsFalse>)
)

And it can go on an on, as many ifs as you need. But how do you build such expression?

Start from the last ‘Condition’

Let’s take an example, a flow where you translate a number into more generic value. If the number is less than 3 the value is LOW, for 3 or 4 it’s MID, and if it’s 5 or more it’s HIGH. When using the ‘Condition’ actions it’ll look as below.

To turn it into a single expression with if(…) start from the bottom. The last condition evaluates whether the value is less than 5.

if(less(outputs('Compose_-_Value'), 5),<ifTrue>,<ifFalse>)

You can use the trick with the ‘Filter array’ action if you’re not sure how to write such condition.

If it’s true, use the value MID, otherwise use the value HIGH.

if(less(outputs('Compose_-_Value'), 5), 'MID', 'HIGH')

That was the last condition, now let’s go one step higher, to the previous condition. The flow will reach the 2nd condition only if the first condition is false.

if(<condition>, <ifTrue>, if(less(outputs('Compose_-_Value'), 5), 'MID', 'HIGH'))

The first condition should evaluate whether the value is less than 3.

if(less(outputs('Compose_-_Value'), 3), 
  <ifTrue>, 
  if(less(outputs('Compose_-_Value'), 5), 
    'MID', 
    'HIGH'
  )
)

And if it’s true, it should use the value LOW.

if(less(outputs('Compose_-_Value'), 3), 
  'LOW', 
  if(less(outputs('Compose_-_Value'), 5), 
    'MID', 
    'HIGH'
  )
)

Since there’re no other conditions in the flow, that’s it. A single expression that’ll get the value without branching the flow.

Summary

Whenever you start stacking conditions in your Power Automate flow, you should reconsider whether they are needed, or if you can replace them and simplify the flow. Start from the last condition, convert it into if(…) expression, and keep adding the other conditions around it. At the end it can be a single expression that can replace a whole bunch of the ‘Condition’ actions.

It’s another concept complementing the configuration lists that’ll help you build more efficient and easier to manage flows.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Replace multiple conditions with single Power Automate expression appeared first on Let's POWER Automate.

How to navigate in an array within Power Automate flow

“I’d like to pick a specific item from an array, what’s the best approach to navigate in there using Power Automate?”


Arrays are a key part of almost every Power Automate flow. It can be an array of SharePoint items or Dataverse rows, array with users inside multiple people picker field, or any other array created by splitting a string. Often you want to process all the items, but in some situations you need just one specific value. How do you navigate in an array? How do you get the value on the first place, last place, or anywhere in between?

Get the first and last item

If you need the first or last item, you can use an expression. This is very often used to avoid loops in a flow – if there’s only one item you don’t need a loop, you can just take the first one and use it directly.

The expression to get the first item is first(…).

first(<array>)

With an example array [“a”, “b”, “c”] the first(…) expression will return “a”.

Power Automate navigate in array

The second expression, this one to get the last item is last(…).

last(<array>)

With an example array [“a”, “b”, “c”] the last(…) expression will return “c”.

Power Automate navigate in array

Get Nth item from an array

If you’re not interested in the first or last item, you can use also indexes in the array for navigation as explained in the JSON navigation article. Adding an index in square brackets will get you the specific item. It starts from 0 (first item) and goes up to length-1 (last item).

<array>[<index>]

As an example, to get the 2nd item use index 1.

Power Automate navigate in array

Getting item on a random index

It gets a lot more complicated if you don’t know the position. If you’re looking for some value but you’re not sure if it’s first, second, third, or anywhere else.

In general you should never get into that situation. It’s not easy to find index of a specific item. Instead of trying to do that you should pre-process the results.

Are you looking for a specific value? Use ‘Filter array’ before accessing the item to remove everything but that item from the array. Apply first(…) on the outcome and you’re done.

Are you looking for the highest/lowest value? Use the sort(…) expression to sort the array first. Move the desired item to the top or to the end of the array and then use first(…) or last(…).

Summary

When you navigate in an array in your Power Automate flow, you must always know what you’re looking for. Is it the first or last item? Use the first(…) or last(…) expression on the array. Is it always Nth item? Use the [index] to get the value. Don’t know the position of the value? Preprocess the array with sorting or filtering that’ll allow you to use one of the expressions or the index.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post How to navigate in an array within Power Automate flow appeared first on Let's POWER Automate.

Why the condition is false for the same numbers (Power Automate)

“I have two numbers, they’re the same, yet the condition in Power Automate evaluates as ‘false’ when comparing them!”


Comparing two numbers is such a common functionality in many Power Automate flows. You have two numbers and depending on their comparison the flow will do something. It can be a backup column to avoid infinite trigger loop via trigger condition, a rating from Forms, or just any two numbers. Yet even if the numbers look the same in the flow, when used in a ‘Condition’ it always returns ‘false’! Why? Why does it tell you that it’s not the same number even though you can see it is?

The same character, different format

If the ‘Condition’ doesn’t work you encountered a problem with different data types. There’s a difference whether the number is a number or a “text” that contains the number character. If they’re not the same type the ‘Condition’ can be evaluated as ‘false’.

To get the desired result you must convert both the values to the same type. There’re two expressions to convert a ‘number’ into a number.

Use int(…) to convert whole numbers

The first one is int(…) that’ll convert a numeric value into an integer.

int(<number>)

Note: <…> is a placeholder, replace it including the < and >.

But it must be a whole number with no decimal places. Once you try to convert a decimal number into integer the action will fail.

Power Automate condition false numbers

As such the int(…) expression is a good solution only when you’re 100% sure that the number won’t have any decimal places, e.g. when working with a date.

Use float(…) to convert decimal numbers

If your number can contain also decimal places, use the float(…) expression. This expression is more generic as it doesn’t care about the number format. If it’s a whole number – fine; if it’s a decimal number – also fine.

float(<number>)

Note: <…> is a placeholder, replace it including the < and >.

Power Automate condition false numbers

Once you have the numbers in the same format it should evaluate the conditions correctly.

Summary

When your Power Automate condition always returns ‘false’, even though you can see that the numbers are the same, try to play with the data type. There’s a chance that one of the numbers is a text, not a number, and Power Automate doesn’t like that. Take both sides of the condition and convert them into the same data type. If they’re whole numbers, you can use the int(…) expression, but once decimal numbers come into play you’ll have to use float(…).


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Why the condition is false for the same numbers (Power Automate) appeared first on Let's POWER Automate.

Check Conditions In Power Automate During Run

Is your IF condition always evaluating to False? Debugging and Testing your Flows should be easy. When using a Condition in Power Automate, in the run we cannot see the expression or the results of what is being evaluated. I will go over a quick workaround to debug and find out what is happening in the condition

FeatureIMG

jcook127001

Converting Time Zones Easily In Power Automate

Did you know that Power Automate has a Date Time action that can easily convert, and format time zones in one action? Why is this important? Power Automate natively uses UTC as its time zone, as well as most SharePoint sites. Using an action can be easier than using expressions.

FeatureIMG

jcook127001

❌
❌