How to compare everything with everything using Power BI or Power Query


A question in Mr. Excel-Forum about how to design your data model if you want to compare values from 10 different (fact-) tables with each other got me curious: As this simply felt so wrong… and where there are 10 tables today, there will be probably be 12 tables next …?

Time for Power Query to play out its strengths on dynamic approaches then: Key is to create one consolidated table from all the different input-tables with an additional column that contains the name of each source table.

If your data sits in Excel tables, you can find the description on how this works in the new Power Query book from Ken Puls and Miguel Escobar, starting on page 47 (key is to keep the name-column!).

In my example I’m using web-data that already has the format of a consolidated table, comparing inflations rates of different countries with each other. So the data-structure looks like this:


You then start a new query that refers to your source data and merge it with the source again on the year-column. The year-column shall stay the same, as we don’t want to compare different years against each other, but only different countries (Sources).

This will actually create a crossjoin of all countries against the country in the respective row – but within the same year. Last step is to create an additional column that calculates the difference between the values. This tells you how the inflation rate of the country to compare against is in relation to the source-country:


& this is the code:

Source = SourceData,
SelfMerge = Table.NestedJoin(Source,{"Year"},SourceData,{"Year"},"NewColumn",JoinKind.LeftOuter),
ExpandCrossjoin = Table.ExpandTableColumn(SelfMerge, "NewColumn", {"Source", "Year", "Value"}, {"Crossjoin.Source", "Crossjoin.Year", "Crossjoin.Value"}),
CalcDiff = Table.AddColumn(ExpandCrossjoin, "Diff", each -[Value]+[Crossjoin.Value]),
ChgFormats = Table.TransformColumnTypes(CalcDiff,{{"Value", type number}, {"Diff", type number}})

You can filter, slice&dice as you like and create pretty fancy reports with this technique 🙂



OK – technically at the end it’s just a simple crossjoin – the interesting part is actually what kind of problem we have solved with it: Combine multiple tables to compare against each other. So I’ll take this as the kickoff for my series on consolidation & reconciliation techniques then, so stay tuned!

Enjoy & stay queryious 🙂

Comments (6) Write a comment

Leave a Reply

Die Datenschutzbestimmungen finden Sie hier: / Please find the privacy policy here: