Maintain position of value in UNIQUE function

ncbf87

New Member
Joined
Apr 17, 2017
Messages
9
Hi guys,

Hope you're well. I'd appreciate some guidance from the pros here.

I've a table of all employee's position title which I need to summarise into a table of unique position titles --> do a count --> and allow manual input in another column what is the required headcount of a position end of year. The challenge comes when a manager may change what a current position title is called, which will then refresh the UNIQUE formula, the sorting of values will differ, and this will mess up the manual input of headcounts

Example (screenshot attached):

Col D (Table 2) = line by line of all available positions in the company

Col F = UNIQUE(Table2[All Positions]))

Col G = COUNTIF(Table2[All Positions],F2#)

Col H = Manual Input

Column H is a data we want to track, maintain, and allow future changes. However, it needs to match the "unique position" line in column F.

If the position title in column D changes (rename, new row), column F will refresh with a change in order of the positions, which will make column H's input redundant.

Is there any alternative to approach this challenge, or a solution to fix the position of the position titles (maybe by having a unique ID for sorting purpose?)

Excel ver: Microsoft 365
 

Attachments

  • 35pzmus2pwj71.png
    35pzmus2pwj71.png
    36.8 KB · Views: 24

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
maybe by having a unique ID for sorting purpose?
That is the most sensible way. The unique ID would need to be added to the table on the left. Assuming that the ID is added to column E the formula would be something like.
Excel Formula:
=INDEX(SORT(UNIQUE(Table2[[All Positions]:[Unique ID]]),2),,1)
Which would sort on the order of the ID instead of the position. Note that it is still likely to mess up if you use a formula to generate the unique ID from the position name or if some, but not all instances of a position are changed, which will effectively create an additional position. If this happens, the order would remain but the new position would be inserted next to the original position with the same ID, shifting the rest down.
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Maintain position of value in UNIQUE function
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Thanks Fluff, sorry about the cross-posting and thanks for posting the link on behalf.

I've also attached the mini-sheet here for better reference.

Note that the top half of the minisheet shows the original data going out to the business. The business will then start their manual headcount input in the last column. Hence why sorting of the summarised position title must stay fixed.

However, the business user may also rename the position title in column B/C. If the title is existing, it's fine, the sorting won't change, and the manual input not affected. However, if the title is new (referring to the bottom half of the minisheet, position 777), it messes up the sorting by removing position 4, and appending position 777 before position B. The ideal sorting/outcome is showed in ell J18

Book1.xlsx
ABCDEFGHIJKL
1Current
2Original Position TitleManual Change to Position TitleFinal Position Title (to be summarised)Unique Positions (from Final Position Title)CountManual Input (FTE)
3Position21Position21Position115
4Position65Position65Position2113
5Position63Position63Position2212
6Position45Position45Position415
7Position58Position BPosition BPosition4511
8Position77Position77Position531
9Position22Position22Position631
10Position1Position1Position651
11Position53Position53Position771
12Position4Position4Position B1
13
14
15
16CurrentIDEAL
17Original Position TitleManual Change to Position TitleFinal Position Title (to be summarised)Unique Positions (from Final Position Title)CountManual Input (FTE)Unique Positions (from Final Position Title)CountManual Input (FTE)
18Position21Position21Position115Position115
19Position65Position65Position2113Position2113
20Position63Position63Position2212Position2212
21Position45Position45Position4515Position405
22Position58Position BPosition BPosition5311Position4511
23Position77Position77Position631Position531
24Position22Position22Position651Position631
25Position1Position1Position771Position651
26Position53Position53Position 7771Position771
27Position4Position 777Position 777Position B1Position B1
28Position 7771
29
30
31
32
33
34
35
36
37
38
39
40
Sheet1
Cell Formulas
RangeFormula
E3:E12E3=UNIQUE(SORTBY(Table2[Final Position Title (to be summarised)],REPT("Ω",Table2[Manual Change to Position Title]>0)&Table2[Final Position Title (to be summarised)]))
F3:F12F3=COUNTIF(Table2[Final Position Title (to be summarised)],E3#)
C3:C12,C18:C27C3=IF(B3="",A3,B3)
E18:E27E18=UNIQUE(SORTBY(Table22[Final Position Title (to be summarised)],REPT("Ω",Table22[Manual Change to Position Title]>0)&Table22[Final Position Title (to be summarised)]))
F18:F27F18=COUNTIF(Table22[Final Position Title (to be summarised)],E18#)
Dynamic array formulas.
 
Upvote 0
That is the most sensible way. The unique ID would need to be added to the table on the left. Assuming that the ID is added to column E the formula would be something like.
Excel Formula:
=INDEX(SORT(UNIQUE(Table2[[All Positions]:[Unique ID]]),2),,1)
Which would sort on the order of the ID instead of the position. Note that it is still likely to mess up if you use a formula to generate the unique ID from the position name or if some, but not all instances of a position are changed, which will effectively create an additional position. If this happens, the order would remain but the new position would be inserted next to the original position with the same ID, shifting the rest down.
Thanks jasonb75,
I've posted a minisheet showing the scenario and ideal outcome for better reference. Your solution unfortunately doesn't solve the issue, very likely I didn't explain myself well enough, sorry.
 
Upvote 0
Why has Position 58 been omitted from the ideal output instead of being shown with a zero count like Position 4? On the assumption that the omission was an error and that it should be included for consistency, this appears to work as needed.

Edit:- I went back to do a little more testing and immediately noticed that the sequence array doesn't stop as it should when there are duplicates in column B. I'll leave the original here for you to test and have a look at fixing the error shortly.

Book1
ABCDEFG
17Original Position TitleManual Change to Position TitleFinal Position Title (to be summarised)Unique Positions (from Final Position Title)CountManual Input (FTE)
18Position21Position21Position115
19Position65Position65Position2113
20Position63Position63Position2212
21Position45Position45Position405
22Position58Position BPosition BPosition4511
23Position77Position77Position531
24Position22Position22Position580
25Position1Position1Position631
26Position53Position53Position651
27Position4Position 777Position 777Position771
28Position 7771
29Position B1
Sheet1
Cell Formulas
RangeFormula
E18:E29E18=LET(o,UNIQUE(Table22[Original Position Title]),m,Table22[Manual Change to Position Title],IF(SEQUENCE(COUNTA(o,m))<=COUNTA(o),SORT(o),INDEX(SORT(m),SEQUENCE(COUNTA(o,m))-COUNTA(o))))
F18:F29F18=COUNTIF(Table22[Final Position Title (to be summarised)],E18#)
C18:C27C18=IF(B18="",A18,B18)
Dynamic array formulas.
 
Upvote 0
This works but it's a bit clunky, maybe somebody else can clean it up a little. Note that if there are no manual changes in column B then the dynamic arrays will return a blank row at the bottom of the results table. It would be possible to omit that but I've left it for now to reduce the length of the formula.
Book1
EFG
17Unique Positions (from Final Position Title)CountManual Input (FTE)
18Position115
19Position2113
20Position2212
21Position405
22Position4511
23Position531
24Position580
25Position631
26Position651
27Position771
28Position 7771
29Position B1
Sheet1
Cell Formulas
RangeFormula
E18:E29E18=LET(o,UNIQUE(Table22[Original Position Title]),m,UNIQUE(Table22[Manual Change to Position Title]),f,FILTER(m,m<>"",""),s,SEQUENCE(COUNTA(o,f)),IF(s<=COUNTA(o),SORT(o),INDEX(SORT(f),s-COUNTA(o))))
F18:F29F18=IF(E18#="","",COUNTIF(Table22[Final Position Title (to be summarised)],E18#))
Dynamic array formulas.
 
Upvote 0
This works but it's a bit clunky, maybe somebody else can clean it up a little. Note that if there are no manual changes in column B then the dynamic arrays will return a blank row at the bottom of the results table. It would be possible to omit that but I've left it for now to reduce the length of the formula.
Book1
EFG
17Unique Positions (from Final Position Title)CountManual Input (FTE)
18Position115
19Position2113
20Position2212
21Position405
22Position4511
23Position531
24Position580
25Position631
26Position651
27Position771
28Position 7771
29Position B1
Sheet1
Cell Formulas
RangeFormula
E18:E29E18=LET(o,UNIQUE(Table22[Original Position Title]),m,UNIQUE(Table22[Manual Change to Position Title]),f,FILTER(m,m<>"",""),s,SEQUENCE(COUNTA(o,f)),IF(s<=COUNTA(o),SORT(o),INDEX(SORT(f),s-COUNTA(o))))
F18:F29F18=IF(E18#="","",COUNTIF(Table22[Final Position Title (to be summarised)],E18#))
Dynamic array formulas.
Thanks jason75.

If only I can upload an attachment with the comments. Please see screenshot of comments (of the process) below on the upper half of the minisheet earlier. Your question is valid, but not an error.
Position58 was omitted because it happens when I'm prepping the file before going to the business. Another screenshot below showing the bottom half of the minisheet

Upper half:
1630233753813.png


Bottom half:
1630233875026.png


Unfortunately (correct me if I'm wrong), the formula doesn't work if the new position title is before the alphabet "B". For example, renaming a position to position A will sort it before position B. While renaming it to position C will sort it after position B.

Example below. I've renamed the title based on this order (position B was already there):
1. Position A
2. Position A1
3. Position C

Book1.xlsx
ABCDEFG
16Current
17Original Position TitleManual Change to Position TitleFinal Position Title (to be summarised)Unique Positions (from Final Position Title)CountManual Input (FTE)
18Position21Position21Position105
19Position65Position65Position2113
20Position63Position63Position2212
21Position45Position45Position405
22Position58Position BPosition BPosition4511
23Position77Position77Position530
24Position22Position22Position580
25Position1Position A1Position A1Position631
26Position53Position APosition APosition651
27Position4Position CPosition CPosition771
28Position A1
29Position A11
30Position B1
31Position C1
Sheet1 (2)
Cell Formulas
RangeFormula
E18:E31E18=LET(o,UNIQUE(Table225[Original Position Title]),m,UNIQUE(Table225[Manual Change to Position Title]),f,FILTER(m,m<>"",""),s,SEQUENCE(COUNTA(o,f)), IF(s<=COUNTA(o),SORT(o),INDEX(SORT(f),s-COUNTA(o))))
F18:F31F18=IF(E18#="","",COUNTIF(Table225[Final Position Title (to be summarised)],E18#))
C18:C27C18=IF(B18="",A18,B18)
Dynamic array formulas.
 
Upvote 0
That makes it clearer, what you are asking will not be possible with formulas in that exact format.

At best you could either have the output unsorted, or possibly sorted by the original list with the manual changes replacing the originals in the correct row (at present untested theory that may or may not work).

To get exactly as you are asking for would require two vba procedures, one for you to set up the initial sheet, another for the end user that will detect any subsequent changes and update the output accordingly. Naturally this has potential to fail if the user doesn't allow macros to run.
 
Upvote 0
That makes it clearer, what you are asking will not be possible with formulas in that exact format.

At best you could either have the output unsorted, or possibly sorted by the original list with the manual changes replacing the originals in the correct row (at present untested theory that may or may not work).

To get exactly as you are asking for would require two vba procedures, one for you to set up the initial sheet, another for the end user that will detect any subsequent changes and update the output accordingly. Naturally this has potential to fail if the user doesn't allow macros to run.
Thanks! To have confirmation that this cannot work is still progress. What about Power Query though?
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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