Power BI: extract columns from a table to another one

When I have multiple tables and I want to insert a specific column from a table to an existing one or to a new one, I will use one of those 2 functions:

  • RELATED, for instance RELATED('table'[argument]). To be used to add a new column to an existing table. For this formula to work, tables should have a relationship
    power bi
  • SELECTCOLUMNS, for instance SELECTCOLUMNS('table',[argument]). To be used to create a new table (relationship no needed) with an existing column
    power bi

NOTE: change “table” and “argument” by yours.

This formula will put the same name as “argument” but if I want to put a different name, I will use this one:

SELECTCOLUMNS('table',"different name",[argument])

power bi

NOTE: change “different name” by yours.

If I want to add multiple columns, just add another [argument] like that:

  • SELECTCOLUMNS('table',[argument1],[argument2])
    power bi
  • SELECTCOLUMNS('table',"different name1",[argument1],"different name2",[argument2])
    power bi

NOTE: instead to use [argument1], I can use a specific value:

SELECTCOLUMNS('table',"different name1",”specific value”,"different name2",[argument2])

power bi

To get only unique values, I will add the DISTINCT function:

DISTINCT(SELECTCOLUMNS('table',"different name1",[argument1]))

power bi

To filter a specific criteria, I will add the FILTER function, for instance, if I have a huge data and I want to extract only data for a specific group:

  • To get data for a particular criteria:
    FILTER(DISTINCT(SELECTCOLUMNS('table',"different name1",[argument1],"different name2",[argument2])),[different name2]="value")
    power bi
  • To exclude blank values:
    FILTER(DISTINCT(SELECTCOLUMNS('table',"different name1",[argument1],"different name2",[argument2])),NOT(ISBLANK([different name2])))
    power bi

NOTE: “different name2” is the new column name where there is the criteria/blank cell(s)

To filter from another table, I will use the CALCULATETABLE function:

SELECTCOLUMNS(CALCULATETABLE('table1',FILTER('table2','table2'[argument]="value")),"different name1",[argument1],"different name2",[argument2])

power bi

NOTE: argument1 and argument2 are from table1

Now if I add the UNION function, I will be able to merge columns from 2 different tables into 1 same column:

UNION(SELECTCOLUMNS('table1',[argument]),SELECTCOLUMNS('table2',[argument]))

power bi

And to not repeat again, if I want to add more columns or put a particular name, just follow the same formula as above.

Interesting Topics