Forum Discussion

ANB_13's avatar
ANB_13
Helper I
3 years ago
Solved

Help Excel formula to Dax

Hello everyone, 

 

Please, someone can help me to covert this excel formula to DAX ?

 

"=IF(OR([@[NATURE CODE 1]]="A",[ @[NATURE CODE 1]]="W");([@[%VOL. CN1]]/100)*[@[GROSS MASS (kg)]];0)+SI(OU([@[NATURE CODE 2]]="A";[ @[NATURE CODE 2]]="W");([@[%Vol. CN2]]/100)*[@[GROSS MASS (kg)]];0)"

 

Thank you very much 

Regards

  • Hi, ANB_13 

     

    try this one:

     

    = IF(
    OR(
    TableName[NATURE CODE 1] = "A",
    TableName[NATURE CODE 1] = "W"
    ),
    (TableName[%VOL. CN1] / 100) * TableName[GROSS MASS (kg)],
    0
    ) + IF(
    OR(
    TableName[NATURE CODE 2] = "A",
    TableName[NATURE CODE 2] = "W"
    ),
    (TableName[%Vol. CN2] / 100) * TableName[GROSS MASS (kg)],
    0
    )

     

    replace the table with your appropriate table name. 

     

     

3 Replies

  • rubayatyasmin's avatar
    rubayatyasmin
    Community Champion

    Hi, ANB_13 

     

    try this one:

     

    = IF(
    OR(
    TableName[NATURE CODE 1] = "A",
    TableName[NATURE CODE 1] = "W"
    ),
    (TableName[%VOL. CN1] / 100) * TableName[GROSS MASS (kg)],
    0
    ) + IF(
    OR(
    TableName[NATURE CODE 2] = "A",
    TableName[NATURE CODE 2] = "W"
    ),
    (TableName[%Vol. CN2] / 100) * TableName[GROSS MASS (kg)],
    0
    )

     

    replace the table with your appropriate table name. 

     

     

  • Hello, 

    Thank you very much, 

     

    I want it also in M language. Can ou help me please ?

     

    Thank you very much

    • rubayatyasmin's avatar
      rubayatyasmin
      Community Champion

      sure, 

       

      let
      Source = TableName,
      DAXFormula = (Table as table) =>
      let
      Result1 = if List.Contains({"A", "W"}, Table[NATURE CODE 1]) then (Table[%VOL. CN1] / 100) * Table[GROSS MASS (kg)] else 0,
      Result2 = if List.Contains({"A", "W"}, Table[NATURE CODE 2]) then (Table[%Vol. CN2] / 100) * Table[GROSS MASS (kg)] else 0,
      FinalResult = Result1 + Result2
      in
      FinalResult,
      CustomColumn = Table.AddColumn(Source, "Converted", each DAXFormula(_))
      in
      CustomColumn

       

       

      if my assistance helped you in any way. hit 👍