cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Daemetius
Helper II
Helper II

Add a counter to a column with a button function in PowerApps

Hello,

 

I'm thinking of adding some sort of "+1" button in PowerApps where users see a a list of items and they "+1" the one they like most. This is a counter I need to make, but in order to do so I"m assuming I have to make a calculated column in the Sharepoint Online list that this powerapp is reading from.

 

What I don't know is if this is possible to make which is the counter column basically where it adds up everytime the "+1" button in PowerApps is pressed. 

 

Any input on this matter is greatly appreciated, I'm pretty stuck on this part

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
bean
Continued Contributor
Continued Contributor

Hmm.. I'd have thought using UpdateIf would have worked.. I'll re-iterate..

 

To increase likes on button click:

>Make sure you have added that sharepoint as a datasource

>Create button

   >Set onSelect: UpdateIf( yoursharepoint/datasource, Subject = "TED", {Likes: Likes+1})

 

After doing this, in theory.. If you press the button, you will see that any entry where the Subject is "TED", then the likes should be 1 higher than before.

 

To see likes via label:

>Ensure that the sharepoint has been added as a datasource

>Create a label

    >Set the text to: LookUp(yoursharepoint/datasource, Subject = "TED" ,Likes)

 

If this doesn't help, can you send more screenshots to help show what errors you are getting? If it does work, let me know..

 

Sean

 

View solution in original post

11 REPLIES 11
v-monli-msft
Community Support
Community Support

Hi @Daemetius,

 

You can do this using UpdateContext:

About the button control, set its Onselect property to UpdateContext({Test:Value1.Text+1})

About the Text box control, set its Text property to Test.

 

Value1 is the counter column number. 

 

More details about PowerApps UpdateContext function, please refer to this article:
https://powerapps.microsoft.com/en-us/tutorials/function-updatecontext/

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.


@v-monli-msft wrote:

Hi @Daemetius,

 

You can do this using UpdateContext:

About the button control, set its Onselect property to UpdateContext({Test:Value1.Text+1})

About the Text box control, set its Text property to Test.

 

Value1 is the counter column number. 

 

More details about PowerApps UpdateContext function, please refer to this article:
https://powerapps.microsoft.com/en-us/tutorials/function-updatecontext/

 

Regards,

Mona


 

I have a column called "Likes" in my list. I suppose I would replace Value1 with Likes, correct?

 

I don't have a textbox as you mention. I have the Likes data card showing. Should I add a text label instead?

 

Update: Got it to sum up on button press. My question is, is this number counter registered in the Sharepoint list? I want this Likes counter to appear on each record when the user is on the main screen which is the list of suggestions and next to the title the amount of likes. (See screenshot)

 

The main screenThe main screen

The amount of likes only shows in the detailed screen shown, but not the main screen above:

 

screen2.png

 

Is there a way to show this? 

bean
Continued Contributor
Continued Contributor

Add a column to the item in your sharepoint called "Likes". Then you could use UpdateIf() when a user presses the +like button. This will then update/increase the like for that item in the Sharepoint list. To display the likes value, probably use LookUp(). If the likes don't update when the button is pressed, just add put ;Refresh(datasource) after the update.

 

Hope that helps?

 

Sean


@bean wrote:

Add a column to the item in your sharepoint called "Likes". Then you could use UpdateIf() when a user presses the +like button. This will then update/increase the like for that item in the Sharepoint list. To display the likes value, probably use LookUp(). If the likes don't update when the button is pressed, just add put ;Refresh(datasource) after the update.

 

Hope that helps?

 

Sean


 

I had the Likes column created already in my list. The default value is 0 when an item is created.

My sharepoint list.PNG

 

the updateif isn't working at all. Isn't there a function that can directly alter a sharepoint value in it? 

 

bean
Continued Contributor
Continued Contributor

Hmm.. I'd have thought using UpdateIf would have worked.. I'll re-iterate..

 

To increase likes on button click:

>Make sure you have added that sharepoint as a datasource

>Create button

   >Set onSelect: UpdateIf( yoursharepoint/datasource, Subject = "TED", {Likes: Likes+1})

 

After doing this, in theory.. If you press the button, you will see that any entry where the Subject is "TED", then the likes should be 1 higher than before.

 

To see likes via label:

>Ensure that the sharepoint has been added as a datasource

>Create a label

    >Set the text to: LookUp(yoursharepoint/datasource, Subject = "TED" ,Likes)

 

If this doesn't help, can you send more screenshots to help show what errors you are getting? If it does work, let me know..

 

Sean

 

View solution in original post

bean
Continued Contributor
Continued Contributor

Actually, on the gallery, add a text label and try add this to it's Text: LookUp(yoursharepoint/datasource, Subject = This.Subject ,Likes)


@bean wrote:

Hmm.. I'd have thought using UpdateIf would have worked.. I'll re-iterate..

 

To increase likes on button click:

>Make sure you have added that sharepoint as a datasource

>Create button

   >Set onSelect: UpdateIf( yoursharepoint/datasource, Subject = "TED", {Likes: Likes+1})

 

After doing this, in theory.. If you press the button, you will see that any entry where the Subject is "TED", then the likes should be 1 higher than before.

 

To see likes via label:

>Ensure that the sharepoint has been added as a datasource

>Create a label

    >Set the text to: LookUp(yoursharepoint/datasource, Subject = "TED" ,Likes)

 

If this doesn't help, can you send more screenshots to help show what errors you are getting? If it does work, let me know..

 

Sean

 


It works! Thank you so much! I've yet to try the labels since they show already. But will try it either way!

 

The only thing I'd like to know is if it's possible to have this Updateif() without the Subect= "TED" as this specified only on one item in the list. Instead is it possible to add that condition based on whatever it is written? Because in the long run when a bunch of users start adding ideas and other people start liking them, it will probably up the likes for the TED record only with this. 

 

I'm guessing it has to do with passing the values from the Subject textbox in the EditScreen:

 

editscreen.png

 

 

 However I'm not familiar with trying to pass values from one screen to another

 

Is this possible?

  

Once again, thank you very much!

bean
Continued Contributor
Continued Contributor

Good to hear.

 

Yup. You're almost there. You can get the text from the box you type in.

So instead of saying the subject="TED", you can have it as Subject=InputBox1.Text

 

 

Passing values from one screen to another is possible. I'd reccomend looking at the Set command. This is basically a global variable - a variable which can be accessed from anywhere in your application(Not screen restricted, like UpdateContext()).

See https://powerapps.microsoft.com/en-us/tutorials/function-set/ and check out the examples. 

 

Keep at it - you'll be a pro in no time at all.

 

Sean

 

 

 

Hi, 

 

I have an app for liking/disliking outfits. 

I have LIKES and DISLIKES columns in my excel data. 

I  have buttons for Like and Dislike. 

I want the excel data to be updated when Like button is pressed. I set the onselect property of the button as 

UpdateContext( {LIKESVAR: (LIKESVAR + 1)} ), and default property of like datacard as likesvar+ likes 

However the excel data doesnt get updated. 

Please help me 🙂 

 

Thanks 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (72,001)