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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

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

Hi - I am using a Grouped Rows function to produce two columns: Total Fees and Total AUM. Total AUM works, but Total Fees does not. 

 

wowziewoo_0-1675853371547.png

 

I keep getting the error:

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

When I click the error, it takes me back to the Grouped Rows section of my code.

 

Below is my code. Any idea what I could be tripping up on? To my newb eyes, the set of code that creates Total AUM is the same in structure as the one that creates Total Fees, but clearly I'm overlooking something. Happy to post the entirety of the code if that helps (all the other rows). 

 

#"Grouped Rows" = Table.Group(#"Changed Type2", {"Value", "QtrEndDate"},{

//Create a column called Total AUM - this section of code works great
{"Total AUM", (t)=>
let
#"LeadAdvisor" = Table.SelectRows(t,each [Attribute] = "LeadAdvisor"),
#"LeadAdvisor AUM" = List.Sum(#"LeadAdvisor"[AUM]),
#"Remove LeadAdvisor Clients" = Table.SelectRows(t, each not List.Contains(#"LeadAdvisor"[Client],[Client])),
#"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Remove LeadAdvisor Clients",
{"Client", "AUM", "Attribute","QtrEndDate", "Value"}, "Attribute.1", "Value.1"),

//Match Sales to Sales%
#"Sales Attrib" = Table.TransformColumns(#"Unpivoted Columns1",{
//Looks like we are splitting off just down to the # in Sales1, Sales2, Sales3
{"Attribute", each Text.Split(_,"s"){1}},
{"Attribute.1", each Text.SplitAny(_,"s%"){1}}}),
AUMs = Table.SelectRows(#"Sales Attrib", each [Attribute] = [Attribute.1]),
#"Sales AUM" = List.Sum
(List.Generate(
()=>[f=AUMs[AUM]{0} * AUMs[Value.1]{0}, idx=0],
each [idx] < Table.RowCount(AUMs),
each [f=AUMs[AUM]{[idx]+1} * AUMs[Value.1]{[idx]+1}, idx=[idx]+1],
each [f]
))
in
#"LeadAdvisor AUM" + #"Sales AUM", Currency.Type
},


//Create a second column called Total Fees
{"Total Fees", (t)=>
let
//return a table where the Attribute = "Lead Advisor" - essentially filtering the table
#"LeadAdvisor2" = Table.SelectRows(t,each [Attribute] = "LeadAdvisor"),
//add up values from the newly-created table
#"LeadAdvisor Fees" = List.Sum(#"LeadAdvisor2"[Fees paid]),
//return a table where ????
#"Remove LeadAdvisor Clients2" = Table.SelectRows(t, each not List.Contains(#"LeadAdvisor2"[Client],[Client])),
#"Unpivoted Columns2" = Table.UnpivotOtherColumns(#"Remove LeadAdvisor Clients2",
{"Client", "Fees paid", "Attribute","QtrEndDate", "Value"}, "Attribute.2", "Value.2"),

//Match Sales to Sales% - below is the section that is causing the error, b/c when I remove it, I get incorrect values instead of errors
#"Sales Attrib2" = Table.TransformColumns(#"Unpivoted Columns2",{
//Splitting Sales1, Sales2, Sales3 into just numbers
{"Attribute.2", each Text.SplitAny(_,"s%"){1}}}),
//Return rows where Attribute (role) =???
Fees = Table.SelectRows(#"Sales Attrib2", each [Attribute] = [Attribute.2]),
#"Sales Fees" = List.Sum
(List.Generate(
()=>[f=Fees[Fees paid]{0} * Fees[Value.2]{0}, idx=0],
each [idx] < Table.RowCount(Fees),
each [f=Fees[Fees paid]{[idx]+1} * Fees[Value.2]{[idx]+1}, idx=[idx]+1],
each [f]
))
in
#"LeadAdvisor Fees"+ #"Sales Fees" , Currency.Type
}
})
in
#"Grouped Rows"

4 REPLIES 4
HotChilli
Super User
Super User

Not easy to debug this.

What it boiled down to is the number of words in "AUM" v "Fees paid".

This part:

{"Attribute.2", each Text.SplitAny(_,"s%"){1}}})

is going to split the column on charcters in "s%" and return the 2nd portion .

 This works fine for the "Sales1%" values but breaks because the first line in the mini-table has a value of "AUM" in attribute.2 so there's nothing for the {1} to refer to. So you get an enumeration error.

