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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
oslcmb
New Member

Expression.Error: The index cannot be negative.

I have been using this query for some time now, but suddenly it throws up the following error when I am trying to run it: 

 

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

 

It is a long time since I have made it, but I believe the relevant step was trying to change a column name if that column name existed in the dataset: 

 

= Table.RenameColumns(Custom1,{{Table.ColumnNames( #"Promoted Headers"){List.PositionOf(List.Transform(Table.ColumnNames( #"Promoted Headers"),each Text.Contains(_,"Record ID")),true)}, "Main Record ID"},{Table.ColumnNames( #"Promoted Headers"){List.PositionOf(List.Transform(Table.ColumnNames( #"Promoted Headers"),each Text.Contains(_,"Associated Contact")),true)}, "New Associated Contact"},{Table.ColumnNames( #"Promoted Headers"){List.PositionOf(List.Transform(Table.ColumnNames( #"Promoted Headers"),each Text.Contains(_,"Associated Company ID")),true)}, "New Associated Company ID"} })

 

 

Any help would be appreciated. I have tried fixing it myself, but have limited PQ knowledge. 

 

Thanks!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

List.PositionOf() returns -1 if the thing you are looking for isn't found. So either Record ID, Associated Contact or Associated Company ID isn't being found.

 

Note that Power Query is case sensitive, so you might have "RECORD ID" or "record ID" or "Record Id" and that doesn't count if you are searching for "Record ID"

If case sensitivity is the issue, then change your Text.Contains() functions to:

Text.Contains(Text.Lower(_), "record id")

 

That will convert whatever is coming in to lower case and you compare against that.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

2 REPLIES 2
Arielcchy
Advocate II
Advocate II

I use try catch/otherwise to catch error from List.PositionOf()

edhans
Super User
Super User

List.PositionOf() returns -1 if the thing you are looking for isn't found. So either Record ID, Associated Contact or Associated Company ID isn't being found.

 

Note that Power Query is case sensitive, so you might have "RECORD ID" or "record ID" or "Record Id" and that doesn't count if you are searching for "Record ID"

If case sensitivity is the issue, then change your Text.Contains() functions to:

Text.Contains(Text.Lower(_), "record id")

 

That will convert whatever is coming in to lower case and you compare against that.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors