• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Generate lists with variable boundries

CarlW

New Member
Hi,

I am trying to create a list depending on 2 field values. In my table, I have a field BottomValue and a field TopValue. For each row I want to add a column with a List starting at BottomValue ending with TopValue, with a +1 increment. According to Microsoft the syntax is:
List.Generate(initial as function, condition as function, next as function, optional selector as nullable function) as list

I started with:
Table.AddColumn(#"Renamed Columns1", "TheList", each List.Generate(() =>10, each _ <= 90, each _ + 1))
Works as a charm.

replacing the 10 with my BottomValue field still works
Table.AddColumn(#"Renamed Columns1", "TheList", each List.Generate(() => [BottomValue], each _ <= 90, each _ + 1))

But replacing the top value with the field, gives an error
Table.AddColumn(#"Renamed Columns1", "TheList", each List.Generate(() => [BottomValue], each _ <= [TopValue], each _ + 1))
The error is:
Expression.Error: We cannot apply field access to the type Number.
Details:
Value=10
Key=TopValue

What am I doing wrong?
Thanks,
Carl
 
I'd go for the simpler option:

Code:
Table.AddColumn(#"Renamed Columns1", "TheList", each {[BottomValue]..[TopValue]})
 
Back
Top