Источник:
https://crmtipoftheday.com/1322/inco...ower-automate/
==============
&tl;dr
When using
Increment variable or
Decrement variable actions, use
coalesce function in the parameter to avoid unexpected results.
Explanation
It was a dark and stormy night. The tax was calculated in a Power Automate flow by looping through the array of applicable records and incrementing a total variable by the tax field value. The client threw a book at me and said that total tax is off by a few dollars. True story. (Except the throw and the book,
the storm was real).
It’s not uncommon in Common Data Service (lol) to imply that when a decimal or money field contains
null it’s equivalent to 0. For example,
null tax means no tax or zero tax. The fun begins when you try to calculate total over an array of records.
What’s the result of this flow?
6? 7? 8? 9?We wouldn’t be here if it was 6, right? The answer is 8.
Increment variable action implies the value of 1 for the
Increment By parameter is not provided (value is null).
The fix is easy – use
coalesce function.
coalesce(items('Apply_to_each'),0)And the result is now 6 which is about as much as Facebook pays in tax in a year. The above applies to
Decrement variable action as well. Duh…
Источник:
https://crmtipoftheday.com/1322/inco...ower-automate/