cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jagarrison1
Level: Power Up

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
Community Support Team
Community Support Team

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
Community Support Team
Community Support Team

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.
Jagarrison1
Level: Power Up

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. 

Community Support Team
Community Support Team

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,679)