Now it looks like you don't need the AUM line in the stage at all so removing it might solve your problem.

 

May I suggest that you aid your debugging by having the code from the function in a separate query.  You can debug it step-by-step there.

Anonymous
Not applicable

Interesting, okay. I really appreciate you taking a look - I will play around with your suggestions and see if I can't figure it out. It helps knowing where I should be looking, so thank you!

Anonymous
Not applicable

See below. The basic gist of this is that each client has a LeadAdvisor, and they also can have a Sales1 person, a Sales2 person, and/or a Sales3 person. Sometimes a LeadAdvisor also shows up in a Sales spot. Each of those sales positions is assigned a percentage. 

 

If a Value is in the Lead Advisor spot, then we want to sum 1*AUM and 1*Fees Paid (so the full amount of each).

 

If a Value is in any of the Sales1,2,3 spots, and is not also LeadAdvisor then we want AUM and Fees times the respective Sales%, and we don't want to double count clients. 

 

But if a Value is in both LeadAdvisor and a Sales spot, they only get the 1*AUM and 1*Fees.

 

So if Kevin is both Lead and Sales2, he just gets 1*AUM and 1*Fees on that client, he does not also get Sales2%*AUM and Sales2*Fees. But if Kevin is only in a Sales spot for a client and not a Lead, then he only gets the %*Sales. 

 

Thank you! 

 

QtrEndDateClientAttribute AUM  Fees paid Sales1%Sales2%Sales3%Value
12/31/20220261C7E9-2579LeadAdvisor $         8,006,181 $      57,679100Eric
12/31/20220261C7E9-2579Sales1 $         8,006,181 $      57,679100Howard
12/31/202212579E87-46DASales1 $         3,497,261 $      17,1480.50.50Craig
12/31/2022257F23A2-ED44LeadAdvisor $              96,806 $            902100Jay
12/31/2022257F23A2-ED44Sales1 $              96,806 $            902100Jay
12/31/2022257F9CA9-444DLeadAdvisor $       32,601,966 $      113,3020.850.120.03Tim
12/31/2022257F9CA9-444DSales2 $       32,601,966 $      113,3020.850.120.03Tim
12/31/2022257F9CA9-444DSales3 $       32,601,966 $      113,3020.850.120.03Chris
12/31/202249EAAB00-257ELeadAdvisor $                       -   $               -  100Amanda
12/31/202249EAAB00-257ESales1 $                       -   $               -  100Amanda
12/31/202252325704-1372LeadAdvisor $            467,760 $         7,3280.750.250Amanda
12/31/202252325704-1372Sales1 $            467,760 $         7,3280.750.250Amanda
12/31/20225A782577-41E7LeadAdvisor $         1,862,783 $               -  0.250.50.25Mike
12/31/20225A782577-41E7Sales2 $         1,862,783 $               -  0.250.50.25Mike
12/31/20225A782577-41E7Sales3 $         1,862,783 $               -  0.250.50.25Gail
12/31/202284257562-FF46LeadAdvisor $         12,029,180 $      69,000100Ted
12/31/202284257562-FF46Sales1 $         12,029,180 $      69,000100Ted
12/31/2022B825795F-69B8LeadAdvisor $         1,388,739 $         9,719100Jay
12/31/2022B825795F-69B8Sales1 $         1,388,739 $         9,719100Jay
12/31/2022D257B373-76FBLeadAdvisor $            147,278 $         2,2560.750.250Amanda
12/31/2022D257B373-76FBSales1 $            147,278 $         2,2560.750.250Amanda
12/31/2022EB5DC257-7367LeadAdvisor $                       -   $              67100Craig
12/31/2022EB5DC257-7367Sales1 $                       -   $              67100Craig
12/31/2022F257EAB4-1387LeadAdvisor $            278,195 $         2,661100Grant
12/31/2022F257EAB4-1387Sales1 $            278,195 $         2,661100Grant
12/31/2022FE825739-847DLeadAdvisor $            877,339 $         6,9080.50.50Kevin
12/31/2022FE825739-847DSales1 $            877,339 $         6,9080.50.50Kevin
ams1
Responsive Resident
Responsive Resident

Hi,

 

Any chance you can give us some sample data for the #"Changed Type2" step so that I can easily run your code on my machine?

 

Ideally in a way that I can I can paste in Power Query, but a table screenshot will do also.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors
Top Kudoed Authors