Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Table.SelectColumns error

I am using Power Query Editor's Custom Column window to attempt the following;

I have Table1 and Table2. I am trying to add a custom column to Table1, that contains Table2 as the value, but only if a value is not null in Table1.

 

 

This code works, it places the table in the new custom column. But it does not include my condition.

 

= Table.SelectColumns(#"Table2", {"Column1", "Column2"})

 

Result = Table2 as a table, with the values within

 

 

This is with the condition added, the result of this code is a null table as the value if [ValueFromThisTable] is not null. Why did it change to a null table when the above code puts in the right table?

 

= if [ValueFromThisTable] = null then null else 
Table.SelectColumns(#"Table2", {"Column1", "Column2"})

 

Result = if the value is null, null. Otherwise, Table2Name as table, with null within

 

 

If someone could please explain to me where I have gone wrong, and why this is happening, I would appreceate it. Thanks

  • Hi Anonymous,

     

    Assuming that your example is in th econtext of Table.AddColumn() the behaviour is quite weird.

    Do you want to try to split the formula to something like:

    t2 = Table.SelectColumns(#"Table2", {"Column1", "Column2"}),
    t1 = Table.AddColumn(..., ..., each if [ValueFromThisTable] = null then null else t2)

    and see if this works Ok?

     

    Thanks,

    John

2 Replies

  • jbwtp's avatar
    jbwtp
    Memorable Member

    Hi Anonymous,

     

    Assuming that your example is in th econtext of Table.AddColumn() the behaviour is quite weird.

    Do you want to try to split the formula to something like:

    t2 = Table.SelectColumns(#"Table2", {"Column1", "Column2"}),
    t1 = Table.AddColumn(..., ..., each if [ValueFromThisTable] = null then null else t2)

    and see if this works Ok?

     

    Thanks,

    John

    • Anonymous's avatar
      Anonymous
      Not applicable

      Well it turns out I just needed to refresh Power Query Editor, the values have always been there they just were showing null. Found this out after trying your version and multiple variations of each step, one by one until it broke. It always broke once I clicked to view one of the tables to validate the data however an expansion of the table reveals its all there. 

       

      Very odd