Forum Discussion
Delete rows with a condition in PowerQuery
- 3 years ago
Hey Dani,
Thanks for the question. It's a common scenario that can be a little tricky. Here's a way:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZFLCsAgDETvknUFzUftWYp36LLHL65My0hcSXg4eeN10TNPoYPueeaFM0vKLbHROP4Ae+AEgESARoB5IAOgbl5gZFEEAN6iGAA+Fh0AGkVYFFGjiBZpdgeIK0pgDwYA3uwgqAevKbAHFGFRxOwBjJd9T5kXoFCuAYA/D6tXAmPd7KnwQwUAdVOFeiUa4wU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Batch = _t, Parameter = _t, #"Inspection date" = (type date)]), ChType = Table.TransformColumnTypes(Source,{{"Batch", type text}, {"Parameter", type text}, {"Inspection date", type date}}), RowsWithNull = Table.SelectRows(ChType, each [Inspection date] = null), BatchesToRemove = List.Distinct( RowsWithNull[Batch] ), BackToSource = Source, RemoveRows = Table.SelectRows(BackToSource, each not List.Contains( BatchesToRemove, [Batch] ) ) in RemoveRowsYou could try above steps. You would
1. Filter your data only the items with null
2. Retrieve the batches related to these
3. Filter the original dataset to exclude these
Cheers,
Rick
--------------------------------------------------
@ me in replies or I'll lose your thread
Master Power Query M? -> https://powerquery.how
Read in-depth articles? -> BI Gorilla
Youtube Channel: BI Gorilla
If this post helps, then please consider accepting it as the solution to help other members find it more quickly.
Hey Dani,
Thanks for the question. It's a common scenario that can be a little tricky. Here's a way:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZFLCsAgDETvknUFzUftWYp36LLHL65My0hcSXg4eeN10TNPoYPueeaFM0vKLbHROP4Ae+AEgESARoB5IAOgbl5gZFEEAN6iGAA+Fh0AGkVYFFGjiBZpdgeIK0pgDwYA3uwgqAevKbAHFGFRxOwBjJd9T5kXoFCuAYA/D6tXAmPd7KnwQwUAdVOFeiUa4wU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Batch = _t, Parameter = _t, #"Inspection date" = (type date)]),
ChType = Table.TransformColumnTypes(Source,{{"Batch", type text}, {"Parameter", type text}, {"Inspection date", type date}}),
RowsWithNull = Table.SelectRows(ChType, each [Inspection date] = null),
BatchesToRemove = List.Distinct( RowsWithNull[Batch] ),
BackToSource = Source,
RemoveRows = Table.SelectRows(BackToSource, each not List.Contains( BatchesToRemove, [Batch] ) )
in
RemoveRows
You could try above steps. You would
1. Filter your data only the items with null
2. Retrieve the batches related to these
3. Filter the original dataset to exclude these
Cheers,
Rick
--------------------------------------------------
@ me in replies or I'll lose your thread
Master Power Query M? -> https://powerquery.how
Read in-depth articles? -> BI Gorilla
Youtube Channel: BI Gorilla
If this post helps, then please consider accepting it as the solution to help other members find it more quickly.