Search code examples
nullpowerbiblank-line

How can I check if a categories value is null in Power BI?


OK, so I am trying to build a legend, and some values are blank from the incoming data (was going to mark this as uncategorized). However, the blank values are not being parsed correctly. I tried MANY combinations and tried searching for this answer for quite some time now and am getting desperate.

I realize this may be a little messy but I've just been testing it out, sorry.

let legendData = categories[1] ? categories[1].values : [];
global.legend.values = [];
let last: any = "";
    // The toString().length of the blank one is 3....  And it is not null, '', or "   "
legendData.forEach((value) => {
     if (value && value != last){global.legend.values.push(value);}
     last = value;
     console.log(value);
});

So again, I am trying to get only all values that are NOT null in global.legend.values. When I print out every element in global.legend.values, however, those pesky blanks are there with their own line each. The value is blank in the imported Excel file, showing up as null in blue text in the DataView, and that console.log(value); is printing out null as well...

value.toString().length is 3, which is also confusing. What could I be missing? I appreciate all help.


Solution

  • Holy mess - I had shifted my legend from one category to a different one, and my answer wasn't general enough. I was only accounting for repeat values right next to each other, not in the whole thing. I still don't know why they were printing out blank, but maybe that was my implementation later on in actually drawing the legend - null values were NOT making it into the transformed array, so I was safe there.

    Here is my better, more general solution:

    let legendData = categories[1] ? categories[1].values : [];
    global.legend.values = [];
    legendData.forEach((value) => {
         if (value && global.legend.values.indexOf(value) < 0){global.legend.values.push(value);}
         });
    

    Sorry for the misunderstanding there - must have just been a long day..