Forum Discussion
ArchStanton
3 years agoPower Participant
Are Variables possible in my code?
Hi,
I'm struggling to understand how the attached code works, is it possible to modify it with Variables to make it read easier?
Case Length (Adj) =
IF (
'Cases'[statecode] = "Active",
DATEDIFF (
IF (
ISBLANK ( 'Cases'[legacycasecreationdate] ),
'Cases'[Created On],
'Cases'[legacycasecreationdate]
),
NOW (),
DAY
),
DATEDIFF (
IF (
ISBLANK ( 'Cases'[legacycasecreationdate] ),
'Cases'[Created On],
'Cases'[legacycasecreationdate]
),
'Cases'[Resolution Date],
DAY
)
)Thanks
Hi ArchStanton ,
You can try to rewrite it like this:
Case Length (Adj) = VAR date_from = IF ( ISBLANK ( 'Cases'[legacycasecreationdate] ), 'Cases'[Created On], 'Cases'[legacycasecreationdate] ) RETURN IF ( 'Cases'[statecode] = "Active", DATEDIFF ( date_from, NOW (), DAY ), DATEDIFF ( date_from, 'Cases'[Resolution Date], DAY ) )
3 Replies
- ERDCommunity Champion
Hi ArchStanton ,
You can try to rewrite it like this:
Case Length (Adj) = VAR date_from = IF ( ISBLANK ( 'Cases'[legacycasecreationdate] ), 'Cases'[Created On], 'Cases'[legacycasecreationdate] ) RETURN IF ( 'Cases'[statecode] = "Active", DATEDIFF ( date_from, NOW (), DAY ), DATEDIFF ( date_from, 'Cases'[Resolution Date], DAY ) )- ArchStantonPower Participant
Thank you - that works perfectly!
- ERDCommunity Champion
ArchStanton , your code says:
If legacycasecreationdate is empty, consider Created On as a Date From. If it's not empty, use it as a Date From.
Then wherever statecode = "Active", count how many days between the date chosen above and now. If statecode has some other value, count how many days between the date chosen above and a Resolution Date.