Forum Discussion

LahiruFernando's avatar
LahiruFernando
Frequent Visitor
3 years ago

Distinct Count from filtered table by per category max value records.

Hi,
I am a novice to Power bi and expect your expertise assistance to solve below.
I have two tables, one is device data and the other is date table. Relationship between two tables is start date from device table and date from date table.

Device Table

 

rank_dateuser_idstart_dateend_datedevice
110000110/1/202010/1/2022x
210000120/2/202020/2/2022y
31000011/5/20211/6/2023x
110000220/1/202020/1/2022y
110000315/1/202015/1/2022y
210000314/05/202014/05/2022x
11000041/3/20211/3/2023x


If taking the user id 100001 to explain the logics to calculate ,

Final output should be like below table which Year and month is from date table.


(to get below table, always need to consider the record of maximum deviceTable[rank_date] for that particular user filtered first for considered date period)

1. Active users - 

distinct count of users, where deviceTable[start_date] <= endOfPeriod  && deviceTable[end_date] >= startOfPeriod
 
2. active_x_devices

distinct count of users, where deviceTable[start_date] <= endOfPeriod  && deviceTable[end_date] >= startOfPeriod, and if the deviceTable[device] = "x"

2. active_y_devices

distinct count of users, where deviceTable[start_date] <= endOfPeriod  && deviceTable[end_date] >= startOfPeriod, and if the deviceTable[device] = "y"

 

Here the user's 100001 device "y" is active after 20/2/2020 his device "x" is no more considered as active as we always take the maximum deviceTable[rank_date] per user for the considered period.

YearMonthActive Usersactive_x_devicesactive_y_devices
2020January11 
2020Ferbruay1 1
2020March1 1
2020April1 1
2020May1 1

 

 

Appreciate if anyone could help. 
Thanking in advance.

2 Replies