Forum Discussion
Table.FirstN function doesn't seem to work properly for my case...
Hi,
Thanks for the workaround, it is indeed working with SelectRows. The logic has to be like this though in order to be like what was expected with FirstN/LastN :
#"Added JobStarted" = Table.AddColumn(Custom1, "JobStarted", each Table.Last(Table.SelectRows([Custom], each [Isuserpartofteama] = true))[Creationdate], type datetimezone),
#"Added JobEnded" = Table.AddColumn(#"Added JobStarted", "JobEnded", each Table.First(Table.SelectRows([Custom], each [Isuserpartofteama] = false))[Creationdate], type datetimezone),But it actually doesn't answer why it is not working with FirstN/LastN ? Indeed, why for instance "each Table.FirstN([Custom], each [Isuserpartofteama] = false)" returns empty tables for the 1st and 4th line ? I keep reading the documentation and it should work, what is wrong with it please ?
Regards,
Welcome to the wonderful world of contexts. Yes, they exist in Power Query too. You are nesting one "each" inside another "each" and Power Query gets confused as to which context to use.
Mitigate by using inline functions or variables ("let ... in ..." ) much like you would do in DAX.