Results 1 to 3 of 3

Thread: Create a repeating set of IDs

  1. #1
    Acolyte Nick Burns's Avatar
    Join Date
    May 2017
    Posts
    44
    Articles
    0
    Excel Version
    Office 365

    Create a repeating set of IDs



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I need to create a repeating set of numbers (1 - 10) for a list of dates, however, there is a root date that needs to be set to 1. All dates after that are increased by 1 up to 10, repeating. All dates before that 10 - 1, repeating.

    The root date will be a parameter that can be changed, and the ending date will keep increasing.

    I've attached the workbook file with the table and requested output.

    Thanks for any help or guidance!
    Attached Files Attached Files
    Oh... by the way, YOU'RE WELCOME!

  2. #2
    Acolyte Bill Szysz's Avatar
    Join Date
    Apr 2016
    Location
    Poznań, Poland Dublin, Ireland
    Posts
    93
    Articles
    0
    Excel Version
    Excel 365
    Hi Nick,
    This is draft only
    Code:
    let
        RootDate = DateTime.Date(Excel.CurrentWorkbook(){[Name="Root"]}[Content]{0}[Root Date]),
        Source = Excel.CurrentWorkbook(){[Name="DateList"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dates", type date}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Dates", Order.Descending}}),
        Custom1 = Table.FirstN(#"Sorted Rows", each [Dates] >= RootDate),
        Tbl1 = Table.Sort(Table.FromColumns({ List.Reverse(Custom1[Dates]), List.Transform(List.Positions(Custom1[Dates]), each Number.Mod(_, 10)+1)}, {"Dates", "ID"}),{{"Dates", Order.Descending}}),
        Custom2 = Table.LastN(#"Sorted Rows", each [Dates] < RootDate),
        #"Added Index" = Table.AddIndexColumn(Custom2, "ID", 0, 1),
        Tbl2 = Table.TransformColumns(#"Added Index", {{"ID", each 10- Number.Mod(_, 10)}}),
        Custom3 = Table.Combine({Tbl1,Tbl2}),
        #"Changed Type1" = Table.TransformColumnTypes(Custom3,{{"Dates", type date}, {"ID", Int64.Type}})
    in
        #"Changed Type1"

  3. #3
    Acolyte Nick Burns's Avatar
    Join Date
    May 2017
    Posts
    44
    Articles
    0
    Excel Version
    Office 365
    Thanks Bill - That works like a charm... now to study it and understand it.
    Oh... by the way, YOU'RE WELCOME!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •