Expand my Community achievements bar.

SOLVED

Formula that checks drop down list and then sums

Avatar

Level 3

I have a table with a drop down list with two values: '$' and 'Hr' (cell called 'PType').  There is a cell called 'Proposed' that contains numerical data. The table is dynamic and can have more cells inserted via a button within the row.  I have a totals section that I want to total the SUM of 'Proposed' if the value in 'PType' is '$'.  I can't figure out what type of statement will allow me to write this.

For now, my solution has been a hidden column whose cell simply states:

if (PType == "$") then
    Proposed
endif

Then, in the totals section, I sum this hidden column since a value outside of '$' returns a '0' and won't affect my SUM.

I am looking for a formula I can write that does this within the totals cell instead of having two cells.

Thanks,

Mallard27

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Here's my take on it.

// form1.page1.subform1.table.footer.SUM::calculate - (JavaScript, client)

var total = 0;

for (i=0; i < form1.page1.subform1.table._row.count; i++) {
    if (table.resolveNode("row[" + i + "].Proposed").rawValue) {
        if (table.resolveNode("row[" + i + "].PType").rawValue == "$") {
            total = total + parseFloat(table.resolveNode("row[" + i + "].Proposed").rawValue);
        }
    }
}

this.rawValue = parseFloat(total);

Steve

View solution in original post

3 Replies

Avatar

Correct answer by
Former Community Member

Here's my take on it.

// form1.page1.subform1.table.footer.SUM::calculate - (JavaScript, client)

var total = 0;

for (i=0; i < form1.page1.subform1.table._row.count; i++) {
    if (table.resolveNode("row[" + i + "].Proposed").rawValue) {
        if (table.resolveNode("row[" + i + "].PType").rawValue == "$") {
            total = total + parseFloat(table.resolveNode("row[" + i + "].Proposed").rawValue);
        }
    }
}

this.rawValue = parseFloat(total);

Steve

Avatar

Level 3

Thanks Steve!!!!

That did the trick.

Avatar

Level 2

Is it possible to have a pre-made table already?  I tried the code you provided however in my case, I do not have the "add row" button.  I already have a table with 20 rows with an amount column and a dropdown column.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----