Forum

Query Expression.Er...
 
Notifications
Clear all

Query Expression.Error

11 Posts
2 Users
0 Reactions
949 Views
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

I get the [Expression.Error] There weren't enough elements in the enumeration to complete the operation error.  However, it is not all the time; maybe 20-25% of the refresh all times.  I am not smart enough to figure out why.  Here is the querey; any "suggestions" would be welcomed:

let

    Source = Web.Page(Web.Contents("https://"I left this blank for the help forum")),

    #"Expanded Data" = Table.ExpandTableColumn(Source, "Data", {"R", "HR", "RBI", "SB", "SO", "Team", "AB", "1B", "2B", "3B", "HBP", "CS", "IBB", "UBB", "HAB", "SV", "IP", "BS", "H", "UBB2", "HP", "ER", "SPW", "RPW", "Ho0", "Q67", "Total"}, {"R", "HR", "RBI", "SB", "SO", "Team", "AB", "1B", "2B", "3B", "HBP", "CS", "IBB", "UBB", "HAB", "SV", "IP", "BS", "H", "UBB2", "HP", "ER", "SPW", "RPW", "Ho0", "Q67", "Total"}),

    #"Filtered Rows2" = Table.SelectRows(#"Expanded Data", each ([AB] <> null)),

    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows2",{"Caption", "Source", "ClassName", "Id"}),

    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Team", type text}, {"R", Int64.Type}, {"HR", Int64.Type}, {"RBI", Int64.Type}, {"SB", Int64.Type}, {"AB", Int64.Type}, {"1B", Int64.Type}, {"2B", Int64.Type}, {"3B", Int64.Type}, {"HBP", Int64.Type}, {"CS", Int64.Type}, {"IBB", Int64.Type}, {"UBB", Int64.Type}, {"HAB", Int64.Type}, {"SV", Int64.Type}, {"SO", Int64.Type}, {"IP", type number}, {"BS", Int64.Type}, {"H", Int64.Type}, {"UBB2", Int64.Type}, {"HP", Int64.Type}, {"ER", Int64.Type}, {"SPW", Int64.Type}, {"RPW", Int64.Type}, {"Ho0", Int64.Type}, {"Q67", Int64.Type}, {"Total", type number}}),

    #"Appended Query" = Table.Combine({#"Changed Type", CurrentPeriod}),

    #"Filled Up" = Table.FillUp(#"Appended Query",{"Through", "Half", "Week", "Dates", "Overall Week"}),

    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([Team] <> null)),

    Custom1 = Table.InsertRows(#"Filtered Rows", 2, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom2 = Table.InsertRows(#"Custom1", 5, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom3 = Table.InsertRows(#"Custom2", 8, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom4 = Table.InsertRows(#"Custom3", 11, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom5 = Table.InsertRows(#"Custom4", 14, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom6 = Table.InsertRows(#"Custom5", 17, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom7 = Table.InsertRows(#"Custom6", 20, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom8 = Table.InsertRows(#"Custom7", 23, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom9 = Table.InsertRows(#"Custom8", 26, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom10 = Table.InsertRows(#"Custom9", 29, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom11 = Table.InsertRows(#"Custom10", 32, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom12 = Table.InsertRows(#"Custom11", 35, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom13 = Table.InsertRows(#"Custom12", 38, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom14 = Table.InsertRows(#"Custom13", 41, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom15 = Table.InsertRows(#"Custom14", 44, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom16 = Table.InsertRows(#"Custom15", 47, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom17 = Table.InsertRows(#"Custom16", 50, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom18 = Table.InsertRows(#"Custom17", 53, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    Custom19 = Table.InsertRows(#"Custom18", 56, {[Team=null, R=null, HR=null, RBI=null, SB=null, AB=null, 1B=null, 2B=null, 3B=null, HBP=null, CS=null, IBB=null, UBB=null, HAB=null, SV=null, SO=null, IP=null, BS=null, H=null, UBB2=null, HP=null, ER=null, SPW=null, RPW=null, Ho0=null, Q67=null, Total=null, Through=null, Week=null, Half=null, Dates=null, Overall Week=null]}),

    #"Reordered Columns" = Table.ReorderColumns(Custom19,{"Team", "Total", "R", "HR", "RBI", "SB", "AB", "1B", "2B", "3B", "HBP", "CS", "IBB", "UBB", "HAB", "SV", "SO", "IP", "BS", "H", "UBB2", "HP", "ER", "SPW", "RPW", "Ho0", "Q67", "Through", "Half", "Week", "Overall Week"}),

    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Total", "H2H Score"}, {"UBB", "UBBH"}, {"UBB2", "UBBP"}}),

    #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns",{"Through"})

in

    #"Removed Columns1"

Please forgive me; I am not the best with this stuff.  You can tell because I have repeated steps to get a "blank" row every three rows after the first adjustment.  But, it works other than the occasional Expression.Error.  Thanks.  

 
Posted : 29/04/2022 8:26 am
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

Not entirely sure what you intend to do but that error occurs when you try to insert a row and the Offset element is larger than the number of rows in the current table.

In the picture below, I tried to insert a 6th row (i.e. number 5 in a zero base index) in a table that only has 4. In the previous step I successfully inserted the third row.

Screenshot-2022-04-28-170206.png

 
Posted : 29/04/2022 11:03 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

I know.  Hard to get the intention across.  And, I just am not that familiar with queries. The main thing with the rows, after row 2, I needed to insert a blank row every 3 rows until you see where it ends.  

 
Posted : 30/04/2022 7:00 am
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

You write "until you see where it ends". What do you mean by that? How big is your table?

But, perhaps the technique demonstrated in the attached file works for you. It splits the Source table into nested tables of three rows each into one single column. Then it inserts a row with errors at the beginning of each nested table. Once expanded, the errors are replaced by nulls resulting in empty rows. The last step is to remove the very first row.

 
Posted : 30/04/2022 7:19 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

Not that large; only 60 total rows.  

 
Posted : 30/04/2022 8:45 am
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

OK, please see my previous post. I believe it could work for you.

 
Posted : 30/04/2022 8:46 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

Attached is the actual query if you wanted to see the full "version."

 
Posted : 30/04/2022 9:03 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

File should be here this time.

 
Posted : 30/04/2022 9:05 am
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

Thanks! I'll get back to you later. On my way out now.

 
Posted : 30/04/2022 9:10 am
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

Inserted my code in your file and it seems to work fine. And it's all dynamic. If the web page contains 100 rows or perhaps only 50 rows next time, it will still work. Give it a try.

 
Posted : 30/04/2022 10:08 am
(@novusexcel)
Posts: 67
Estimable Member
Topic starter
 

This seems to work and I see where you are coming from.  It's not the rows I have, it's the rows of the source.  I need to take a longer look at your code as I am not familiar with that.  But, it really seemed to simplify my code a lot and I would like to do what I can to learn this.  Thank you.

 
Posted : 30/04/2022 10:49 am
Share: