Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
gadao
Frequent Visitor

Compare Column Names from Multiple Sources

Hi there,

 

I was wondering if someone could give me some ideas in creating a matching col names table.

 

The ideia is simple, but i can't figure out.

 

This table would have n columns, each column representing a table in your PQ.

The rows should show the column names for each 'column table', but it should bring side by side when the column name is the same across tables.

 

Table 1Table 2Table 3Table 4
AAAA
B B 
C  C
 DD 
E   
F   
  GG
HHH 

 

So far I tested some ideas over these functions:

 

Table.Pivot

Table.UnpivotOtherColumns

Table.FromList

Table.ColumnNames

 

Thanks for helping

6 REPLIES 6
dufoq3
Super User
Super User

Hi @gadao, another solution:

You have to define your tables here:

dufoq3_2-1758728119461.png

 

Output:

dufoq3_1-1758728093176.png

 

You can delete steps Table1 - Table4 (they are just as sample tables).

let
    Table1 = #table(Text.ToList("ABCEFH"), {}),
    Table2 = #table(Text.ToList("AHD"), {}),
    Table3 = #table(Text.ToList("HGABD"), {}),
    Table4 = #table(Text.ToList("GAC"), {}),
    DefineTablesHere = [ //I do not know your table names, but you have to specify all of them here.
    Table1 = Table1,
    Table2 = Table2,
    Table3 = Table3,
    Table4 = Table4
  ],
    TablesColNames = List.Transform(Record.ToList(DefineTablesHere), Table.ColumnNames),
    AllColNames = List.Buffer(List.Sort(List.Distinct(List.Combine(TablesColNames)))),
    TableMap = Table.FromColumns(List.Transform(TablesColNames, each List.Transform(AllColNames, (x)=> if List.Contains(_, x) then x else null)), Record.FieldNames(DefineTablesHere))
in
    TableMap

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

AlexisOlson
Super User
Super User

You can write a custom function that takes a list of table names and a column to compare and outputs this result.

 

Custom function CompareTableColumns:

 

(table_names as list, column as text) as table =>
let
    Tables = Record.FieldValues(Record.SelectFields(#shared, table_names)),
    TableCols = List.Transform(Tables, each Table.Column(_, column)),
    Union = List.Sort(List.Distinct(List.Combine(TableCols))),
    MatchItems = List.Transform(Union, (u) => List.Zip(List.Transform(TableCols, each List.Select(_, each _ = u))){0}),
    ToTable = Table.FromRows(MatchItems, table_names)
in
    ToTable

 

This creates a sorted, distinct union of the columns and then stacks the table columns side-by-side based on this union using a method similar to what @Anonymous proposed.

 

You can invoke the function like this:

 

CompareTableColumns({"T1", "T2", "T3", "T4"}, "Col1")

 

AlexisOlson_0-1645033482034.png

where each of the tables looks similar to the T4 example:

AlexisOlson_1-1645033809153.png

@AlexisOlson I'm trying to do precisely this, but I'm getting an error relating to the column field ("Col1"). Can you explain the role of the column and "Col1" fields in your sample code?

 

I'm attaching screenshots of my queries in case they shed light on the error I'm receiving. Thanks in advance for any insight.

 

CompareTableColumns.pngColumnComparison.pngCompare Error.png

Do all of your test tables have a column named "Col1"? If not, that's your problem.

Thanks @AlexisOlson.  I figured out the problem.

 

Unlike the OP's tables (which are a single column containing heading names), mine were pivoted. For each of my tables, I had to use Table.ColumnNames to generate a list of columns, and then delete the other columns before running the custom function. 

Anonymous
Not applicable

You could make a Table.ColumnNames(TableName) for each table, and then use List.Zip to so that each column name is in the same position in the list, like:

 

= List.Zip({ColumnList1, ColumnList2, ColumnName3})

 

Then make it into a table using Table.FromRows(TheListZipQuery)

 

--Nate 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors