Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi,
I'm trying to calculate delayed discharge days within each month for delayed discharges in progress during that month.
The maximum delay within a given month for a specific record is the length of the month e.g. 31 days in August.
I have this DAX measure which isn't returning the correct values for what I need:
Solved! Go to Solution.
@timbad it's difficult without the pbix file, if you can share some sample data it'd better. However, try with this formula:
Delayed Discharge Days Snapshot ALL =
VAR SOP = MIN('Date'[Date])
VAR EOP = MAX('Date'[Date])
RETURN
CALCULATE(
SUMX(
'Delayed Discharge (CRFD)',
VAR DischargeStart = 'Delayed Discharge (CRFD)'[IPDelayedDischargeStartDate]
VAR DischargeEnd = COALESCE('Delayed Discharge (CRFD)'[IPDelayedDischargeEndDate], EOP)
VAR EffectiveStart = MAX(DischargeStart, SOP)
VAR EffectiveEnd = MIN(DischargeEnd, EOP)
VAR DaysInMonth = DATEDIFF(EffectiveStart, EffectiveEnd, DAY) + 1
RETURN
IF(DaysInMonth > 0, DaysInMonth, 0)
),
'Delayed Discharge (CRFD)'[IPDelayedDischargeStartDate] <= EOP,
('Delayed Discharge (CRFD)'[IPDelayedDischargeEndDate] >= SOP || ISBLANK('Delayed Discharge (CRFD)'[IPDelayedDischargeEndDate])),
REMOVEFILTERS('Date')
)
BBF
@timbad it's difficult without the pbix file, if you can share some sample data it'd better. However, try with this formula:
Delayed Discharge Days Snapshot ALL =
VAR SOP = MIN('Date'[Date])
VAR EOP = MAX('Date'[Date])
RETURN
CALCULATE(
SUMX(
'Delayed Discharge (CRFD)',
VAR DischargeStart = 'Delayed Discharge (CRFD)'[IPDelayedDischargeStartDate]
VAR DischargeEnd = COALESCE('Delayed Discharge (CRFD)'[IPDelayedDischargeEndDate], EOP)
VAR EffectiveStart = MAX(DischargeStart, SOP)
VAR EffectiveEnd = MIN(DischargeEnd, EOP)
VAR DaysInMonth = DATEDIFF(EffectiveStart, EffectiveEnd, DAY) + 1
RETURN
IF(DaysInMonth > 0, DaysInMonth, 0)
),
'Delayed Discharge (CRFD)'[IPDelayedDischargeStartDate] <= EOP,
('Delayed Discharge (CRFD)'[IPDelayedDischargeEndDate] >= SOP || ISBLANK('Delayed Discharge (CRFD)'[IPDelayedDischargeEndDate])),
REMOVEFILTERS('Date')
)
BBF
Thank you so much for your quick response, and for the code: worked perfectly first time!
Much appreciated. 😊
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 11 | |
| 9 | |
| 9 | |
| 6 | |
| 5 |
| User | Count |
|---|---|
| 27 | |
| 22 | |
| 19 | |
| 17 | |
| 11 |