Forum Discussion

ragygad's avatar
ragygad
Frequent Visitor
3 years ago

Compare values with if statement

I have a table with multiple fields and my main concern is 2 fields, one has ID and the other has grade (numerical field). 

I am trying to check first id ID to ID match in the same field and if they match, check grade field and see if its value higher than its previous value bases on the date order (if its higher for a higher date then 1 , if its lower for a higher date then its 0) then put a 1 else put a 0
 

 

10 Replies

  • AbhinavJoshi's avatar
    AbhinavJoshi
    Responsive Resident

    Hello, you could use a if else in Power Query M, here's a sample code
     = Table.AddColumn(#"Previous Step", "OutputColumnName", each if ( ( [#"ID1"] = [#"ID2"] ) and ( [#"GradeValue"] > YourValue ) ) then 1 else 0)

    • AbhinavJoshi's avatar
      AbhinavJoshi
      Responsive Resident

      To achieve it in DAX, try this code NewColumn =
      IF(
      Table1[ID] = EARLIER(Table1[ID]),
      IF(
      Table1[Grade] > EARLIER(Table1[Grade]),
      1,
      0
      ),
      BLANK()
      )

      • ragygad's avatar
        ragygad
        Frequent Visitor

        I tried that but you cant have earlier in a function with if statement , it only works with filter function