The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi,
I am new to Power Query. I have written the following custom function for a query which I am trying to get to work:
(gsf as list, ltf as list, percentchange as list, grouping as list) as list =>
let
GSF = List.Buffer(gsf),
LTF = List.Buffer(ltf),
PercentChange = List.Buffer(percentchange),
Grouping = List.Buffer(grouping),
GRTList = List.Generate
(
()=> [ GRT = 0, i = 0, j = 0 ],
each [i] < List.Count(GSF),
each if j = 0
then if GSF{[i]} <> 0
then [GRT = GSF{[i]}, i = [i] + 1, j = [j] + 1]
else [GRT = LTF{[i]}, i = [i] + 1, j = [j] + 1]
else if GSF{[i]} <> 0
then [GRT = GSF{[i]}, i = [i] + 1, j = [j] + 1]
else try if Grouping{[i]} = Grouping{[i] + 1}
then [GRT = [GRT] * PercentChange{[i] + 1}, i = [i] + 1, j = [j] + 1]
else [GRT = GSF{[i]+1}, i = [i] + 1, j = 0]
otherwise [i = [i] + 1, j = 0]
,
each [GRT]
)
in
GRTList
But, I get the following error:
An error occurred in the ‘’ query. Expression.Error: The name 'j' wasn't recognized. Make sure it's spelled correctly.
Thanks a lot for the help!
Pankaj
Solved! Go to Solution.
Hey,
I found the mistake.
I found out that I was missing [] around j in the following statement:
each if j = 0
Br
Pankaj
Hey,
I found the mistake.
I found out that I was missing [] around j in the following statement:
each if j = 0
Br
Pankaj