Forum Discussion

KamilGH's avatar
KamilGH
Frequent Visitor
3 years ago
Solved

ID Count per each calendar date

Hi everyone,

 

I have the following issue that I need your help to solve.

 

the following is an example of the dataset I have:

Membership_idStart_DateEnd_Date
m1July 1, 2023July 5, 2023
m2July 5, 2023July 9, 2023
m3July 4, 2023July 7, 2023

 

my goal is to get the count of membership_id per day like the example below:

DateCount of Memberships
July 1, 20231
July 2, 20231
July 3, 20231
July 4, 20232
July 5, 20233
July 6, 20232
July 7, 20232
July 8, 20231
July 9, 20231

 

 

in SQL, I can to join the first table with the calendar table and get the following results:

 

 

 

SELECT *
FROM First_Table t
LEFT OUTER JOIN Calendar c ON c.date >= t.Start_Date AND c.dt_dt <= t.End_Date

 

 

I could import the results to PowerBi and and count the memberships per day. however, the SQL query generates a huge amount of records which causing issues due to the restrictions we have.

DatesMembership_id
July 1, 2023m1
July 2, 2023m1
July 3, 2023m1
July 4, 2023m1
July 5, 2023m1
July 5, 2023m2
July 6, 2023m2
July 7, 2023m2
July 8, 2023m2
July 9, 2023m2
July 4, 2023m3
July 5, 2023m3
July 6, 2023m3
July 7, 2023m3

 

I hope there's a way to achieve that in PowerBi.

 

Thanks