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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Seaweed81
Regular Visitor

Expression.Error: There weren't enough elements in the enumeration to complete the operation

I know this has been asked before however, none of the "solved" seems to fit.  I get this error when I refresh sometimes 20 times, sometimes just once and sometimes it works right away.  I guess my confusion is it will just eventaully work and sometimes on the 1st time.  Any idea what would cause this?  I'm new to this as most of this was built for me, and I'm trying to learn it, but this one has the best of me and is beyond frustrating.

10 REPLIES 10
ImkeF
Super User
Super User

This depends on what you're doing: Please copy the code from the advanced editor here to investigate.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

So forgive me, when I mentioned I was new, I'll show my ignorance.  What are you referring to specifically when you say code?  Is this the source that I'm linked to?

Hi @Seaweed81,

 

The code mentioned by ImkeF was the Power Query code. You can get it via clicking the Advanced Editor in Query editor mode.

1.PNG

 

What changes did you make after loading data into Power BI desktop? And whcih step caused above error? Was there any more detailed error message?

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

There were no changes made.  I technically created this, but am also somewhat new as well.  I am a bit more advanced in regards to the questions, however.

 

There were no changes made (outside of some transformations for cleanup, no pivots, etc).  We are connecting to a stats page.  There are multiple queries for different stats/scenarios.  The easiest way to get this to work with no fuss is to delete all relationships, refresh, then go back and connect the relationships.  But, this is getting cumbersome as we add more and more tables/queries.  The other thing important to mention is, it's never the same table that receives the error.  Based on all I have read about the error, it appears to have something to do with pivoted data that creates duplicates.  I will post the code, but on a different machine at the moment and is only in the .pbix file.

Here is the error message.

 

 

 

This is the information from the advanced editor:

 

let
Source = Web.Page(Web.Contents("http://www.fangraphs.com/leaders.aspx?pos=all&stats=bat&lg=all&qual=0&type=c,21,23,34,35,40,41,43,44...")),
Data11 = Source{11}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data11,{{"Header", type text}, {"#", Int64.Type}, {"Team", type text}, {"SB", Int64.Type}, {"AVG", type number}, {"BB%", Percentage.Type}, {"K%", Percentage.Type}, {"ISO", type number}, {"BABIP", type number}, {"LD%", Percentage.Type}, {"GB%", Percentage.Type}, {"FB%", Percentage.Type}, {"HR/FB", Percentage.Type}, {"wOBA", type number}, {"wRC+", Int64.Type}, {"Hard%", Percentage.Type}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Team", "SB", "AVG", "BB%", "K%", "ISO", "BABIP", "LD%", "GB%", "FB%", "HR/FB", "wOBA", "wRC+", "Hard%"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Versus", each "RH")
in
#"Added Custom"

There doesn't seem to be an issue with that query. Its showing perfect results on my machine:

 

PBI_ExpressionErrorShowingAlright.jpg

 

But this query doesn't have any pivot-operation. So maybe you've copied the code from the wrong query?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@ImkeF No, that was the right one.  That's the rub...it does work "a lot" of the time, but randomly decides to throw that enumeration error.  Is it possible the data source could cause an issue?  I just ask because I know that site is sometimes very slow in loading, so wondering if something on the server side could cause the issue?

 

If you're saying nothing is wrong with it, I believe that.  I have been telling @Seaweed81 that I felt the model was fine, it was an issue on the data side, though I didn't know how to verify this assumption...

I think I have the same issue, because I load the data from a database, and then do some editing steps in Query editor where I change column names etc.

 

And when the data is slow to load from the database it seems like it tries to jump over to renaming the columns (where there are none to rename because the data has not loaded), thus causing the expression error. Or that is at least my theory on it.

Yes, this could be a reason: If your source data don't come in, the subsequent queries will fail as well.

You can implement error-handling mechanisms with try ... otherwise.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.