Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have three columns of data: client_id, admit_date, and discharge_date. From this, I need to be able to calculate how many clients are in the program on any given day and be able to find average daily census numbers for a time period (week and month).
It seems to me that I should be able to do a form of COUNTIF of distinct client_id if the start_date is <= last day of the reporting period and the discharge date is >= first day of the reporting period, but I have no idea how to actually do that in a calculated measure.
Any help guiding me toward the right path would be greatly appreciated.
i think you need something like the measure
=CALCULATE(SUM([id]);DATESBETWEEN('Таблица1'[date 2];FIRSTDATE('Таблица1'[date 2]);LASTDATE('Таблица1'[date 2])))
Or you can use columns (=weeks(); and =month()), add them to slicer and use the measure AVG
Sorry for my English 😉
@Anonymous
I'm not entirely sure how to do that, but the data is pretty simple.
client_id | admit_date | discharge_date |
1 | 2016-10-21 | 2017-04-17 |
2 | 2016-10-27 | 2017-03-26 |
3 | 2016-11-01 | 2017-03-09 |
4 | 2016-11-02 | 2017-03-14 |
5 | 2016-11-15 | 2017-05-06 |
6 | 2016-12-01 | 2017-04-10 |
7 | 2016-12-02 | 2017-04-10 |
8 | 2016-12-04 | 2017-05-26 |
9 | 2016-02-13 | 2017-05-06 |
10 | 2016-12-08 | 2017-05-17 |
11 | 2016-12-14 | 2017-03-28 |
12 | 2016-12-16 | 2017-03-09 |
13 | 2016-12-16 | 2017-03-18 |
14 | 2016-12-18 | 2017-03-30 |
15 | 2016-12-19 | 2017-03-05 |
16 | 2016-12-22 | 2017-05-08 |
17 | 2016-12-30 | 2017-04-21 |
18 | 2017-01-01 | 2017-03-07 |
19 | 2017-01-04 | 2017-05-18 |
20 | 2017-01-09 | 2017-03-29 |
... and so on for a couple thousand rows.
Hi @rfickes,
According to your description, you want to get the distinct client count of selected date range, right?
If this is a case, you can refer to below formula to calculate the distinct count of match client count.
Steps:
1. Create a calendar with original date.
Calendar = CALENDAR(FIRSTDATE(Sheet2[admit_date]),LASTDATE(Sheet2[discharge_date]))
2. Add a measure to original table to calculate based on select range on calendar table.
Count = CALCULATE(DISTINCTCOUNT(Sheet2[client_id]),FILTER(ALL(Sheet2),[admit_date]>=FIRSTDATE(ALLSELECTED('Calendar'[Date]))&&[discharge_date]<=LASTDATE(ALLSELECTED('Calendar'[Date]))))
3. Use calendar date as the source of slicer, then calculate with selected date.
Regards,
Xiaoxin Sheng
Is there any way to get around FIRSTDATE and LASTDATE not being usable in DirectQuery mode?
Allowing unrestricted measures in DirectQuery mode solved one of the issues, but is it possible to build the calendar in DirectQuery and not Import mode?
I'm using DirectQuery to read the data from a SQL data warehouse and avoid having to pull over tens of thousands of lines of data into Power BI, but it's really starting to hamper my ability to work with the data. That being said, I'm new to Power BI and data warehousing, so I may be missing something obvious.
According to your description, you want to get the distinct client count of selected date range, right?
Actually, that's close, but I'm looking to be able to get an average distinct client count per day over a defined date range. So, for example, let's say on Monday I have 350 clients, on Tuesday I have 375, on Wendesday I have 365, and on Thursday I have 380. For Monday, my average daily client count would be 350. For Monday - Tuesday, it would be 362.5. For the week, it would be 367.5.
HI @rfickes,
>>Allowing unrestricted measures in DirectQuery mode solved one of the issues, but is it possible to build the calendar in DirectQuery and not Import mode?
You can try to create it in power query:
Regards,
Xiaoxin Sheng
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
72 | |
38 | |
31 | |
27 |
User | Count |
---|---|
92 | |
50 | |
44 | |
40 | |
35 |