Skip to main content
JimBerkes
Participant
Jun 3, 2026 6:00 PM UTC
Question

Need help translating nested if else to coldfusion report iif

coldfusion report 

Calculated Field SumForward

SumForward(Sum:iif((query.SumOfTrainingHours + calc.SumForward  GTE 40),iif(calc.SumForward + query.Carryover LTE 40,query.Carryover,40-calc.SumForward), query.SumOfTrainingHours))

This statement above is calculating the wrong result

 

This if else below will return the correct result but I don’t understand how to format this for the ColdFusion report .

Can someone help?

<cfif query.SumOfTrainingHours + query.Carryover GT 40 and query.SumOfTrainingHours + query.Carryover LTE 80 >
    <cfset result = query.SumForward + query.Carryover - 40>
<cfelseif query.SumOfTrainingHours + query.Carryover GT 80 >
    <cfset result =40>
<cfelse>
    <cfif query.SumOfTrainingHours eq 40>
       <cfset result = 40 >
     <cfelseif query.SumOfTrainingHours + query.Carryover eq 40>
       <cfset result = 0>
     <cfelse>
         <cfset result = query.SumOfTrainingHours
      </cfif>
</cfif>

 

Thanks

JimBerkes

    6 replies

    BKBK
    Community Expert
    Community Expert
    Jun 5, 2026 5:07 PM UTC

    Hi ​@JimBerkes ,

    in the code in my last post, you may replace 

    (query.SumOfTrainingHours + query.Carryover) GT 40 AND (query.SumOfTrainingHours + query.Carryover) LTE 80

    with 

    (query.SumOfTrainingHours + query.Carryover - 40) * (81 - query.SumOfTrainingHours - query.Carryover) GT 0

    for integers, or with

    (query.SumOfTrainingHours + query.Carryover - 40) * (80.005 - query.SumOfTrainingHours - query.Carryover) GT 0

    for decimals 

    Translate
    BKBK
    Community Expert
    Community Expert
    Jun 5, 2026 10:44 AM UTC

    Hi ​@JimBerkes ,
    The CFML code you’ve provided won’t work, let alone provide the correct result. That is because it contains an error (missing >)

    <cfset result = query.SumOfTrainingHours

    Let’s assume that that is a typo.
    You should experiment with Claude AI. When I ask it to convert your CFML to Report Builder code, the result is


    iif(
    (query.SumOfTrainingHours + query.Carryover) GT 40 AND
    (query.SumOfTrainingHours + query.Carryover) LTE 80,
    query.SumForward + query.Carryover - 40,
    iif(
    (query.SumOfTrainingHours + query.Carryover) GT 80,
    40,
    iif(
    query.SumOfTrainingHours EQ 40,
    40,
    iif(
    (query.SumOfTrainingHours + query.Carryover) EQ 40,
    0,
    query.SumOfTrainingHours
    )
    )
    )
    )


     

    Translate
    Charlie Arehart
    Community Expert
    Community Expert
    Jun 5, 2026 4:04 PM UTC

    vide infra

    Translate
    /Charlie (troubleshooter, carehart. org)
    BKBK
    Community Expert
    Community Expert
    Jun 6, 2026 12:34 PM UTC

    lapsus oculorum 😀

    Translate
    JimBerkes
    JimBerkesAuthor
    Participant
    Jun 4, 2026 2:50 AM UTC

    Hi Charlie,

    Thanks for your help!  The existing iif code has always provided a result, but the result has always been incorrect.    

    Now it’s my job to fix it but I don’t recall ever working on any ColdFusion reports :-)   Your code will help me understand the syntax better

    Thanks

    Jim 

    Translate
    Charlie Arehart
    Community Expert
    Community Expert
    Jun 3, 2026 8:56 PM UTC

    Jim, before offering a conversion, do you mean that old code had worked for years and suddenly now gives wrong values? That would seem to point to a change in the data. Or do you mean you're building or editing a report and you crafted that first variant and found it not working well?

     

    In either case, it helps to mention how iif in report builder (like in cfml) takes 3 args, the first being the condition to evaluate, and if it results in true then the second arg's results are evaluated (and returned as the result in rb) , else the 3rd's are. (In your cfml, you're setting a result instead, but I assume that was just for testing the logic.)

     

    Note that the (very old, cf7 era) rb parser does not support if/elseif /else logic, only that simple iif. (It also doesn't support cfscript, which came out initially with cf8, so we can't use what it offers.)  So doing if/elseif /else demands we used nested iif calls--and we need to be very careful about it. :-) 

     

    Here's a shot at converting it for use in rb. Note I've used new lines and indentation to help make the logic better stand out better. This is not tested, so apologies for mistakes:

    Iif(
    (query.SumOfTrainingHours + query.Carryover GT 40) AND (query.SumOfTrainingHours + query.Carryover LTE 80),
    (query.SumForward + query.Carryover - 40),
    Iif(
    query.SumOfTrainingHours + query.Carryover GT 80,
    40,
    Iif(
    query.SumOfTrainingHours EQ 40,
    40,
    Iif(
    query.SumOfTrainingHours + query.Carryover EQ 40,
    0,
    query.SumOfTrainingHours
    )
    )
    )
    )

    Even if it fails, perhaps the observations I've offered might help you sort things out. 

    Translate
    /Charlie (troubleshooter, carehart. org)