return top 3 entries

blue333

Board Regular
Joined
Mar 19, 2009
Messages
64
Hi

I cannot post any attachments so I cannot share the sample data I made. I copied it below. The formatting is off. Hopefully you can still understand the sample.

I have a job matrix that shows staff movement. The table is read as follows. There were 22 people from job B that moved into job A. There were 3 people in job C that moved into job A. The percentage is based on the to job. I need to know the top three "FROM JOBS" that moved into each "TO JOB". This is shown in the expected outcome. In addition to the job, I also need to know the corresponding %.

Any ideas on how to do this?

Thanks in advance!

SOURCE DATA
STAFF MOVEMENT COUNTSSTAFF MOVEMENT PERCENTAGE OF "TO JOB"
FROM JOB
FROM JOB
ABCDETOTALABCDETOTAL
TO JOB
A
122301945TO JOB
A
2%
49%7%0%42%100%
B0079319B
0%0%37%47%16%100%
C3320715C20%20%13%0%47%100%
D21173546D4%2%2%15%76%100%
E120003E33%67%0%0%0%100%
EXPECTED OUTCOME
TOP THREE IN TERMS OF JOBTOP THREE IN TERMS OF %
TOP 3 FROM JOB
TOP 3 FROM JOB
TO JOB
ABECTO JOB
A49%42%7%
B
DCEB
47%37%16%
CEABC47%20%20%
DEDAD76%15%4%
EBAE67%33%

<tbody>
</tbody>
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I think this is close to what you require. The intervening table RANK ORDER is necessary because I couldn't figure out how to create the necessary array.

Copy the formulas down and across as necessary.


Book1
ABCDEFGHIJKLMNO
1STAFF MOVEMENT COUNTSSTAFF MOVEMENT PERCENTAGE OF "TO JOB"
2FROM JOBFROM JOB
3TO JOBABCDETOTALTO JOBABCDETOTAL
4A122301945A2%49%7%0%42%100%
5B0079319B0%0%37%47%16%100%
6C3320715C20%20%13%0%47%100%
7D21173546D4%2%2%15%76%100%
8E120003E33%67%0%0%0%100%
9
10RANK ORDER IN TERMS OF JOB
1112345
12To/FromABCDE
13A2219310
14B97300
15C73320
16D357211
17E21000
18
19TOP 3 THREE IN TERMS OF JOB
20top3TOP 3 THREE IN TERMS OF %
21To/FromABCDETo/FromABCDE
22aBECA49%42%7%
23bDCEB47%37%16%
24cEABC47%20%20%
25dEDAD76%15%4%
26eBAE67%33%
Sheet74
Cell Formulas
RangeFormula
G4=SUM(B4:F4)
O4=SUM(J4:N4)
A19="TOP "&B20&" THREE IN TERMS OF JOB"
I20="TOP "&B20&" THREE IN TERMS OF %"
J22=IF(B22="","",INDEX($J4:$N4,MATCH(B22,$J$3:$N$3,0)))
B22{=IF(COLUMNS($B22:B22)>COUNTIFS($B4:$F4,">="&LARGE($B4:$F4,MIN($B$20,COUNTIFS($B4:$F4,">"&0)))),"",INDEX($B$3:$F$3,AGGREGATE(15,6,(COLUMN($B4:$F4)-COLUMN($B$3)+1)/($B4:$F4=B13),COUNTIF($B13:B13,B13))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
Job=Sheet42!$A$2:$A$6
 
Last edited:
Upvote 0
Forget that WOORKBOOK DEFINED RANGE NAME...I don't know what it's doin' there. Also, remove the word THREE from those two formulas.
 
Upvote 0
Forget that WOORKBOOK DEFINED RANGE NAME...I don't know what it's doin' there. Also, remove the word THREE from those two formulas.

thanks for the reply!

I am trying to automate as much of this calculation as possible. We have a data feed that provided the data. For the most part you calculation looks great. The part that confuses me is the rank order table. What are you trying to do with that? Can that be automated? I don't mind if its a separate table but it just needs to be done automatically.

thanks again!!
 
Upvote 0
The approach I have been using to calculate the top 3 is this formula

=LARGE($L9:$P9,COLUMNS($G20:G20))

$L9:$P9 contains the data that is being ranked.
$G20:G20 gives the rank needed (1st, 2nd, 3rd etc). This value increases as the formula is dragged across.

the problem with this approach is that if I want to change from top 3 to top 5 then I have to adjust my formulas by dragging them.

The data set I am working with is much larger than the one I have posted as a sample. I have close to 400 job titles I care about. Perhaps I need to look at top 10 or top 75. I have related tables that would also have to be re-adjusted. painful!

I like your approach alot. I just enter the number of top X i want and it gives it to me. That way i can setup the structure once and don't have to re-adjust each time for different scenarios. I just want to have to calculate the rank matrix each time. if that can be automated then that would be awesome!

thanks again for your help!!
 
Upvote 0
Well let's see if I can explain the mess I've made. The Order Table is needed as fodder for the K argument in function AGGREGATE, which by necessity is an expanding range ( itself achieved with function COUNTIFS). I can't seem to reckon a way to make an array out of it something inside function COUNTIFS.

Note that the headings in B12:F12 are essentially meaningless and they can be omitted.

The table just there because we need to order every single item of the source data to make the algorithm function.

So, I think it's what you call automatic. If you refer to this video, you'll see the challenge presented by your data. I had to do what he did, yet for every line item and as columns instead of rows. https://youtu.be/rKDI-kdBsjY
 
Last edited:
Upvote 0
Well let's see if I can explain the mess I've made. The Order Table is needed as fodder for the K argument in function AGGREGATE, which by necessity is an expanding range ( itself achieved with function COUNTIFS). I can't seem to reckon a way to make an array out of it something inside function COUNTIFS.

Note that the headings in B12:F12 are essentially meaningless and they can be omitted.

The table just there because we need to order every single item of the source data to make the algorithm function.

So, I think it's what you call automatic. If you refer to this video, you'll see the challenge presented by your data. I had to do what he did, yet for every line item and as columns instead of rows. https://youtu.be/rKDI-kdBsjY

thank you so very much!! The youtube video put into context what you were trying to do. I combined both your input and the youtube video to make it work. here is how i did with without any external rank table:

AGGREGATE(15,6,(COLUMN('To From (%)'!$B$5:$F$5)-COLUMN('To From (%)'!$B$5)+1)/('To From (%)'!$B5:$F5=B9),COUNTIF($B9:B9,B9)))

where B9 refers to the % table that was calculated earlier. the above formula is part of the calculation for returning the job titles.

you saved my life at work :)

have a great day!!
 
Last edited:
Upvote 0
Good show! We did it. I'm glad to help ensure you still have a job! Thanks for posting your solution for passersby who might have similar questions.
 
Upvote 0

Forum statistics

Threads
1,216,176
Messages
6,129,313
Members
449,500
Latest member
Jacky Son

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