cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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

Hi @Anonymous ,

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
v-xida-msft
Community Support
Community Support

Hi @Anonymous ,

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.
Anonymous
Not applicable

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. 

Hi @Anonymous ,

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
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,504)