This maybe a simple snippet, but I cannot get it to work. I have a small arcade line on my dashboard list to calculate the time that gas was turned off. Simpily subtracts the On time from the Off time.
But, when a service is never turned off, it has nothing in these fields to subtract and results in a 'NaN' I wanted to add an iif statement that takes these NaN's and either leaves them blank and displays nothing or more ideally comes back with 'Zero'
But since it is a NaN result and not something that I can add an If Blank, I am struggling to figure out how this can be done.
Any help would be amazing! Thanks.
Attached: List view from dashboard and the snippet of the arcade
Arcade Text:
var Status = $datapoint.OutageStatus
var Off = $datapoint.DateOff
var On = $datapoint.DateRelightComplete
var DaysOff = DateDiff (On, Off, 'hours')
var HoursOff = Round(DaysOff,1)
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
HoursOff:HoursOff,
}
}
Line item template:
({expression/HoursOff} Hours without Gas)
Solved! Go to Solution.
You can wrap the whole expression in an Iif function, and return something else when there's no value. And you can actual build the entire text string in the expression as well.
var Off = $datapoint.DateOff
var On = $datapoint.DateRelightComplete
var HoursOff = Iif(
IsEmpty(Off), // check if field is empty
'System Never Turned Off',
`(${Round(DateDiff(On, Off, 'hours'), 1)} Hours without Gas)`
)
return {
attributes: { HoursOff }
}
Then your line item template can just be {expression/HoursOff} .
You can check if those values are empty before doing your calculations
var Status = $datapoint.OutageStatus;
var Off = $datapoint.DateOff;
var On = $datapoint.DateRelightComplete;
var HoursOff;
if (IsEmpty(On) || IsEmtpy(Off)) {
HoursOff = 0;
} else {
HoursOff = Round(DateDiff(On, Off, 'hours'), 1);
}
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
HoursOff:HoursOff,
}
}
or you can use the IsNan function afterward
var Status = $datapoint.OutageStatus
var Off = $datapoint.DateOff
var On = $datapoint.DateRelightComplete
var DaysOff = DateDiff (On, Off, 'hours')
var HoursOff = Round(DaysOff,1)
if (IsNan(HoursOff)) HoursOff = 0;
You can wrap the whole expression in an Iif function, and return something else when there's no value. And you can actual build the entire text string in the expression as well.
var Off = $datapoint.DateOff
var On = $datapoint.DateRelightComplete
var HoursOff = Iif(
IsEmpty(Off), // check if field is empty
'System Never Turned Off',
`(${Round(DateDiff(On, Off, 'hours'), 1)} Hours without Gas)`
)
return {
attributes: { HoursOff }
}
Then your line item template can just be {expression/HoursOff} .
That's perfect! I was trying to get the iif statement in the wrong spot. This also helps me understand how to simplify my arcade formatting. Thank you so much for the help!