cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jaimat
Frequent Visitor

Calculate number of approvals with dropdown OnChange

I am trying to count the approvals in three dropdown boxes where each of which has two choices "Approved" and "Pending". If all the three different dropdowns are "Approved" by different approvers at different time then the Power Apps moves to final closing. There may be one to three approvers.

 

My application works fine if there is straight "Approved" as I am counting each dropdown value in a Text Box. But the count fails if an approver selects "Approved" and then changes its mind and selects 'Pending" before saving.

 

I try to balance this with formula OnChange property of the dropdown. varChange has been initiatialized to 0 at screen OnVisible:

If(ddlDropdown1.Selected.Value="Approved",UpdateContext({varChange:varChange+1})); 

If(varChange>0 && !ddlDropdown1.Selected.Value="Approved", UpdateContext({varChange:varChange-1}))

 

The first part of adding 1 is working but it does not reduce the varChange value in second part.

 

It was also tried:

If(ddlDropdown1.Selected.Value="Approved",UpdateContext({varChange:Value(1)}),

ddlDrodown1.Selected.Value="Pending", UpdateContext({varChange:Value(0)}))

Again not success.

 

How do I change between adding 1 and reducing one value in the above scenario of the dropdown change of "Approved" and "Pending"

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @jaimat .

 

Could you please try this?

If(
ddlDropdown1.Selected.Value="Approved",
UpdateContext({varChange:varChange+1}), 
ddlDropdown1.Selected.Value="Pending"&& varChange > 0,
UpdateContext({varChange:varChange-1})
)

or

 

If(
ddlDropdown1.Selected.Value="Approved",
UpdateContext({varChange:1}), 
ddlDropdown1.Selected.Value="Pending"&& varChange > 0,
UpdateContext({varChange:0})
)​

Hope this helps.

Sik

View solution in original post

3 REPLIES 3
v-siky-msft
Community Support
Community Support

Hi @jaimat .

 

Could you please try this?

If(
ddlDropdown1.Selected.Value="Approved",
UpdateContext({varChange:varChange+1}), 
ddlDropdown1.Selected.Value="Pending"&& varChange > 0,
UpdateContext({varChange:varChange-1})
)

or

 

If(
ddlDropdown1.Selected.Value="Approved",
UpdateContext({varChange:1}), 
ddlDropdown1.Selected.Value="Pending"&& varChange > 0,
UpdateContext({varChange:0})
)​

Hope this helps.

Sik

Wow!! This works like a charm. Thank you very much. The numbers are adding and subtracting correctly. Do not see a place to mark this as solution. Would just like to conform one more thing. I am putting the number of each approval(only "Approved") in a Text Input box. Each approver has to Save after his selection in a SharePoint list). The Default of the the Text Box is: If(varChange>0,Parent.Default+varChange,Parent.Default). Can this fail in any condition!! Also I trying to check OnSuccess of Save as follow: If(SharePointIntegration.Selected.TotalNeededApprovals=SharePointForm1.LastSubmit.TotalApprovals,Patch({ID:txtSPID.Text},{Status:"Completed"})). Should it be done some other way!! Thanks again for the above solution. It was a great boost.

leyburn19
Memorable Member
Memorable Member

I assume the Dropdowns have Approved, Pending, Not Approaved?
I would look at having a hidden label with a value based on the dropdown and the reference the label's result.

 

Eg:

 

If(ddlDropdown1.Selected.Value="Approved","1",If(ddlDropdown1.Selected.Value="Pending","2","3")

 

using this you also do not need the varChange variable and you can referenc the label result for your submit process and it is always based on the visible value of the dropdown,  no need for onchange

 

If(value(Label?.Text)=1,"""""" etc

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,787)