Forum Discussion

kd_pandey's avatar
kd_pandey
Regular Visitor
2 years ago
Solved

IF and Statement in Excel Power Query

I am trying to create below scenario in excel power query, where I'm getting when trying to create Point. 2 & 3

 

table as below

 

TypeAmount_AAmount_BAmount_C
New8921  
Renew3703  
Renew427  
Renew7379  
Renew3148  
Renew787  
New2437  
New6799  
  15440
  79120
  96100
New2513  
New7962  
Renew4483  
Renew1296  
Renew4438  
Renew3202  
  07922
  01413
  04167
  05959
  06227
New843  
New6560  
New7359  
Renew5718  
  00
  00
  10971682
  5991133
New3569  
New3899  
New4583  
New7713  
New2874  
New2938  
  • in the example data you gave the Amount_A values were null.

    Changed the code so it works with = 0 too 🙂

    if [Amount_A] = null or [Amount_A] = 0  then
        if [Amount_C] = null or [Amount_C] = 0 then
            if [Amount_B] = 0 or [Amount_B] = null

                  then null
                  else "Expiring"
           else "Renewed"
    else [Type]

6 Replies

  • You will have to add another custome column in Powerqueryas following,
    = if [Type] <> null and [Type] <> "" then [Type]
    else if [Amount C] <> 0 or [Amount C] <> null then "Renewed"
    else if ([Amount B] = 0 or [Amount B] = null) and ([Amount C] = 0 or [Amount C] = null) then ""
    else "Expiring"

    Please accept it as solution if works.

    • kd_pandey's avatar
      kd_pandey
      Regular Visitor

      this is the result of both solutions .. expring is missing in both 

       

      • BenjaminSNN's avatar
        BenjaminSNN
        Frequent Visitor

        in the example data you gave the Amount_A values were null.

        Changed the code so it works with = 0 too 🙂

        if [Amount_A] = null or [Amount_A] = 0  then
            if [Amount_C] = null or [Amount_C] = 0 then
                if [Amount_B] = 0 or [Amount_B] = null

                      then null
                      else "Expiring"
               else "Renewed"
        else [Type]

  • BenjaminSNN's avatar
    BenjaminSNN
    Frequent Visitor

    I think this should do the trick. Add a new custom column with the following code:

    if [Amount_A] = null then
        if [Amount_C] = null or [Amount_C] = 0 then
            if [Amount_B] = 0 or [Amount_B] = null

                  then null
                  else "Expiring"
           else "Renewed"
    else [Type]


    Tip: Basing logic on the False premise (C <> 0) often makes things more complicated. Try to build your logical from the true (C = 0) premise