Forum Discussion
New column based in multiple If statements in Power Query
- 2 years ago
The very last else if is causing the issue - i think the code there should be
if [#"N - Início"] <> null then [#"N - Início"]If you're interested, there's the coalesce function in PowerQuery, which might make it a bit easier to read and debug your code:
https://gorilla.bi/power-query/coalesce/
So in your case, you can rewrite the if statement as:
each [#"M - Início"] ?? [#"T - Início"] ?? [#"N - Início"] ?? null
The very last else if is causing the issue - i think the code there should be
if [#"N - Início"] <> null then [#"N - Início"]
If you're interested, there's the coalesce function in PowerQuery, which might make it a bit easier to read and debug your code:
https://gorilla.bi/power-query/coalesce/
So in your case, you can rewrite the if statement as:
each [#"M - Início"] ?? [#"T - Início"] ?? [#"N - Início"] ?? nullHi, vicky_!
I changed the if functions so it reads like that:
#"Personalização Adicionada" = Table.AddColumn(#"Colunas Renomeadas", "Data", each if [#"M - Início"] <> null then [#"M - Início"] else if [#"M - Início"] = null then [#"T - Início"] else if [#"T - Início"] = null then [#"N - Início"] else if [#"N - Início"] <> null then [#"N - Início"] else [#"M - Início"])No success, same results. No surprise if I still did something wrong.
In the other hand, the coalesce function worked perfectly, besides looking beautifully neat! Thank you very much for all the help!
- vicky_2 years agoSuper User
Oh haha whoops. I'm glad that at least the second part worked.