Forum Discussion
Removing errors from list (not column) - in Power Query 'M'
- 9 years ago
Here are two further ideas using List.Positions to index the original list, but I don't think they are necessarily any more elegant and not sure performance-wise:
= List.RemoveNulls( List.Transform( List.Positions( ListWithError ), each try ListWithError{_} otherwise null ) )= List.Accumulate( List.Positions( ListWithError ), {}, (CleanListSoFar, CurrentPosition) => CleanListSoFar &
(if
(try ListWithError{CurrentPosition})[HasError] then {} else {ListWithError{CurrentPosition}} ) )
Here are two further ideas using List.Positions to index the original list, but I don't think they are necessarily any more elegant and not sure performance-wise:
=
List.RemoveNulls(
List.Transform(
List.Positions( ListWithError ),
each try ListWithError{_} otherwise null
)
)=
List.Accumulate(
List.Positions( ListWithError ),
{},
(CleanListSoFar, CurrentPosition) =>
CleanListSoFar &
(if
(try ListWithError{CurrentPosition})[HasError] then {} else {ListWithError{CurrentPosition}}
)
)
Hello OwenAuger!
Thanks a lot!
Your solutions looks very interesting.
Personally I'll take second solution for my purposes, as it is more universal (for example, whether I need remove errors only but not nulls).
But first solution is also very interesting because we can replace errors with other values (not nulls), and after some face-lifting this could be a very useful function like List.ReplaceErrors:
(ListWithError as list, optional Replacement as any) as list =>
let
Source = List.Transform(List.Positions(ListWithError), each try ListWithError{_} otherwise Replacement)
in
SourceThanks again for the idea!