Trying to group 4 columns by percentage. Running out of memory!

Darkstar_

New Member
Joined
Nov 24, 2018
Messages
13
I'm hoping there is a much easier way of doing what I am doing.

Firstly, this dummy document should illustrate things.

We have our raw data (i've made the data by using another larger sheet and have about 7 queries in excel just to make it look like the first tab in the linked sheet).
I then want to average the results by area for a specific criteria.
For example, Green results are above 70, amber is between 50 and 69 and red is below 50.

I managed to do this but it's messy. I ended up creating nearly 10+ queries to achieve this. The second tab of the linked sheet is a rough outline of my endgame. I couldn't be bothered to do all the results for this dummy document, it took so much time. So I ended up only making Result 1. But I want all 5 results in this table.
When I do make it at work, my computer (works PC's aren't the best) grinds to a halt and throws up out of memory errors.

So to achieve something (I think) should be easy to do, I end up having nearly 30 queries going.
I end up duplicating queries, filter results between 70-100, duplicate, change it and repeat for all 5 results. I then finally merge them. I'm pretty sure there is an easier way of doing this, but currently the way I do it, seems to burn out our computers at work.
 
You should be able to edit in the formula bar or advanced editor.
Have you got View Formula Bar ticked?
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I do now. Although it still isn't clear for me, so apologies.

I assumed it would be more complex. For example

Result 1 - Greater than 80 = Green, Between 70 and 80= Amber, less than 70=Red
Result 2 - Greater than 90 = Green, Between 80 and 90= Amber, less than 80=Red
Result 3 - Greater than 85 = Green, Between 70 and 85= Amber, less than 70=Red
Result 4 - Greater than 90 = Green, Between 90 and 80= Amber, less than 80=Red

This is what I need, but I fear it is too complex for this to handle, hence why I've had to make multiple queries.
 
Upvote 0
I'm not sure where I've missed understanding what you are trying to achieve so I'll go through the steps in a bit more detail.
First, make a table in your Excel worksheet with the criteria for the different rankings, you don't have to define Amber as it is between Red and Green. Give the table a name, I've used criteriaTable.

It looks like this:
ResultRedGreen
Result 17080
Result 28090
Result 37085
Result 48090

<tbody>
</tbody>

You can change the values and refresh later if you want.

You've already created a table with the raw data. I've named it dataTable.

Now go to Power Query and create a blank query. Go to Advanced editor and paste the following over the statements that are already there:

let
Source = Excel.CurrentWorkbook(){[Name="criteriaTable"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Result", type text}, {"Red", type number}, {"Green", type number}})
in
#"Changed Type"

I've called this criteriaTable, you need to edit the name.

Make another blank query and paste this over the code that appears by default, I have simplified the code so the conditional format can be accessed by double clicking on the conditionalColumn step:

let
Source = Excel.CurrentWorkbook(){[Name="dataTable"]}[Content],
changedType = Table.TransformColumnTypes(Source,{{"Area", type text}}),
removedColumns = Table.RemoveColumns(changedType,{"Title"}),
unpivotOtherCols = Table.TransformColumnTypes(Table.UnpivotOtherColumns(removedColumns, {"Area"}, "Result", "Value"),{{"Value", type number}}),
mergedQueries = Table.NestedJoin(unpivotOtherCols,{"Result"},criteriaTable,{"Result"},"criteriaTable",JoinKind.LeftOuter),
expandedCriteriaTable = Table.ExpandTableColumn(mergedQueries, "criteriaTable", {"Red", "Green"}, {"Red", "Green"}),
conditionalColumn = Table.AddColumn(expandedCriteriaTable, "Ranked Group", each if [Value] >= [Green] then "Green" else if [Value] >= [Red] then "Amber" else if [Value] < [Red] then "Red" else null),
removedCriteria = Table.RemoveColumns(conditionalColumn,{"Red", "Green"}),
sortedResults = Table.Sort(removedCriteria,{{"Area", Order.Ascending}}),
#"Changed Type" = Table.TransformColumnTypes(sortedResults,{{"Ranked Group", type text}})
in
#"Changed Type"

Give the query a name and load it to the Data Model and close the editor.

Back in Excel create a Pivot table from the Data Model. You should get this if I have understood correctly what you are after:

Average of Value
Result 1Result 2Result 3Result 4
Row LabelsGreenAmberRedGreenAmberRedGreenAmberRedGreenAmberRed
Canada90.340.386.526.594.027.058.5
China89.875.433.795.084.637.392.777.835.395.485.541.1
Croatia58.062.055.595.022.0
France86.271.037.095.083.443.494.577.539.995.583.342.3
Germany24.796.034.035.782.010.5
Japan87.370.048.095.083.042.588.077.217.294.080.039.2
Russia91.076.337.196.186.042.490.375.232.796.288.045.5
United Kingdom19.042.058.059.0
United States79.034.0100.088.043.792.580.325.685.039.2

<colgroup><col style="mso-width-source:userset;mso-width-alt:4169;width:86pt" width="114"> <col style="mso-width-source:userset;mso-width-alt:1755; width:36pt" width="48" span="12"> </colgroup><tbody>
</tbody>
 
Upvote 0
I think I get it now, apologies.
Are you able to attach a workbook with the pivot table attached, so I can see how it all fits together?
 
Upvote 0
I'd love to. However attaching or inserting files seems to be a black art on this forum. I am restricted on Addins. I've tried a pm but cannot find an attach option?
P
 
Upvote 0
Black magic indeed. Every other forums seems to manage just fine, but anyways.
I think you have given me a lot to chew on, at work tomorrow I'm going to put what I've learnt here into practice to hopefully produce something useful for us.
Thanks again, if I have any other follow ups, I will post here.
 
Upvote 0

Forum statistics

Threads
1,215,267
Messages
6,123,964
Members
449,137
Latest member
yeti1016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top