Forum Discussion
EvertonRosa
5 years agoHelper I
Get next line from Related Table (Table.)
I need a little help to write a Power Query function in order to get the next line (id) from a related table. Actual code is: let data = Table.Column(dCalendarA, "Month/Year") in if [FiscalPeri...
- Anonymous5 years ago
Hi EvertonRosa
I don't see your original code working...based on my understanding, you have a table like the screenshot, another table called dCalendarA. While you fetch the dCalendarA.CloseDate, you are looking at Month/Year in both tables to match? I modified your code a little bit, let me know if you want something else
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjy0QElH6dACI0t9A0N9IwMjQyDXwBDEAMs4lpQm5ijF6oyqHLwqA4ryKzJz80lWawRTa6ZvYARXa4TFBdRTSYr9cLWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, DataFechamento = _t, #"Month/Year" = _t, FiscalPeriod = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"DataFechamento", type date}, {"Month/Year", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let data = Table.Column(dCalendarA, "Month/Year") in if [FiscalPeriod] = null then null else if [FiscalPeriod] = "Atual" then dCalendarA[CloseDate]{List.PositionOf(data, [#"Month/Year"])} else try dCalendarA[CloseDate]{List.PositionOf(data, [#"Month/Year"])+1} otherwise null) in #"Added Custom"
Anonymous
5 years agoNot applicable
Hi EvertonRosa
I don't see your original code working...based on my understanding, you have a table like the screenshot, another table called dCalendarA. While you fetch the dCalendarA.CloseDate, you are looking at Month/Year in both tables to match? I modified your code a little bit, let me know if you want something else
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjy0QElH6dACI0t9A0N9IwMjQyDXwBDEAMs4lpQm5ijF6oyqHLwqA4ryKzJz80lWawRTa6ZvYARXa4TFBdRTSYr9cLWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, DataFechamento = _t, #"Month/Year" = _t, FiscalPeriod = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"DataFechamento", type date}, {"Month/Year", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each
let data = Table.Column(dCalendarA, "Month/Year") in
if [FiscalPeriod] = null then null
else if [FiscalPeriod] = "Atual" then dCalendarA[CloseDate]{List.PositionOf(data, [#"Month/Year"])}
else try dCalendarA[CloseDate]{List.PositionOf(data, [#"Month/Year"])+1} otherwise null)
in
#"Added Custom"
EvertonRosa
5 years agoHelper I
It did work!!! Thanks a lot 😉