Forum Discussion
List.RemoveItems Bug related to Number.NaN
Just ran into this and I think it's a bug. Say you have a simple list with NaNs in it and you want to remove them. Neither List.RemoveItems() nor List.RemoveMatchingItems() will remove the NaNs. See repro below:
let
Source = {3, 540, 309, 30, Number.NaN, 384},
RemoveNan = List.RemoveItems(Source, {Number.NaN})
in
RemoveNan
Now, I know this could be solved via List.Select(Source, each not Number.IsNaN(_)), but this definitely seems like inconsistent, unintended, or unexpected behavior. See another repro using Number.PositiveInfinity where it works like you would expect.
let
Source = {3, 540, 309, 30, Number.PositiveInfinity, 384},
RemovePosInfinity = List.RemoveItems(Source, {Number.PositiveInfinity})
in
RemovePosInfinity
I've also tested this simple code with Number.NegativeInfinity, Number.PI, Number.E, Number.Epsilon, and null, and for everything but Number.NaN, List.RemoveItems/List.RemoveMatchingItems works.
3 Replies
- AnonymousNot applicable
You are using Number.NaN, but that doesn't appear to be a valid function in the number functions list:
https://learn.microsoft.com/en-us/powerquery-m/number-functions
--Nate
- routineMetric0Regular Visitor
It's not a function, it's a constant. https://learn.microsoft.com/en-us/powerquery-m/number-nan
- AnonymousNot applicable
Ha, so it is! 🙂
---Nate