Forum Discussion

vasu1102's avatar
vasu1102
Frequent Visitor
4 years ago
Solved

Why am I getting 'An error occurred in the ‘’ query. Expression.Error: The name wasn't recognized'?

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

  • Hey,

    I found the mistake.

    I found out that I was missing [] around j in the following statement:

    each if j = 0

     

    Br

    Pankaj

1 Reply

  • vasu1102's avatar
    vasu1102
    Frequent Visitor

    Hey,

    I found the mistake.

    I found out that I was missing [] around j in the following statement:

    each if j = 0

     

    Br

    Pankaj