cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sobenson
Advocate II
Advocate II

Subtract from SharePoint column unless greater than 0

I am writing a flow that if someone changes a "status" column a second "priority" column will subtract 1 from the current value.  I am using the expression:

sub(outputs('Update_item_2')?['body/on0o'],1)

and it works, however I don't want to to go below zero.

I tried this, but it says my expression is invalid

if(triggerOutputs()?['body/on0o']>0,(sub(triggerOutputs()?['body/on0o'],1)),)

Any suggestions?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

 

if
(
  greater(variables('number'),0), sub(variables('number'),1), 0
)

 

See how you get on with that instead, I think your exact expression would be:

if
(
  greater(triggerOutputs()?['body/on0o'],0),(sub(triggerOutputs()?['body/on0o'],1)),0
)

But you will have to check your end.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

View solution in original post

2 REPLIES 2
Paulie78
Super User
Super User

 

if
(
  greater(variables('number'),0), sub(variables('number'),1), 0
)

 

See how you get on with that instead, I think your exact expression would be:

if
(
  greater(triggerOutputs()?['body/on0o'],0),(sub(triggerOutputs()?['body/on0o'],1)),0
)

But you will have to check your end.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

Hi @Paulie78 , thank you! 

You had one to many () in the sub statement in the example you copied of my info, (your example statement was correct) but this worked great!  Thanks!

 

This was the final working version

if(greater(triggerOutputs()?['body/on0o'],0),sub(triggerOutputs()?['body/on0o'],1),0)

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (3,221)