I’m trying to do simple math on the results of a pivot and I am getting “null” values. Substituting in fixed integer or float values it works as expected, so I assume that I am not piping the values into the function, but I can’t figure out where I went wrong.
Any tips (and explanation) where I went wrong? Looking at the output as a table the input numbers all look good and it is clear that the output is “null”.
@Patrick808 It’s because you have null values in your math operations. If any operands in a mathematic operation are null, the operation returns null.
There are two things I can think of that will cause this:
You have points with null values (pre-pivot)
Your timestamps don’t perfectly align, so as a result of the pivot, some rows don’t have values for some of the columns used in your map operation.
I suspect it’s probably #2. There are a few solutions:
Use fill() to fill each of the columns in the pivoted data. Pivoted data does make this process a little cumbersome since fill() can only fill one column at a time:
You can normalize the timestamps to a precision where points should all align. For example, if you’re seeing sub-second differences in timestamps between all the different fields, you can normalize the timestamps to the second. To do this, use truncateTimeColumn() before you pivot the data:
Truth be told, you may need to do both of these. If timestamps still don’t align after normalizing/truncating the time values, you will still have to fill all the null columns.
Ah, I see the issue. You have an underscore (_) in front of AC1 in your map() call. That column doesn’t exist in the data, so it’s returning null. Remove the underscore and you should be good to go.