Search code examples
powerbipowerbi-desktopm

Power BI - Power Query Case Statement


Is there a way to do a case statement inside of Power BI, specifically written in M?

I have columns that look like this:

col_a     col_b      col_c
steve     smith      steve smith
null      james      james
sally     null       sally

Col_c is a concatenation of columns a and b. If column a or b are null, then I want column c to be null, no matter what.

Any suggestions?


Solution

  • M has a fairly standard if, then, else syntax.

    if [col_a] = null or [col_b] = null
    then null
    else [col_a] & " " & [col_b]