Forum Discussion

jrosa5's avatar
jrosa5
New Member
4 years ago
Solved

Creating a customer number based on the values of another column

I am trying to create a column that incrementally increases by one based on the values of another column in my query. The dataset I'm working with has non-unique customers within it, but I cannot jus...
  • ronrsnfld's avatar
    ronrsnfld
    4 years ago

    Try this:

    let
    
    //change next two lines to reflect actual data source
        Source = Excel.CurrentWorkbook(){[Name="IDtbl"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}),
    
    //You don't indicate where you get the first value from
    //   so you'll have to code it somehow.
        #"First UCN" = 38294,
    
    //Generate list of UCN's and associated IDs
        UCNs = List.Generate(
            ()=>[ucn=#"First UCN", id=#"Changed Type"[ID]{0}, idx=0],
            each [idx] < Table.RowCount(#"Changed Type"),
            each [ucn=if #"Changed Type"[ID]{[idx]+1} = [id] then [ucn] else [ucn]+1,
                    id=#"Changed Type"[ID]{[idx]+1}, idx = [idx]+1],
            each {[ucn],[id]}),
    
    //convert to a table
        tbl = Table.FromColumns(
                {List.Alternate(List.Combine(UCNs),1,1,1)} &
                {List.Alternate(List.Combine(UCNs),1,1,0)},
                type table[UCN=Int64.Type, ID=Int64.Type])
    in
        tbl