官术网_书友最值得收藏!

Pitfalls of using joins

Joins are simple to understand and use, but there is one hidden pitfall that can create lots of issues in your output data. Until now, we have seen simple data that had a one-to-one relationship between the values of the joining field, but in some scenarios, you may encounter multiple relationships between data. In such a case, your output data may get duplicated and the overall result may turn out wrong.

Let's understand this using the same example we used in the preceding sections. The only change will be that we add the last record in the Customer table:

 

You can see in the preceding table that we added a new record, which makes a duplicate entry for the primary key; that is, CustomerID, with a value of 3.

When we use this table along with any join condition, it will create two records in the resulting table, because the record 3 has a duplicate value. Let's assume that we use left join the Customer table to the Order table. The resulting output would look like the following screenshot:

You can see in the preceding screenshot that order number 102 has appeared twice, one with the customer name as Sam and the other as Vinay. You can also observe that OrderValue also got duplicated due to this new record. So, when you calculate on OrderValue from this resulting table, you will get the wrong value.

Thus, whenever you use any joins in Qlik Sense, you must make sure that the joining table has distinct records to get the correct values after joining.

One good way to check, which I also follow, is that the resulting table record count should be equal to the first table, because if there is a one-to-one relationship among the values, then the record count should be same. If they are not the same, then you should look for the duplicate values for the joining key in the joining table.
主站蜘蛛池模板: 信阳市| 朔州市| 延安市| 齐齐哈尔市| 辛集市| 农安县| 曲沃县| 休宁县| 北安市| 黄梅县| 宜黄县| 彰武县| 盐山县| 水富县| 三台县| 那坡县| 青岛市| 隆化县| 宜兰县| 得荣县| 兴业县| 南雄市| 观塘区| 开鲁县| 青铜峡市| 虎林市| 新闻| 漳浦县| 丽江市| 永丰县| 津南区| 鲁山县| 清河县| 高安市| 万宁市| 会宁县| 和平县| 吕梁市| 威海市| 吉首市| 灯塔市|