Forum Discussion

Irwin's avatar
Irwin
Icon for Helper IV rankHelper IV
4 years ago
Solved

Selective combine 3 columns in Power Query ?

Hi guys,

 

I have 3 columns that I would like to combine into one. I would like to do this in power query as I have alot of rows.

The columns contain values from null, 0, 1,2.... to ~25 (see example)

 

I would like power query to check column 1 and if there is a number, use this in the new column. If null or 0, then check column 2 and use this number. If this is also null or 0, then use result from column 3. 

 

 

How can I do this in the power query?

Thank you for all answers 🙂

  • You can add a custom column with an expression like this to get your result.

     

    = List.First(List.Select({[Column1], [Column2], [Column3]}, each _ <> null and _ <> 0))

     

     

    Pat

     

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    You can add a custom column with an expression like this to get your result.

     

    = List.First(List.Select({[Column1], [Column2], [Column3]}, each _ <> null and _ <> 0))

     

     

    Pat

     

    • Irwin's avatar
      Irwin
      Icon for Helper IV rankHelper IV

      This works. Thanks!

       

      Now that I have begun to grasp how DAX works I have realised that much of my work would be better done in the power query, so I need to learn M aswell... 

      I dont understand why your code does, but it will suffice for now, and then down the road I will understand why. 🙂

       

      Thank you again.