Forum Discussion
ctrip77
7 years agoFrequent Visitor
List.generate syntax error
Hi, I have a table with 4 columns Date_start, Date_End, Interval. I add a custom column with the following code: List.Generate( () => [ a = [Date_Start], b = [Date_End] ], each [a] <= [b], each [...
ImkeF
Community Champion
7 years agoapart from a capitalisation issue, that code is already correct (M is case sensitive):
Table.AddColumn(#"Changed Type", "Custom", each if [interval] = 2 then (x) => List.Generate( () => [ a = x[Date_Start], b = x[Date_End] ], each [a] <= [b], each [ a = Date.AddMonths( [a], x[Interval] ), b = [b] ], each [a] ) else (x) => List.Generate( () => [ a = x[Date_Start], b = x[Date_End] ], each [a] <= [b], each [ a = Date.AddYears( [a], x[Interval] ), b = [b] ], each [a] ) )
ctrip77
7 years agoFrequent Visitor
thanks for your reply ImkeF !
After change the IF to lowercase, Now instead having the text "list" on the column I see "function" and if I click on the cell, in the bottom pane (where before appear the expanded list) now is showing "function (x as any) as any
I think Im missing something but cant find it!
thanks in advance!
- ImkeF7 years ago
Community Champion
Oh yes, my bad:
Table.AddColumn(#"Changed Type", "Custom", (x) => if x[interval] = 2 then List.Generate( () => [ a = x[Date_Start], b = x[Date_End] ], each [a] <= [b], each [ a = Date.AddMonths( [a], x[Interval] ), b = [b] ], each [a] ) else List.Generate( () => [ a = x[Date_Start], b = x[Date_End] ], each [a] <= [b], each [ a = Date.AddYears( [a], x[Interval] ), b = [b] ], each [a] ) )