Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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!
Solved! Go to Solution.
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.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingI was trying to lookup the Holiday name - IF it exists -- so, I fully expect it to not find anything most of the time. With Arielcchy's advise, I came up with this, which seems to be working:
#"Added IsHoliday" = Table.AddColumn(#"Added Is6weeksPlusMinus", "IsHoliday", each if (try DimHolidays[Holiday]{List.PositionOf(DimHolidays[Date], [Date])} otherwise "None") = "None" then "No" else "Yes", type text )
I use try catch/otherwise to catch error from List.PositionOf()
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.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingThis is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
9 | |
8 | |
6 | |
6 |