Replace N/A values with 0 in indicators
This script replaces N/A values with 0 values. Applies for Indicator widgets.
Before:
After:
Copy the following script and place it under 'Edit Script' in the designated Indicator widget:
widget.on('ready', function (w, e) {
-
Hi Robert Vaughan and Jessica Orlando
replace the code you have with this, it will fix both of these problems!
widget.on('render', function (w, q) {
if(w.queryResult.value.text == "")
{
w.queryResult.value.data = 0;
w.queryResult.value.text = 0;
}
if(w.queryResult.secondary != null && w.queryResult.secondary.text == "")
{
w.queryResult.secondary.data = 0;
w.queryResult.secondary.text = 0;
}
}) -
Hi, Ben Sadan!
Thank you very much for the code!
This code does not work for me, unfortunately. My primary value is a basic DUPCOUNT; however, the secondary one is PASTMONTH of it.
Both are 0 and it displays as such for the primary; however, still displays #N/A for the secondary.
Any help would be appreciated!
-
Hi Ben Sadan
This code seems to work for counts but not with sum.
If the indicator is using a Sum value, even with the code the result still shows "N/A".
Could you please help with this? -
here is an update for the script to take the N/A into account and display it as 0
hope this helps!
widget.on('render', function (w, q) {
if(w.queryResult.value.text == "" || w.queryResult.value.text == "#N/A")
{
w.queryResult.value.data = 0;
w.queryResult.value.text = 0;
}
if(w.queryResult.secondary != null && (w.queryResult.secondary.text == "" || w.queryResult.value.text == "#N/A"))
{
w.queryResult.secondary.data = 0;
w.queryResult.secondary.text = 0;
}
}) -
Hi Ben Sadan ,
It works perfectly. Thank you very much for your help.
Best,
-
This code is based the type of the returned data
widget.on('render', function (w, q) {
if (isNaN(w.queryResult.value.data) === true)
{
w.queryResult.value.data = 0;
w.queryResult.value.text = "0";
}
if(w.queryResult.secondary != null && isNaN(w.queryResult.secondary.data) === true)
{
w.queryResult.secondary.data = 0;
w.queryResult.secondary.text = "0";
}
})
Please sign in to leave a comment.
Comments
10 comments