cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Counting the number of times a button is pushed and clearing repeated rows.

Hi guys, 

 

I am attempting to build a parts catalog, with in the app i would like to add a part to a data table then return the number of times that part is added into a single row with the number of time the part was added. 

 

The formula i am currently using is this: 

 

Collect(DataTable2, {NO:'S-#', PARTCODE : Product, QTY : inCart +1, DESCRIPTION : Description, MATERIAL : None}); Set(inCart, CountIf(DataTable2, PARTCODE = ThisItem.Product))

 

However, I am having issues removing repeddative rows and getting the QTY correct. 

 

Thanks in advance for the help! 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Counting the number of times a button is pushed and clearing repeated rows.

Hi @Jagarrison1 ,

Have you taken a try with the above solution I provided?

 

If you want to remove repeated rows from your DataTable2, I think the solution I provided above could achieve your needs. Please take a try with the solution I provided above, then check if the issue is solved.

 

In addition, based on the needs that you mentioned, I suppose that you want to add 1 to the QTY column when you add same product into your DataTable2 rather than add a new row for the same Product, is it true?

If you just want to add 1 to the QTY column when you add same product into your DataTable2 rather than add a new row for the same Product, I think there is something issue with your formula.

I have made a test on my side, please take a try with the following workaround. Please modify your formula as below:

If(
!IsBlank(LookUp(DataTable2, PARTCODE = Product)), /* <-- Check if the DataTable2 collection has contained same Product record already */
Patch(DataTable2, LookUp(DataTable2, PARTCODE = Product), {QTY: QTY+1}),
Collect(DataTable2, {NO:'S-#', PARTCODE : Product, QTY : 1, DESCRIPTION : Description, MATERIAL : None})
);
Set(inCart, CountIf(DataTable2, PARTCODE = ThisItem.Product))

Please consider take a try with above solution, then check if the issue is solved. Then within your DataTable2, it would not contain repeated rows for same Product, and the Qty column would store correct value.

 

More details about the Patch function, please check the following article:

Patch function

 

Best regards,

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

View solution in original post

3 REPLIES 3
Highlighted
Community Support
Community Support

Re: Counting the number of times a button is pushed and clearing repeated rows.

Hi @Jagarrison1 ,

Do you want to remove the repeated rows from the DataTable2 collection?

 

I assume that the PARTCODE Column is the Primary column in your DataTable2 collection, which could identify one record uniquely, is it true?

 

If you want to remove the repeated rows from the DataTable2 collection, please take a try with the following formula:

ForAll(
          RenameColumns(DataTable2, "PARTCODE", "PARTCODE1"),
If(
CountRows(Filter(DataTable2, PARTCODE = PARTCODE1)) > 1, /* <-- Check if current loop item has repeated items within the DataTable2 */
Remove(DataTable2, LookUp(DataTable2, PARTCODE = PARTCODE1))
) )

More details about the ForAll function in PowerApps, please check the following article:

ForAll function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
New Member

Re: Counting the number of times a button is pushed and clearing repeated rows.

Yes, I want to remove all repeated rows and return the number of times it was repeated into the "QTY" Column. Yes it is the primary column and it is unique. 

Highlighted
Community Support
Community Support

Re: Counting the number of times a button is pushed and clearing repeated rows.

Hi @Jagarrison1 ,

Have you taken a try with the above solution I provided?

 

If you want to remove repeated rows from your DataTable2, I think the solution I provided above could achieve your needs. Please take a try with the solution I provided above, then check if the issue is solved.

 

In addition, based on the needs that you mentioned, I suppose that you want to add 1 to the QTY column when you add same product into your DataTable2 rather than add a new row for the same Product, is it true?

If you just want to add 1 to the QTY column when you add same product into your DataTable2 rather than add a new row for the same Product, I think there is something issue with your formula.

I have made a test on my side, please take a try with the following workaround. Please modify your formula as below:

If(
!IsBlank(LookUp(DataTable2, PARTCODE = Product)), /* <-- Check if the DataTable2 collection has contained same Product record already */
Patch(DataTable2, LookUp(DataTable2, PARTCODE = Product), {QTY: QTY+1}),
Collect(DataTable2, {NO:'S-#', PARTCODE : Product, QTY : 1, DESCRIPTION : Description, MATERIAL : None})
);
Set(inCart, CountIf(DataTable2, PARTCODE = ThisItem.Product))

Please consider take a try with above solution, then check if the issue is solved. Then within your DataTable2, it would not contain repeated rows for same Product, and the Qty column would store correct value.

 

More details about the Patch function, please check the following article:

Patch function

 

Best regards,

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

View solution in original post

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,563)