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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Gandhi
Regular Visitor

The index cannot be negative.

I have an problem (data doesn't flow). In Power Query there is 1 error table (or 2, but second one is because first).

Error is:
Expression.Error: The index cannot be negative.
Details:
Value=[List]
Index=-1


and when I go to Error, it is in step "fnGetHighestParent".

= (n as number) as number =>
let
PosOfParent = List.PositionOf( ListTeamID, n ),
ParID = ListParentID{PosOfParent}
in
if ParID = null then ListTeamID{PosOfParent} else @fnGetHighestParent(ListParentID{PosOfParent})

In Data View, there is no negative indexes. So I don't know what this error means. Does anyone has any ideas?

Thank in advance!
-G

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Gandhi 

 

List.PositionOf returns -1 if the value being searched cannot be found.  There is an optional argument in this function if this happens.  Please see this documentation: https://learn.microsoft.com/en-us/powerquery-m/list-positionof 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

1 REPLY 1
danextian
Super User
Super User

Hi @Gandhi 

 

List.PositionOf returns -1 if the value being searched cannot be found.  There is an optional argument in this function if this happens.  Please see this documentation: https://learn.microsoft.com/en-us/powerquery-m/list-positionof 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors