Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Distinct Count of Id's between first and last date dynamically with calendar table

I have a table where I keep PersonId's from our application and then the first and last date of their subscriptions. These are normally in whole year spans. So the FirstSubStartDate would be 8/31/2021 and LastSubEndDate is 8/30/2022.

I also have a Reporting Calendar table that updates daily and allows me to chop up the data in any form I choose.

My struggle is finding a way to write a measure where I can choose what way to do a distinct count of these personid's and choose to graph it by year, month or whatever option I have in this reporting calendar.

Person Subscription Table

PersonIdFirstSubStartDateLastSubEndDate
11868/31/20208/30/2022
348592/10/20202/9/2021
348898/8/20208/7/2021


Here is what Im looking for:
I need a measure so when I put it into a bar or line graph and have Months for the X Axis, that it provides the distinct number of Id's in that month.

So in the above examples, if I was looking at Jan-Dec in 2021, 1186 would count once in each month where 34859 would count in Jan and Feb and then 34889 would count Jan-Aug. Only 1186 would count beyond 8/2021 because its LastSubEndDate goes into 2022.

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Along with your example data I created a date table that was unrelated to the example data.
The measure I used was

Count of IDs =
CALCULATE(
    DISTINCTCOUNT('Table'[PersonId]),
    FILTER('Table', 'Table'[FirstSubStartDate] <= MAX(dimDate[Date]) && 'Table'[LastSubEndDate] >= MIN(dimDate[Date]) )
)
Using the date table date hierarchy as the x-axis I was able to get
 
jgeddes_0-1663854670067.png

You can then use the date hierarchy to view the data at the resolution you desire

jgeddes_1-1663854777408.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
jgeddes
Super User
Super User

Along with your example data I created a date table that was unrelated to the example data.
The measure I used was

Count of IDs =
CALCULATE(
    DISTINCTCOUNT('Table'[PersonId]),
    FILTER('Table', 'Table'[FirstSubStartDate] <= MAX(dimDate[Date]) && 'Table'[LastSubEndDate] >= MIN(dimDate[Date]) )
)
Using the date table date hierarchy as the x-axis I was able to get
 
jgeddes_0-1663854670067.png

You can then use the date hierarchy to view the data at the resolution you desire

jgeddes_1-1663854777408.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

I was really overthinking that. I had everthing except for the MIN/MAX. Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.