cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerapps890
Post Prodigy
Post Prodigy

Update counter with a lookup

My counter resets whenever I change the data source. I want the counter to be updated when a checkbox is checked or unchecked. This is what I think it would be for checked Patch(
'CPQ Voting',
Coalesce(
LookUp('CPQ Voting', Title= varUserEmaill && CR=ThisItem.Name && Description=ThisItem.Description && Date=TodayD && Email_=PName && IDcol=ThisItem.Step),
Defaults('CPQ Voting')
),
{Title: varUserEmaill, CR:ThisItem.Name, Description:ThisItem.Description, Date:TodayD, Email_: PName, IDcol:ThisItem.Step});
UpdateIf(collCPQMasterData, Step=ThisItem.Step, {Description:ThisItem.Description}) . What would the uncheck and default be. My gallery us populated by CPQ and the checkboxes checked go in a datasource called CPQ Voting. I have a counter outside of the gallery.

31 REPLIES 31
powerapps890
Post Prodigy
Post Prodigy

RemoveIf(LookUp('CPQ Voting', Title= varUserEmaill && CR=ThisItem.Name && Description=ThisItem.Description && Date=TodayD && Email_=PName && IDcol=ThisItem.Step),
Defaults('CPQ Voting')
),
{Title: varUserEmaill, CR:ThisItem.Name, Description:ThisItem.Description, Date:TodayD, Email_: PName, IDcol:ThisItem.Step});
I can't get the syntax of the uncheck correct.

Try:

 

RemoveIf('CPQ Voting',ID = ThisItem.ID); Refresh('CPQ Voting')

(if the data source is a Sharepoint list, otherwise you should use the primary key of the datasource table).

 

Note, that this will erase your record from datasource !

well I also need to remove it from my collection collCPQMasterdata how do I do that? @gabibalaban 

@powerapps890 

Consider putting this all in the OnSelect action rather than the Check and UnCheck separately.

 

Patch(
    'CPQ Voting',
    Coalesce(
        LookUp('CPQ Voting', Title= varUserEmaill && 
                             CR=ThisItem.Name && 
                             Description=ThisItem.Description && 
                             Date=TodayD && 
                             Email_=PName && 
                             IDcol=ThisItem.Step
         ),
         Defaults('CPQ Voting')
     ),

    {Title: varUserEmaill, 
     CR:ThisItem.Name, 
     Description:ThisItem.Description, 
     Date:TodayD, 
     Email_: PName, 
     IDcol:ThisItem.Step,
     CheckValue: Self.Value
     }
);
UpdateIf(collCPQMasterData, Step=ThisItem.Step, 
    {Description:ThisItem.Description,
     CheckValue: Self.Value
    }
)

 

This assumes something that you might not have which is a CheckValue in your datasource.  There is no sense in adding and removing the record based on checked and unchecked.  If you add a column to your 'CPQ Voting' list called CheckValue and make it a Yes/No column, you will be able to achieve this.  

In the above formula, when the user clicks the checkbox (check or uncheck) the OnSelect action formula above will patch the 'CPQ Voting' list based on either the existing record (I believe you can simplify your lookup as well) or a new record if none exists.  It will then Patch that record with the information you want and will also post the state of the CheckBox - either true or false.

 

This above formula also assumes a CheckValue column in your Gallery collection - collCPQMasterData.  If you have none, since it is a collection, you can use the AddColumns function to add it.  It is not important for storing it, it is only because you will base the Default of your check box on it - ThisItem.CheckValue

 

Also, there is no need to Refresh a datasource if you make a direct Patch, Update. or Remove to it.  It will already be refreshed.  There is no need to incur the performance expense of a refresh.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

The collection and the data source works the same with the RemoveIf function.

 

RemoveIf(<collection or datasource>, <a condition which uniquely identify the record.)

@powerapps890 

If you remove it from your collection, you will lose that entire row in your gallery.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

When i put it in my onstart I just saw a lot of red underlines and this identifier isnt recognized @RandyHayes 

@powerapps890 

??? Why are you putting this in the OnStart??  Please re-read my post.  This goes in the OnSelect for the CheckBox in your Gallery.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I meant OnSelect, the entire thing says patch has invalid arguments. 

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,779)