Forum Discussion
IF Statement Amendment
- 10 months ago
Hi ArchStanton , try this formula.
Logic Used:
When the Created On equals the Resolution Date , return 1 day;
otherwise for resolved cases return an inclusive day count (DATEDIFF + 1).
For active cases the existing behaviour is preserved (you can switch to inclusive there too if you prefer).Case Length = VAR StartDate = IF( ISBLANK( 'Cases'[legacycasecreationdate] ), 'Cases'[Created On], 'Cases'[legacycasecreationdate] ) VAR IsActive = 'Cases'[statecode] = "Active" VAR ResDate = 'Cases'[Resolution Date] RETURN IF( IsActive, -- Active: difference between StartDate and now (unchanged behaviour) DATEDIFF( StartDate, NOW(), DAY ), -- Resolved: handle blanks, same-day, otherwise inclusive DATEDIFF (+1) IF( ISBLANK( ResDate ), BLANK(), IF( DATEVALUE( StartDate ) = DATEVALUE( ResDate ), 1, -- same calendar day => 1 DATEDIFF( StartDate, ResDate, DAY ) + 1 -- inclusive count ) ) )Notes / rationale
DATEVALUE(...) is used when comparing StartDate and ResDate so time components donโt make two same-day timestamps look different.
DATEDIFF(...)+1 gives an inclusive day count (e.g., start = 1-Jan, end = 2-Jan โ 2 days).
If you want inclusive logic for active cases too, change the active branch to DATEDIFF( StartDate, NOW(), DAY ) + 1.
If you prefer to always return 0 rather than BLANK() for missing Resolution Date, replace BLANK() with 0.
โญHope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
๐กFound it helpful? Show some love with kudos ๐ as your support keeps our community thriving!
๐Letโs keep building smarter, data-driven solutions together!๐ [Explore More]
Hi ArchStanton , try this formula.
Logic Used:
When the Created On equals the Resolution Date , return 1 day;
otherwise for resolved cases return an inclusive day count (DATEDIFF + 1).
For active cases the existing behaviour is preserved (you can switch to inclusive there too if you prefer).
Case Length =
VAR StartDate =
IF(
ISBLANK( 'Cases'[legacycasecreationdate] ),
'Cases'[Created On],
'Cases'[legacycasecreationdate]
)
VAR IsActive = 'Cases'[statecode] = "Active"
VAR ResDate = 'Cases'[Resolution Date]
RETURN
IF(
IsActive,
-- Active: difference between StartDate and now (unchanged behaviour)
DATEDIFF( StartDate, NOW(), DAY ),
-- Resolved: handle blanks, same-day, otherwise inclusive DATEDIFF (+1)
IF(
ISBLANK( ResDate ),
BLANK(),
IF(
DATEVALUE( StartDate ) = DATEVALUE( ResDate ),
1, -- same calendar day => 1
DATEDIFF( StartDate, ResDate, DAY ) + 1 -- inclusive count
)
)
)Notes / rationale
DATEVALUE(...) is used when comparing StartDate and ResDate so time components donโt make two same-day timestamps look different.
DATEDIFF(...)+1 gives an inclusive day count (e.g., start = 1-Jan, end = 2-Jan โ 2 days).
If you want inclusive logic for active cases too, change the active branch to DATEDIFF( StartDate, NOW(), DAY ) + 1.
If you prefer to always return 0 rather than BLANK() for missing Resolution Date, replace BLANK() with 0.
โญHope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
๐กFound it helpful? Show some love with kudos ๐ as your support keeps our community thriving!
๐Letโs keep building smarter, data-driven solutions together!๐ [Explore More]
This works perfectly, thank you!