Forum Discussion

smpa01's avatar
smpa01
Icon for Community Champion rankCommunity Champion
3 years ago
Solved

Create table from list of integers by specifying true data type

++ AlexisOlson CNENFRNL Rickmaurinus 

Referring to this 

Is there a way to create a table from a list of integers in one shot?

 E.g.

If I do this,

 

let 
    yearMax = 2023,
    yearMin=yearMax-1,
    yearList = {yearMin..yearMax},
    tbl = Table.FromList(
    yearList,
    null,
    type table[ actualYr = Int64.Type ] 
)
in
    tbl

 

I run into this

I know I can do this. But I want to avoid any extra step if I can, given that PQ is doing heavy transformations in succeeding steps and I want to optimize as much as I can.

 

let 
    yearMax = 2023,
    yearMin=yearMax-1,
    yearList = List.Transform({yearMin..yearMax},each Text.From(_)),
    tbl = Table.FromList(
    yearList,
    null,
    type table[ actualYr = Text.Type ] 
),
    #"Changed Type" = Table.TransformColumnTypes(tbl,{{"actualYr", Int64.Type}})
in
    #"Changed Type"

 

Thank you in advance

  • Please try this instead.

    let 
        yearMax = 2023,
        yearMin=yearMax-1,
        yearList = {yearMin..yearMax},
        tbl = #table( type table [actualYr = Int64.Type], List.Split(yearList, 1))
    in
        tbl

    Pat

  • this code works

     

    let
    yearMax = 2023,
    yearMin=yearMax-1,
    yearList = {yearMin..yearMax},
    tbl = Table.FromList(
    yearList,
    Splitter.SplitByNothing(),
    type table[ actualYr = Int64.Type ]
    )
    in
    tbl

3 Replies

  • ppm1's avatar
    ppm1
    Icon for Solution Sage rankSolution Sage

    Please try this instead.

    let 
        yearMax = 2023,
        yearMin=yearMax-1,
        yearList = {yearMin..yearMax},
        tbl = #table( type table [actualYr = Int64.Type], List.Split(yearList, 1))
    in
        tbl

    Pat

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    this code works

     

    let
    yearMax = 2023,
    yearMin=yearMax-1,
    yearList = {yearMin..yearMax},
    tbl = Table.FromList(
    yearList,
    Splitter.SplitByNothing(),
    type table[ actualYr = Int64.Type ]
    )
    in
    tbl