This is my code
Set(remaining_amount_needed,total_amount_required);
ClearCollect(SelectedPacks, []); // This collection will store the selected packs.
ClearCollect(
SelectedPacks,
ForAll(
PurchaseOptionsSorted,
If(
remaining_amount_needed > 0,
{
Drug: Drug,
PackSize: AMT,
UnitPrice: Unit_price,
Order: RoundDown(remaining_amount_needed / AMT, 0),
Quantity: RoundDown(remaining_amount_needed / AMT, 0) * AMT,
left_quantity: remaining_amount_needed-RoundDown(remaining_amount_needed / AMT, 0) * AMT
},
Blank()
);
// Update remaining_amount_needed for the next iteration
//UpdateContext({remaining_amount_needed: remaining_amount_needed - RoundDown(remaining_amount_needed / AMT, 0) * AMT})
//remaining_amount_needed=remaining_amount_needed +1
)
)
For each loop, I want to update the varaiable, remaining_amount_needed= its starting value - quantity
and the loop should finish when it becomes 0
ChatGPT told me to add this in the end of the loop:
Set(remaining_amount_needed, remaining_amount_needed - RoundDown(remaining_amount_needed / AMT, 0) * AMT
but it gave me error:
This function cannot be invoked within ForAll.