I’m trying to perform a basic IF/ELSE calculation on a list of items and then perform a SUM aggregation on the list to calculate a total repair cost to be displayed as a “total Repair Costs” in the Metric Card.
In this case, if the boolean field {Include Repair} = True , then Unit Repair Cost * Qty , Else “0”
I created a derived property {modelled_line_repair_cost} to try to simplify the calculation but struggling to be able to apply the field to an IF/ELSE calculation with it being a derived property.
My current approach has been:
A numeric variable transformation - Repair_x_Qty
A Numeric Variable transformation - IF_Repair (which is the IF/ELSE) referencing the Repair_x_Qty (see below configuation)
Column math doesn’t directly support if/else but in your case where you want to make an existing numerical value 0 based on some boolean you could add a column to this object type that stores a 1 or 0 and multiply by that.
You could also achieve this with a function backed value.
When I had a similar issue, I resolved it by adding a column, “Row Total” equal to unit cost * qty. Then, the custom part was replacing the edit action with a TypeScript action where the inputs are unit cost (optional) and qty (optional), and the pseudo code was: set unit cost to unit cost, set qty to qty, and set row total to unit cost * qty. The rest doesn’t require code. If we assume the table’s input object set is “Table Objects”. Then copy the variable to create “Table’s Included Objects” and add a filter to the copy’s configuration that filters to objects where “Include Repair?” is True. Lastly, use this new, “Table’s Included Objects” as the input to a numeric aggregation variable that aggregates the sum of the “total row” property.
Alternatively, you could use the Include True/False in the row total pseudocode such that if Include is True then row total = unit cost * qty else row total = 0. Then the filtered variable could be skipped, and lastly, the numeric aggregation variable would similarly sum on row total.