4 Replies Latest reply: Oct 26, 2015 12:33 PM by Ruben Marin RSS

    If statement help

    mark pratt

      I'm trying to create a new measure using the following if statement, however not working help please.

       

      if {[Ext Transaction Code]="326"} then

      Sum([LAS Principal])-Sum([Charged Off Amount]);

      else

      Sum([LAS Principal]); 
      end if   

        • Re: If statement help
          Sunny Talwar

          Try this may be:

           

          If([Ext Transaction Code] = 326, Sum([LAS Principal]) - Sum([Charged Off Amount]), Sum([LAS Principal]))

          • Re: If statement help
            Ruben Marin

            Hi Mark, there are two kind of 'if', you're using the syntasx that controls wich section of the script runs, meanwhile the logic of your 'if' leads to a condition to check the loaded values, in this case the syntax is inside the load sentence:

             

            LOAD YourFields,

                 If([Ext Transaction Code]=326, Sum([LAS Principal])-Sum([Charged Off Amount]), Sum([LAS Principal])) as LAS

                 //If(Condition, thenSentences, elseSentences) as NameOfResultingField

             

            Btw, if you're using a Sum() inside the load you'll need to use the 'group by' clause.

              • Re: If statement help
                mark pratt

                Can you explain what you mean and what is the "group cause", please? Thanks!

                  • Re: If statement help
                    Ruben Marin

                    If you have aggregation functions like Sum(), Avg()... some function that makes a calculation over different records you'll neded to set aggroup by by all other fields that aren't in an aggregation function:

                    LOAD YourFields,

                         If([Ext Transaction Code]=326, Sum([LAS Principal])-Sum([Charged Off Amount]), Sum([LAS Principal])) as LAS

                    Group by Yourfields, [Ext Transaction Code];

                     

                    But maybe you only need to remove the sum():

                    LOAD YourFields,

                         If([Ext Transaction Code]=326, [LAS Principal]-[Charged Off Amount],[LAS Principal]) as LAS

                    ...