Professional Documents
Culture Documents
The situation:
I have two tables. One is Sales Table; One is Traffic Table. What we need to do is to combine them into a single
fact table.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
BUT… If we do that with Left Outer Join, we will miss some data points. The following screenshot depicts the
situation:
Those traffic records with “?” do not have a matching record in the Sales table. As a result, those traffic records
are missed in the output, and most of the time without any notice/warning…
In ideal world, every store should have sales every day. However in real world, there may be zero-sales days… sad
but true. In those days, we had visitors (Traffic In) but no sales, which is no good. In this case, if we use Left
Outer Join, we will miss out those data with Traffic but no sales.
You may suggest we use the Traffic table as the anchor table to merge sales data to it, it will solve the problem (by
using Right Outer Join; or swap the order of the tables). Well, that’s only true when all stores have traffic data.
Nevertheless, only a few stores (in our example, 3 out of 8) have traffic data.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
1. Go to Data tab
2. Select From Table/Range
1. Under
Privacy Home
& Cookies: Tab
This site –> Close
uses cookies. & Load
By continuing to use this website, you agree to their use.
Now we should have the two queries loaded to connection only, as you can see in the Queries and Connections
pane. Right click the Sales query and Edit…
If you have experience with merging queries in Power Query, Full Outer Join should be your top-of-mind solution
for this problem. Nevertheless, it’s not a convenient way as the layout of the output will not be what you want…
Click the double arrows icon in the column header, and then
Here we go!
We have the Traffic correctly mapped to the Sales table. From row 53 to 56, the four records with traffic but no
sales are displayed there. However nothing is under the Date and Store columns…
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
Well, although we get the Date and Store information as expected, we’d also got two extra columns across the
entire merged table…
This is obviously not an ideal layout. Who wants two columns for the same attributes?
We will need many tedious steps to convert this layout back to normal. Therefore I am going to do it with another
approach, which is exactly the topic of today.
Second attempt – Left Out Join + Right Anti Join followed by Append
Repeat the Merge Step described above. But this time we do a Left Outer Join:
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
1. Rename it to “TrafficWithNoSales“
2. Delete the steps “Expanded Traffic” and “Merged Queries” by clicking the x
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
The result we have should contain only one row! All the TrafficWithNoSales records are stored in the “Table”
under the Traffic column.
Yeah… We’ve got a table showing the records where we have Traffic but no sales.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
Note: The columns “Date” and “Store” in the two tables must be exactly the same. Otherwise the Appended
result may put them into different columns. You may need to rename the column headers if required.
Almost there…
Now we have the TrafficWithNoSales records nicely appended to the Sales table merged with traffic data.
Tip: We may also rename the query to something more meaningful, e.g. Sales with Traffic data
About MF
An Excel nerd who just transition into a role related to data analytics at current company......
Recently in love with Power
Query and Power BI.
Keep learning new Excel and Power BI stuffs and be amazed by all the new discoveries.
View all posts by MF →
This entry was posted in Power Query and tagged Append Query, Merge Query. Bookmark the permalink.
mma173 says:
March 24, 2020 at ^.^
The way I would resolve this is different. I read both of your solutions.
• Merged the result twice again based on both columns: first time with the Sales Table then with the Traffic Table.
Done
Like
Reply
MF says:
March 24, 2020 at ^.^
Like
Reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
wmfexcel
Blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.