cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lardo5150
Microsoft
Microsoft

How to subtract with Forall

When I do a forall with a sum to add 1 to each value, it works perfectly.

Set(var_hours,ForAll(CollectHours,Sum(Value,1)))

 

But if I do -1 to subtract, I am getting an error.

Set(var_hours,ForAll(CollectHours,Sum(Value,-1)))

 

I can't find if there is an actual subtract function?

 

How do you subtract using the forall function?

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @lardo5150 ,

Just move the bracket

Set(
   var_hours,
   ForAll(
      CollectHours,
      Sum(Value)-1
  )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @lardo5150 ,

Just move the bracket

Set(
   var_hours,
   ForAll(
      CollectHours,
      Sum(Value)-1
  )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

@WarrenBelz , sorry, I should have put the full formula.

If(CurrentTimeZone.Text = "UTC-7:00",Set(var_hours,ForAll(CollectHours,Sum(Value)-1)));

I am still getting an error with this.

The formula contains 'ParenClose' where 'Eof' is expected

 

Again, the same one works for adding a 1.

If(CurrentTimeZone.Text = "UTC-6:00",Set(var_hours,ForAll(CollectHours,Sum(Value,1))));

That -1 seems to be giving me trouble.

lardo5150
Microsoft
Microsoft

ok, it is not the formula.  Playing around I found this.

I made the subtract formula first and it took.

I then added my others, and the little red squiggly showed up on a different formula that was working before.

So here is what I have.  I must be doing something wrong.

lardo5150_0-1643496674131.pnglardo5150_1-1643496707885.png

 

So essentially what I want to happen...

I get the current time zone of the user, which I have validated works.

I then run some if statements.  The one that matches gets set.

What am I doing wrong here?

If I use two of the formlas, it works.  when I add the third (and I still have to do pacific) it breaks.

I dont understand the error yet, but I think I fixed it.

 

If(CurrentTimeZone.Text = "UTC-8:00",Set(var_hours,ForAll(CollectHours,Sum(Value)-2)));
If(CurrentTimeZone.Text = "UTC-7:00",Set(var_hours,ForAll(CollectHours,Sum(Value)-1)));
If(CurrentTimeZone.Text = "UTC-6:00",Set(var_hours,ForAll(CollectHours,Sum(Value,1))));
If(CurrentTimeZone.Text = "UTC-5:00",Set(var_hours,ForAll(CollectHours,Sum(Value,0))));

Hi @lardo5150 ,

I have just run the below on a test list I have here adding a numeric field and received the expected result

If(
   User().Email = "xxxxxxx@xxxxxx.com",
   Set(
      var_hours,
      ForAll(
         TestFields,
         Sum(NumberTest) - 1
      )
   )
)

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.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,000)