Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
Hi!
I'm developing a callback dashboard and the challenge is the following, I have a table of incoming calls and another table with phones that must be purged. I need to identify which cases should be purged from the incoming calls table without generating duplicates.
The purges table can contain the same phone several times, in different channels or dates, so when I do the "merge" in the power bi, some phones are duplicated and I am not able to remove the duplicates taking into account the rules.
First of all the tables look like these:
*The phone numbers, as well as the channels were originally replaced by random values, generated from the Excel "random" formula.
Incoming call table:
id | date | phone_number | channel |
69819 | 01/07/2022 | 981485009 | CS |
69227 | 01/07/2022 | 991588762 | CS |
69536 | 01/07/2022 | 999408912 | CS |
69853 | 01/07/2022 | 999472894 | CS |
70018 | 01/07/2022 | 1120946054 | CS |
69558 | 01/07/2022 | 1122027100 | CS |
69540 | 01/07/2022 | 1122587241 | CS |
69629 | 01/07/2022 | 1124095781 | CS |
70093 | 01/07/2022 | 1124095781 | CS |
69911 | 01/07/2022 | 1124096723 | CS |
70116 | 01/07/2022 | 1125621333 | CS |
69370 | 01/07/2022 | 1125725400 | CS |
69669 | 01/07/2022 | 1126019574 | CS |
69287 | 01/07/2022 | 1126597208 | CS |
Purges table:
phone_number | channel | initial_date | final_date |
30732524688599 | CS | 01/01/2020 | |
14337853219993 | CS | 01/01/2020 | |
59190721082293 | CS | 01/01/2020 | |
16283679073036 | CS | 01/01/2020 | |
47630830671103 | CS | 01/01/2020 | |
25328736777322 | CS | 01/01/2020 | |
54018118052795 | CS | 01/01/2020 | |
53195278252695 | CS | 01/01/2020 | |
57259967606207 | SAC | 01/01/2020 | |
7320107239150 | SAC | 01/01/2020 | |
49314065238063 | SAC | 01/01/2020 | |
16594429566012 | SAC | 01/01/2020 | |
16597967001819 | SAC | 01/01/2020 | |
88940702501287 | SAC | 01/01/2020 | |
7671555843556 | SAC | 01/01/2020 | |
6297551829108 | SAC | 01/01/2020 | |
19233336321891 | SAC | 01/01/2020 | |
13016669976935 | RECEPTIVE | 01/01/2020 | |
42839095059532 | RECEPTIVE | 01/01/2020 | |
16082650569259 | RECEPTIVE | 01/01/2020 |
The rules are as follows:
My idea would be, do it like in SQL, similar to the example below, but I don't know how to do something similar in power query or in M, can you help me?
select
c.phone_number,
c.channel,
c.date
from
calls c
join
purge p on
p.phone_number = c.phone_number and
p.channel = c.channel and
(case
when final_date is null then
case
when p.initial_date <= c.date then 1
else 0
end
else
case
when c.date between p.initial_date and p.final_date then 1
else 0
end
end)=1
Sorry for the mess in the SQL code, I couldn't adjust the text editing on the site.
HI @Anonymous ,
Hold control and click the column you want to merge. You can select multiple columns to merge to avoid duplicate values.
Regards
KT
Thanks. But the problem is that of the three columns I need to relate, only two work this way. In the case of the date, I need the power query to bring me only the cases from the purges table that have periods compatible with the date of the call, present in the table of received calls.
@Anonymous Can you share sample output in table format?
Incoming call table
id | phone_number | channel | date |
1 | 9992365b | LEVEL 1 | 11/07/2022 |
2 | 992b6576 | LEVEL 1 | 11/07/2022 |
3 | 99834738 | LEVEL 1 | 11/07/2022 |
4 | 99375454 | LEVEL 1 | 11/07/2022 |
5 | 99b29a86 | LEVEL 1 | 11/07/2022 |
6 | 9943377a | LEVEL 1 | 11/07/2022 |
7 | 99957b85 | LEVEL 1 | 11/07/2022 |
8 | 99957b85 | LEVEL 1 | 11/07/2022 |
9 | 99957b85 | LEVEL 1 | 11/07/2022 |
10 | 993a9aaa | LEVEL 1 | 01/08/2022 |
11 | 993a9aaa | LEVEL 1 | 01/08/2022 |
12 | 993a9aaa | LEVEL 1 | 03/10/2022 |
13 | 99834528 | LEVEL 1 | 05/07/2022 |
14 | 99834528 | LEVEL 1 | 05/07/2022 |
15 | 99834528 | LEVEL 1 | 05/07/2022 |
16 | 99988a65 | SAC | 21/10/2022 |
17 | 99988a65 | SAC | 21/10/2022 |
18 | 99988a65 | SAC | 21/10/2022 |
19 | 99437b43 | LEVEL 1 | 04/07/2022 |
20 | 99437b43 | LEVEL 1 | 04/07/2022 |
21 | 99437b43 | LEVEL 1 | 04/07/2022 |
Purges table
phone_number | channel | initial_date | final_date |
99375454 | LEVEL 1 | 01/08/2022 | |
993a9aaa | LEVEL 1 | 01/01/2020 | |
99437b43 | LEVEL 1 | 01/01/2020 | |
99988a65 | LEVEL 1 | 01/02/2021 | |
99437b43 | LEVEL 1 | 01/07/2022 | |
99834528 | LEVEL 1 | 01/07/2022 | |
9943377a | LEVEL 1 | 01/10/2022 | |
99437b43 | LEVEL 1 | 01/05/2022 | |
99b29a86 | LEVEL 1 | 01/09/2022 | |
99834528 | SAC | 01/10/2022 | |
99834528 | RETENTION | 01/10/2022 | |
993a9aaa | SAC | 01/12/2022 | |
993a9aaa | RETENTION | 01/12/2022 | |
99437b43 | SAC | 01/01/2020 | |
99957b85 | SAC | 01/01/2020 | |
99437b43 | LEVEL 2 | 01/01/2020 | |
99957b85 | LEVEL 2 | 01/01/2020 | |
99988a65 | SAC | 01/02/2021 | |
99988a65 | SAC EPV | 01/02/2021 | |
99437b43 | SAC | 01/07/2022 | |
99834528 | SAC | 01/07/2022 | |
99988a65 | SAC | 01/10/2022 | |
99988a65 | RETENTION | 01/10/2022 |
Merged incoming calls table (by phone_number and channel)
id | phone_number | channel | date | initial_date | final_date |
4 | 99375454 | LEVEL 1 | 11/07/2022 | 01/08/2022 | |
10 | 993a9aaa | LEVEL 1 | 01/08/2022 | 01/01/2020 | |
11 | 993a9aaa | LEVEL 1 | 01/08/2022 | 01/01/2020 | |
12 | 993a9aaa | LEVEL 1 | 03/10/2022 | 01/01/2020 | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/01/2020 | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/07/2022 | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/05/2022 | |
20 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/01/2020 | |
20 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/07/2022 | |
20 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/05/2022 | |
21 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/01/2020 | |
21 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/07/2022 | |
21 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/05/2022 | |
5 | 99b29a86 | LEVEL 1 | 11/07/2022 | 01/09/2022 | |
6 | 9943377a | LEVEL 1 | 11/07/2022 | 01/10/2022 | |
13 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | |
14 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | |
15 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | |
16 | 99988a65 | SAC | 21/10/2022 | 01/02/2021 | |
16 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | |
17 | 99988a65 | SAC | 21/10/2022 | 01/02/2021 | |
17 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | |
18 | 99988a65 | SAC | 21/10/2022 | 01/02/2021 | |
18 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | |
1 | 9992365b | LEVEL 1 | 11/07/2022 | ||
2 | 992b6576 | LEVEL 1 | 11/07/2022 | ||
3 | 99834738 | LEVEL 1 | 11/07/2022 | ||
7 | 99957b85 | LEVEL 1 | 11/07/2022 | ||
8 | 99957b85 | LEVEL 1 | 11/07/2022 | ||
9 | 99957b85 | LEVEL 1 | 11/07/2022 |
Merged table in treatment
id | phone_number | channel | date | initial_date | final_date | classification | action | comment |
1 | 9992365b | LEVEL 1 | 11/07/2022 | common call | keep in base | it was not found in the purges base, therefore it must be | ||
10 | 993a9aaa | LEVEL 1 | 01/08/2022 | 01/01/2020 | purge | keep in base | call within the period | |
11 | 993a9aaa | LEVEL 1 | 01/08/2022 | 01/01/2020 | purge | keep in base | call within the period | |
12 | 993a9aaa | LEVEL 1 | 03/10/2022 | 01/01/2020 | purge | keep in base | call within the period | |
13 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | purge | keep in base | call within the period | |
14 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | purge | keep in base | call within the period | |
15 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | purge | keep in base | call within the period | |
16 | 99988a65 | SAC | 21/10/2022 | 01/02/2021 | purge | exclude from base | call within the period | |
16 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | purge | keep in base | call within the period, most recent | |
17 | 99988a65 | SAC | 21/10/2022 | 01/02/2021 | purge | exclude from base | call within the period | |
17 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | purge | keep in base | call within the period, most recent | |
18 | 99988a65 | SAC | 21/10/2022 | 01/02/2021 | purge | exclude from base | call within the period | |
18 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | purge | keep in base | call within the period, most recent | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/01/2020 | purge | exclude from base | call within the period | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/07/2022 | purge | keep in base | call within the period, most recent | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/05/2022 | purge | exclude from base | call within the period | |
2 | 992b6576 | LEVEL 1 | 11/07/2022 | common call | keep in base | it was not found in the purges base, therefore it must be |
Treated merged table
id | phone_number | channel | date | initial_date | final_date | classification |
1 | 9992365b | LEVEL 1 | 11/07/2022 | common call | ||
10 | 993a9aaa | LEVEL 1 | 01/08/2022 | 01/01/2020 | purge | |
11 | 993a9aaa | LEVEL 1 | 01/08/2022 | 01/01/2020 | purge | |
12 | 993a9aaa | LEVEL 1 | 03/10/2022 | 01/01/2020 | purge | |
13 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | purge | |
14 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | purge | |
15 | 99834528 | LEVEL 1 | 05/07/2022 | 01/07/2022 | purge | |
16 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | purge | |
17 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | purge | |
18 | 99988a65 | SAC | 21/10/2022 | 01/10/2022 | purge | |
19 | 99437b43 | LEVEL 1 | 04/07/2022 | 01/07/2022 | purge | |
2 | 992b6576 | LEVEL 1 | 11/07/2022 | common call |
I hope it helps you understand
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
19 | |
11 | |
10 | |
7 | |
7 |