Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
vasu1102
Frequent Visitor

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

1 ACCEPTED SOLUTION
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

View solution in original post

1 REPLY 1
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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors