Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

SCHOOL ASSIGNMENT: Multiple conditions in an conditional column

Dear PowerBI gurus,

 

For our school assignment we've received a data set with clear requirements, we need to clean this and import this to a MS Database later. At the moment we've covered most parts. There is still one challenge where we are stuck:

 

We have one column named "ALG_Omschrijving". All rows which contain "serie" can hold a maximum of 10 products in stock. The products in stock are listed in the column "VOORRAAD_Aantal". We've used a conditional column where we configure:

If ALG_Omschrijving contains "serie" then 10

Else VOORRAAD_Aantal

 

We would like to expand this with one more condition:

If ALG_Omschrijving contains "serie" AND if VOORRAAD_Aantal is greater then 10 then 10

ELSE VOORRAAD_Aantal

 

We've tried to edit the query manual, this was our closest shot but it also didn't work. Anyone any suggestions or a suggestion/alternative to solve this challenge? 

 

*** WE ARE EXTREME NOOBS / ENTIRELY NEW TO THIS STUFF

 

Thank you in advance.

 

Regards,

Shadi

  • Anonymous's avatar
    Anonymous
    3 years ago

    We've managed to solve this challenge with the following formula:

     

    = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving], "serie") and [VOORRAAD_Aantal] > 10 then 10 else [VOORRAAD_Aantal])

4 Replies

  • Hi -

     

    Don't think you need to nest the if statements, you can just use an "and" in the if-clause eg:

     

    = Table.AddColumn(Source, "Custom", each if [Col1] = "Val1" and [Col2] = "10" then "Some Val" else "Some Other Val")

     

    Cheers,

     

    Peter

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Peter_Beck ,

      Thank you for your help, I've tried this formula but it returns a column full of errors. I've tried it in several ways none of them did work:

       

      = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving] = "serie" and ([VOORRAAD_Aantal]) > "10") then 10 else [VOORRAAD_Aantal])

       

      = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving] = "serie" and [VOORRAAD_Aantal] > "10") then 10 else [VOORRAAD_Aantal])

       

      = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving] = "serie" and ([VOORRAAD_Aantal]) > "10" then 10 else [VOORRAAD_Aantal])

       

      = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving] = "serie" and ([VOORRAAD_Aantal]) > "10" then 10 else ([VOORRAAD_Aantal]))

       

      = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving] = "serie" and [VOORRAAD_Aantal] > "10" then 10 else [VOORRAAD_Aantal])

       

      Thank you again anyways.

       

      Rg,

      Shadi

  • Anonymous's avatar
    Anonymous
    Not applicable

    We've also tried this formula, unfortunately it also didn't work:

     

    =Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", each if text.Contains(ALG_Omschrijving,"serie") and VOORRAAD_Aantal > 10 then 10 else VOORRAAD_Aantal)

  • Anonymous's avatar
    Anonymous
    Not applicable

    We've managed to solve this challenge with the following formula:

     

    = Table.AddColumn(#"Renamed ALG_VerkoopPrijsExcl new", "Custom", each if Text.Contains([ALG_Omschrijving], "serie") and [VOORRAAD_Aantal] > 10 then 10 else [VOORRAAD_Aantal])