Forum Discussion
Detectar numeración no correlativa (Power Query)
Hola necesito saber como detectar en una columna numeros NO correlativos o faltantes y colocarlos en otra columna o tabla indicando cuales faltan.
Alguna ayuda?
Columna con numeración
| R-5471370 |
| R-5471371 |
| R-5471372 |
| R-5471373 |
| R-5471375 |
| R-5471376 |
| R-5471377 |
| R-5471379 |
| R-5471380 |
| R-5471381 |
| R-5471382 |
| R-5471383 |
| R-5471384 |
| R-5471387 |
| R-5471388 |
| R-5471389 |
| R-5471390 |
| R-5471391 |
| R-5471392 |
| R-5471394 |
| R-5471395 |
| R-5471396 |
| R-5471397 |
| R-5471398 |
| R-5471399 |
| R-5471401 |
| R-5471403 |
| R-5471405 |
| R-5471406 |
| R-5471407 |
Nueva columna o tabla
| Numeracion | Estado |
| R-5471370 | OK |
| R-5471371 | OK |
| R-5471372 | OK |
| R-5471373 | OK |
| R-5471374 | |
| R-5471375 | OK |
| R-5471376 | OK |
| R-5471377 | OK |
| R-5471378 | |
| R-5471379 | OK |
| R-5471380 | OK |
| R-5471381 | OK |
| R-5471382 | OK |
| R-5471383 | OK |
| R-5471384 | OK |
| R-5471385 | |
| R-5471386 | |
| R-5471387 | OK |
| R-5471388 | OK |
| R-5471389 | OK |
| R-5471390 | OK |
| R-5471391 | OK |
| R-5471392 | OK |
| R-5471393 | |
| R-5471394 | OK |
| R-5471395 | OK |
| R-5471396 | OK |
| R-5471397 | OK |
| R-5471398 | OK |
| R-5471399 | OK |
| R-5471400 | |
| R-5471401 | OK |
| R-5471402 | |
| R-5471403 | OK |
| R-5471404 | |
| R-5471405 | OK |
| R-5471406 | OK |
| R-5471407 | OK |
This logic in Power Query will do it torovic
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc+xDcAgFMTQXagTCQIf7tZIi9h/DdIFl66ePGd672ij1JHTuv4qqAdVUYHqqIHyWYIneIIneGooCBIKnuEZnuEZgvFn/Bm6ofvUWy6oigpUR33C2g==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Valid", each "OK", type text), ExistingNumbers = List.Transform(#"Added Custom"[Data], each Number.From(Text.End(_, 7))), AllNumbers = {List.Min(ExistingNumbers)..List.Max(ExistingNumbers)}, Difference = List.Difference(AllNumbers, ExistingNumbers), Missing = List.Transform(Difference, each "R-" & Text.From(_)), #"Converted to Table" = Table.FromList(Missing, Splitter.SplitByNothing(), {"Valid"}, null, ExtraValues.Error), #"Appended Query" = Table.Combine({#"Added Custom", #"Converted to Table"}), #"Added Custom1" = Table.AddColumn(#"Appended Query", "Sort Column", each if [Data] = null then Number.From(Text.End([Valid], 7)) else Number.From(Text.End([Data],7))), #"Sorted Rows" = Table.Sort(#"Added Custom1",{{"Sort Column", Order.Ascending}}) in #"Sorted Rows"It returns this. You can delete the sort column if desired.
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
1 Reply
- edhans
Community Champion
This logic in Power Query will do it torovic
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc+xDcAgFMTQXagTCQIf7tZIi9h/DdIFl66ePGd672ij1JHTuv4qqAdVUYHqqIHyWYIneIIneGooCBIKnuEZnuEZgvFn/Bm6ofvUWy6oigpUR33C2g==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Valid", each "OK", type text), ExistingNumbers = List.Transform(#"Added Custom"[Data], each Number.From(Text.End(_, 7))), AllNumbers = {List.Min(ExistingNumbers)..List.Max(ExistingNumbers)}, Difference = List.Difference(AllNumbers, ExistingNumbers), Missing = List.Transform(Difference, each "R-" & Text.From(_)), #"Converted to Table" = Table.FromList(Missing, Splitter.SplitByNothing(), {"Valid"}, null, ExtraValues.Error), #"Appended Query" = Table.Combine({#"Added Custom", #"Converted to Table"}), #"Added Custom1" = Table.AddColumn(#"Appended Query", "Sort Column", each if [Data] = null then Number.From(Text.End([Valid], 7)) else Number.From(Text.End([Data],7))), #"Sorted Rows" = Table.Sort(#"Added Custom1",{{"Sort Column", Order.Ascending}}) in #"Sorted Rows"It returns this. You can delete the sort column if desired.
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.