Forum Discussion
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 tblPat
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
Solution 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 tblPat
- smpa01
Community Champion
👍
- wdx223_Daniel
Community 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