Background:
- Submit data is the collection where I store my data.
- Success Count is where I want to count each record that had an empty error table. However, my code currently records ALL the items in SubmitData for each loop instead of just the count that went through without an error. How can I filter it to only the item that is being evaluated in the ForAll loop?
ForAll(
SubmitData,
If(
IsEmpty(
Errors('H2A Housing Inspection',
(Patch('H2A Housing Inspection'
,Defaults('H2A Housing Inspection'),
{Title: "",
DDate: Now()}
)
)
)
),
Collect(SuccessCount,SubmitData.Counter)
)
);
Notify(
CountA(SuccessCount.Counter) & " out of " &
CountA(SubmitData.region5),NotificationType.Success)
Solved! Go to Solution.
My approach to the solution is different from yours since it increments a Value stored in a 1 row collection each time there is a success and it does not rely on filters. Please study the changes I made carefully and let me know if you have any questions.
// reset success counter to 0
ClearCollect(colSuccessCount,{Value: 0})
ForAll(
SubmitData,
If(
IsEmpty(
Errors('H2A Housing Inspection',
(
Patch(
'H2A Housing Inspection',
Defaults('H2A Housing Inspection'),
{Title: "", DDate: Now()}
)
)
)
),
// increment success counter if there are no error
Patch(colSuccessCount,{Value: First(colSuccessCount).Value + 1})
)
);
Notify(
// display the counter result
First(colSuccessCount).Value & " out of " &
CountA(SubmitData.region5),NotificationType.Success
)
---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
Hi @dyee4614 ,
Please modify your codes as below:
ForAll(
SubmitData,
If(
IsEmpty(
Errors('H2A Housing Inspection',
(Patch('H2A Housing Inspection'
,Defaults('H2A Housing Inspection'),
{Title: "",
DDate: Now()}
)
)
)
),
Collect(SuccessCount,Counter)
)
);
Notify(
CountA(SuccessCount.Value) & " out of " &
CountA(SubmitData.region5),NotificationType.Success)
I modify 'SubmitData.Counter' to Counter, because 'SubmitData.Counter' returns a single-line table, so every time it loops, the whole single-line table is stored into the SuccessCount collection.
If you change to use Counter, each time it loops, it will only return the counter value of the currently traversed record without error, and collect to SuccessCount collection.
Meanwhile, you need to modify 'SuccessCount.Counter' to 'SuccessCount.Value', because the column name is changed.
Sik
My approach to the solution is different from yours since it increments a Value stored in a 1 row collection each time there is a success and it does not rely on filters. Please study the changes I made carefully and let me know if you have any questions.
// reset success counter to 0
ClearCollect(colSuccessCount,{Value: 0})
ForAll(
SubmitData,
If(
IsEmpty(
Errors('H2A Housing Inspection',
(
Patch(
'H2A Housing Inspection',
Defaults('H2A Housing Inspection'),
{Title: "", DDate: Now()}
)
)
)
),
// increment success counter if there are no error
Patch(colSuccessCount,{Value: First(colSuccessCount).Value + 1})
)
);
Notify(
// display the counter result
First(colSuccessCount).Value & " out of " &
CountA(SubmitData.region5),NotificationType.Success
)
---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
Hi @dyee4614 ,
Please modify your codes as below:
ForAll(
SubmitData,
If(
IsEmpty(
Errors('H2A Housing Inspection',
(Patch('H2A Housing Inspection'
,Defaults('H2A Housing Inspection'),
{Title: "",
DDate: Now()}
)
)
)
),
Collect(SuccessCount,Counter)
)
);
Notify(
CountA(SuccessCount.Value) & " out of " &
CountA(SubmitData.region5),NotificationType.Success)
I modify 'SubmitData.Counter' to Counter, because 'SubmitData.Counter' returns a single-line table, so every time it loops, the whole single-line table is stored into the SuccessCount collection.
If you change to use Counter, each time it loops, it will only return the counter value of the currently traversed record without error, and collect to SuccessCount collection.
Meanwhile, you need to modify 'SuccessCount.Counter' to 'SuccessCount.Value', because the column name is changed.
Sik
It worked! Thanks for your help.
User | Count |
---|---|
122 | |
87 | |
86 | |
75 | |
67 |
User | Count |
---|---|
214 | |
180 | |
137 | |
96 | |
83 |