Forum Discussion
If statement with double condition
- 5 years ago
Hi CleliaComes
This query does what you are asking. Copy paste into PBI Advanced Query editor. It contain a snapshot of your data as shown in your image.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVGeeSWpRXmpCpllSToKBYlF2alFqXk6CkmJednZ+cUlOgqpJcl6QHUGSrE60UreOYl5JQjNMK6hobmesQVChYK+gk9qWWpRYl5yZmoRmnoMSV0zCz1TQ7BurLrQVBsbGFroWRiSa5uJqZ6ZpVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Type rekening" = _t, Categorie = _t, #"Type rekening + categorie" = _t, #"Cash in - cash out" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type rekening", type text}, {"Categorie", type text}, {"Type rekening + categorie", type text}, {"Cash in - cash out", type number}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Type rekening] = "Klant / Leverancier" and [#"Cash in - cash out"] > 0 then "Klant" else if [Type rekening] = "Klant / Leverancier" and [#"Cash in - cash out"] < 0 then "Leverancier" else null) in #"Added Custom"If you want to just add the single line of code to your file to create the Custom Column, this is the line to enter into the Create Custom Column dialog box
if [Type rekening] = "Klant / Leverancier" and [#"Cash in - cash out"] > 0 then "Klant" else if [Type rekening] = "Klant / Leverancier" and [#"Cash in - cash out"] < 0 then "Leverancier" else nullNOTE Your data shows the text string "Klant / Leverancier" but the code you tried to enter for the if statement showed "Klant/Leverancier" - notice the lack of spaces between the words. Make sure you are checking for the correct text. My query checks for the text as shown in your data.
Phil
If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.
Hi CleliaComes
Your formula is correct, I believe there might be some trailing or leading spaces in your text column that might have caused issue.
Please use the below formula as your custom formula:
if[Type rekening] = "Klant / Leverancier" and [#"Cash in - Cash Out"] > 0 then "Klant" else if [Type rekening] = "Klant / Leverancier" and [#"Cash in - Cash Out"] < 0 then "Leverancier" else null
Thanks,
Ankit