Open In App

Merge and Append Queries in Power BI

Power BI is a popular data visualization tool that can be used to create interactive reports and dashboards. It can work on different types of data. A key feature to be noted is its ability to combine multiple data. The merging and appending functions in Power BI let you combine data from several tables.

Depending on the kind of concatenation you need to perform for your needs, you can choose between merge and append queries.



In this article, we will discuss about merging and appending queries in Power BI. We will discover the variations between append and merge queries, various joint kinds, and applications for fuzzy matching.

Merge Queries

Based on common criteria (a common column) between the tables, merge operations unite various datasets or tables horizontally. This means that data is added to the matching rows in the base or first table from the second and subsequent tables.



The primary table will consist of the same number of rows after the procedure as it did at the beginning if you use the default merge operation, but each row will have one or more new columns. However, if you choose for an other type of merge, this will not be applicable. The default merge functions in the same manner as an SQL left outer join.

How to Merge Queries?

Consider that we have two tables. The Sales Data is the first, and the next is Product data.

Sales Data:

Sales Data

Product Data:

Product Data

The following are the steps to merge the queries:

Step 1. Choose the query (table) that you want to combine the other query (or table) into from the Power Query Editor’s left pane. It’s Sales Data in this instance.

Step2. Select Sales Data Table. To access the Ribbon Menu, click the Home Tab.

Step 3. In the Combine section, click Merge.

Step 4. We will see two options under “Merge Queries”: “Merge Queries” and “Merge Queries as New.”

Step 5. After selecting Merge Queries option, choose Sales Data from the first drop-down option, then click Product Key (the shared column that separates the Sales and Product tables).

Step 6. Choose Product Data from the second drop-down option, then click Product_Key.

Step 7. Click on OK.

Merge Query

Join Types

There are six different kinds of joins:

Types Of Join

Join Kind

Fuzzy Match

By selecting the fuzzy match option, we can increase the Merge function’s reach.

When the fuzzy matching option is used, the number of matches will grow. The range of the similarity threshold is 0 to 1. In general, a default value of 0 would indicate a full outer join in SQL—match on precise matches—while a value of 1.00 would indicate an inner join.

In order to discover the matching join, the match by combining text portions option will combine two text values.

Fuzzy Match in Merge Queries

Append Queries

Append Operation is used to combine queries by stacking them on top of each other. When the column values in two tables match, the data rows from a given table will be added (or inserted) at the bottom of the other table’s data rows.

The base table will therefore have same number of columns at the conclusion of the procedures as it did at the beginning, but each column will have extra rows in an append operation.

Append refers to the process of combining the output of two or more queries—which are tables themselves—into a single query.

How to Append Queries?

The following are the steps to append the queries:

Step 1. Choose the query (table) that you wish the other query to append from the Power Query Editor’s left pane. It’s Sales Data in this instance.

Step 2. After selecting Sales Data Table click the Home Tab to access the Ribbon Menu.

Append Queries

Step 3. Select Append Queries from the Combine menu.

Step 4. Select Add Queries as New. A pop-up menu will appear.

Append Query popup

Step 5. Pick first query from the first drop-down selection.

Step 6. Choose second query from the second drop-down selection.

Step 7. Select OK.

After Appending Queries

What if the columns are different in the queries?

Append still functions even if the columns in the source queries are different; however, it will add one column to the output for every new column. The cell value of that column for those rows will be null if that column is absent from one of the sources. Append is equivalent to SQL’s UNION ALL.

Why should we combine Queries?

Before we dive deep into the concept of Merge and Append Queries, we must understand why combining queries is useful.

Difference Between Merge And Append Query

Feature

Merge Query

Append Query

Purpose

merges two tables according to a shared column

stacks two tables on top of one another to combine them.

Requirement

In each table, at least one matching column must exist.

It may require all columns to match in each table

Number of columns

Number of columns may differ in the queries

Queries to be appended should have same number of column

Result

Additions of columns to the query

Addition of more rows to the query

When to use

When you need to combine two tables into one by adding more columns, or when you need to create new relationships between tables

When a table already exists and you need to add more rows of data

Conclusion

Thus, it is easy to work with the data using PowerBI due to features like Merge and Append. Power BI merge and append queries are highly useful when getting ready to visualize your data because they allow you to combine data from several tables. When merge queries contain the fuzzy matching feature, which joins two tables based on partial matches, they become far more powerful.


Article Tags :