Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Conditional If or Switch using var DAX

Hi All,   Please help me with the below condition ,    Column - S.NO,ID,OPS,PP are my Table. Condition - Mentioned the required Condition Result need to come as - Result which i need   ...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous - I don't think this is possible using DAX, but it is possible using Power Query.  Please try the following:

     

     

    let
      Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY5BCsAgDAT/krPCRpPYvkX8/zcapYQW9BKWYWdJ78SUiEv1C+aMAmSYB2CHRupUwjg1ajTadfsVtcUl+OtPqB5U7LelawtbNh0L51hp3y9pjAc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [S.No = _t, ID = _t, OPS = _t, PP = _t]),
      #"Change Data Types" = Table.TransformColumnTypes(Source,{{"S.No", Int64.Type}, {"ID", Int64.Type}}),
      Buffer = Table.Buffer ( #"Change Data Types" ),
      #"Add Conditional Result" = Table.AddColumn(Buffer, "Condition Result", each 
        let 
          i=[S.No], x=[ID], OPS=[OPS], PP=[PP], t=Buffer,
          text1 = Text.Length(OPS), text2 = Text.Length(PP),
          test_1 = 
            if OPS = PP and not ( text1 = 0 or text2 = 0 ) 
            then "Match" 
            else null,
          test_2 = 
            if ( text1 = 0 or text2 = 0 ) 
            then 
              if
                List.ContainsAny( 
                  List.Combine( 
                    { 
                      Table.SelectRows( t , each [ID] = x and ( [S.No] = i - 1 or [S.No] = i + 1) )[OPS],
                      Table.SelectRows( t , each [ID] = x and ( [S.No] = i - 1 or [S.No] = i + 1) )[PP]
                    } 
                  ) ,
                  { OPS , PP } 
                ) 
              then "Extra Population" 
              else null
            else null,
          test_3 = 
            if OPS <> PP 
            then "Non Match" 
            else null, 
          Result = List.First( List.RemoveNulls( { test_1, test_2, test_3, "Missed by ML" } ) )
        in 
          Result
      )
    in
      #"Add Conditional Result"