Forum Discussion

torovic's avatar
torovic
Frequent Visitor
4 years ago
Solved

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

NumeracionEstado
R-5471370OK
R-5471371OK
R-5471372OK
R-5471373OK
 R-5471374
R-5471375OK
R-5471376OK
R-5471377OK
 R-5471378
R-5471379OK
R-5471380OK
R-5471381OK
R-5471382OK
R-5471383OK
R-5471384OK
 R-5471385
 R-5471386
R-5471387OK
R-5471388OK
R-5471389OK
R-5471390OK
R-5471391OK
R-5471392OK
 R-5471393
R-5471394OK
R-5471395OK
R-5471396OK
R-5471397OK
R-5471398OK
R-5471399OK
 R-5471400
R-5471401OK
 R-5471402
R-5471403OK
 R-5471404
R-5471405OK
R-5471406OK
R-5471407OK

 

  • 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's avatar
    edhans
    Icon for Community Champion rankCommunity 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.