SOLVED

excel in windows 10.

%3CLINGO-SUB%20id%3D%22lingo-sub-2760942%22%20slang%3D%22en-US%22%3Eexcel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2760942%22%20slang%3D%22en-US%22%3E%3CP%3Ehow%20to%20create%20a%20button%20that%20sorts%20by%20one%20column%20and%20then%20assigns%20an%20order%20in%20another%20column%20from%20one%20to%2020.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2760942%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2761246%22%20slang%3D%22en-US%22%3ERE%3A%20excel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2761246%22%20slang%3D%22en-US%22%3EHi%2C%20What%20do%20you%20mean%20by%20'order%20from%201%20to%2020'%3F%20What%20is%201%2C%20what%20is%2030%3F%20Kind%20regards%20Hans%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2785652%22%20slang%3D%22en-US%22%3ERE%3A%20excel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2785652%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F150069%22%20target%3D%22_blank%22%3E%40Hans%20Le%20Roy%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eif%20you%20have%2020%20rows%20that%20have%20been%20sorted%20say%20by%20their%20%25%3C%2FP%3E%3CP%3Ethen%20in%20another%20column%20you%20need%20show%20the%20ranking%2Fposition%20from%201-20%3C%2FP%3E%3CP%3Ewhich%20would%20be%201-20%20if%20all%20%25%20were%20different%20but%20if%20for%20some%20reason%20some%20are%20the%20same%26nbsp%3B%3C%2FP%3E%3CP%3Eie%20the%20top%203%2C%26nbsp%3Bthen%20their%20ranking%20would%20be%201%20but%20the%20next%20position%20would%20be%204th%20and%20so%20on%20to%20the%20bottom%20if%20that%20makes%20sense.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2785766%22%20slang%3D%22en-US%22%3ERE%3A%20excel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2785766%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1158556%22%20target%3D%22_blank%22%3E%40Bazz02%3C%2FA%3E%26nbsp%3BDepending%20on%20your%20needs%20and%20below%20assuming%20Excel%20365%2C%20it%20can%20be%20done%20in%20multiple%20ways%20and%20without%20a%20macro-button.%3C%2FP%3E%3CP%3EHaving%20data%20in%20a%20(pyamas)%20table%20you%20can%20calculate%20the%20rank%20using%20a%20column%20formula%3CBR%20%2F%3E%3CSTRONG%3E%3DXMATCH(%5B%40Value%5D%3BSORT(%5BValue%5D))%3C%2FSTRONG%3E%3CBR%20%2F%3E...finding%20the%20value%20on%20the%20same%20row%20(%3CEM%3E%40%3C%2FEM%3E%20%3D%20single%20cell%20intersection)%20among%20all%20values%20sorted%2C%20and%20returning%20the%20number%20of%20the%20first%20match.%3C%2FP%3E%3CP%3EYou%20may%20sort%20that%20column%20using%20the%20arrow%20in%20cell%20C2%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bosinander_1-1632644570687.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F312938iBECA2BC36070EF4F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bosinander_1-1632644570687.png%22%20alt%3D%22bosinander_1-1632644570687.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20it%20is%20an%20interesting%20education%20example%20I%20added%20some%20more%20solutions%20outside%20the%20table%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECell%20E3%20sorts%20the%20table%20each%20time%20data%20changes.%20It%20is%20a%20formula%20in%20only%20one%20cell%20but%20it%20'spills'%20the%20result%20to%20as%20many%20cells%20that%20are%20needed.%3C%2FP%3E%3CP%3E%3DSORT(Table1%5B%5BText%5D%3A%5BValue%5D%5D%3B2)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EG3%20isolates%20the%20percentages%20in%20F3%3AF8%20by%20addressing%20E3%23%20(includes%20the%20full%20spill%20area)%20and%20intersects%20it%20with%20column%20F%20using%20the%20multiple%20cell%20intersection%20character%20%3CEM%3Espace%3C%2FEM%3E.%3CBR%20%2F%3E%3DXMATCH(E3%23%20F%3AF%3BE3%23%20F%3AF)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20need%20to%20redesign%20the%20layout%2C%20it%20may%20be%20more%20handy%20to%20not%20include%20a%20column%20reference%20and%20then%20INDEX%20is%20a%20solution%20where%20row%20number%20zero%20returns%20all%20the%20rows%20and%20the%20two%20tells%20the%20second%20col.%3CBR%20%2F%3E%3DXMATCH(INDEX(E3%23%3B0%3B2)%3BINDEX(E3%23%3B0%3B2))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELET%20is%20yet%20a%20rather%20new%20possibility%20to%20build%20a%20complex%20formula%20step%20by%20step.%20Use%20alt%2BReturn%20for%20line%20breaks.%3CBR%20%2F%3EThe%20last%20row%2Fparameter%20is%20what%20is%20shown%20as%20the%20output%20of%20the%20calculation.%3CBR%20%2F%3E%3DLET(range%3BTable1%5BValue%5D%3B%3CBR%20%2F%3Edata%3BSORT(range)%3B%3CBR%20%2F%3Eoutput%3BXMATCH(data%3Bdata)%3B%3CBR%20%2F%3Eoutput%3CBR%20%2F%3E)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2785815%22%20slang%3D%22en-US%22%3ERE%3A%20excel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2785815%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3E%3CBR%20%2F%3EDid%20you%20try%20the%20RANK%20function%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Frank-function-6a2fc49d-1831-4a03-9d8c-c279cf99f723%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Frank-function-6a2fc49d-1831-4a03-9d8c-c279cf99f723%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EKind%20regards%3CBR%20%2F%3E%3CBR%20%2F%3EHans%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2785839%22%20slang%3D%22en-US%22%3ERe%3A%20excel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2785839%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1158556%22%20target%3D%22_blank%22%3E%40Bazz02%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFollowing%20up%20some%20of%20the%20ideas%20already%20presented%2C%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20162px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F312944i08FDC377969A7B0E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eis%20returned%20by%20the%20formula%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20%20ranking%2C%20RANK(Table1%5BValue%5D%2CTable1%5BValue%5D%2C-1)%2C%0A%20%20%20%20output%2C%20%20IF(%7B0%2C1%7D%2C%20Table1%5BText%5D%2C%20ranking)%2C%0A%20%20%20%20SORT(output)%0A%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20ranking%20is%20placed%20first%20because%2C%20for%20some%20mysterious%20reason%2C%20RANK%20requires%20range%20references%20and%20not%20arrays.%26nbsp%3B%20The%20next%20row%20is%20a%20device%20to%20combine%20the%20newly%20calculated%20rankings%20with%20the%20text%20column%20before%20it%20is%20sorted%20by%20rank.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2785937%22%20slang%3D%22en-US%22%3ERe%3A%20excel%20in%20windows%2010.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2785937%22%20slang%3D%22en-US%22%3E%3CP%3EI%20see%20that%20%3CSTRIKE%3Eabsolute%20references%3C%2FSTRIKE%3E%20%3CSTRONG%3Estatic%20arrays%3C%2FSTRONG%3E%20comes%20more%20and%20more%20handy.%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20CHOOSE%20allows%20to%20combine%20multiple%20dynamic%20arrays.%3C%2FP%3E%3CP%3E%3DSORT(CHOOSE(%7B3%5C1%5C2%7D%3B%20Table1%5BText%5D%3B%20Table1%5BValue%5D%3B%20Table1%5BRank%5D))%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bosinander_1-1632653909790.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F312951iCC020B4B879089CA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bosinander_1-1632653909790.png%22%20alt%3D%22bosinander_1-1632653909790.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EAlso%20noted%20that%20RANK%20is%20around%20for%20backwards%20compatibility.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bosinander_2-1632654347075.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F312952i9EC506753FB32CCD%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bosinander_2-1632654347075.png%22%20alt%3D%22bosinander_2-1632654347075.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

how to create a button that sorts by one column and then assigns an order in another column from one to 20.

 

14 Replies
best response confirmed by Bazz02 (New Contributor)
Solution
Hi, What do you mean by 'order from 1 to 20'? What is 1, what is 30? Kind regards Hans

@Hans Le Roy 

 

if you have 20 rows that have been sorted say by their %

then in another column you need show the ranking/position from 1-20

which would be 1-20 if all % were different but if for some reason some are the same 

ie the top 3, then their ranking would be 1 but the next position would be 4th and so on to the bottom if that makes sense. 

@Bazz02 Depending on your needs and below assuming Excel 365, it can be done in multiple ways and without a macro-button.

Having data in a (pyamas) table you can calculate the rank using a column formula
=XMATCH([@Value];SORT([Value]))
...finding the value on the same row (@ = single cell intersection) among all values sorted, and returning the number of the first match.

You may sort that column using the arrow in cell C2

bosinander_1-1632644570687.png

 

Since it is an interesting education example I added some more solutions outside the table;

 

Cell E3 sorts the table each time data changes. It is a formula in only one cell but it 'spills' the result to as many cells that are needed.

=SORT(Table1[[Text]:[Value]];2)

 

G3 isolates the percentages in F3:F8 by addressing E3# (includes the full spill area) and intersects it with column F using the multiple cell intersection character space.
=XMATCH(E3# F:F;E3# F:F)

 

If you need to redesign the layout, it may be more handy to not include a column reference and then INDEX is a solution where row number zero returns all the rows and the two tells the second col.
=XMATCH(INDEX(E3#;0;2);INDEX(E3#;0;2))

 

LET is yet a rather new possibility to build a complex formula step by step. Use alt+Return for line breaks.
The last row/parameter is what is shown as the output of the calculation.
=LET(range;Table1[Value];
data;SORT(range);
output;XMATCH(data;data);
output
)

@Bazz02 

Following up some of the ideas already presented,

image.png

is returned by the formula

= LET(
    ranking, RANK(Table1[Value],Table1[Value],-1),
    output,  IF({0,1}, Table1[Text], ranking),
    SORT(output)
  )

The ranking is placed first because, for some mysterious reason, RANK requires range references and not arrays.  The next row is a device to combine the newly calculated rankings with the text column before it is sorted by rank.  

I see that absolute references static arrays comes more and more handy. 

Using CHOOSE allows to combine multiple dynamic arrays.

=SORT(CHOOSE({3\1\2}; Table1[Text]; Table1[Value]; Table1[Rank]))

bosinander_1-1632653909790.png

Also noted that RANK is around for backwards compatibility.

bosinander_2-1632654347075.png

Agreed

All fixed , thank you

@Hans Le Roy 

I like Tables because of the way in which they adjust to the actual data (as well as providing structured references) so that Excel is not left to infer what is intended by the user; it is explicit.

@Peter Bartholomew 

[x] Like Tables
I do though stress, during classes, that when you work with column formulas you enter it...

bosinander_0-1632816505776.png

...and in one step gets the formula, a new column and the column filled with that formula.

bosinander_1-1632816548350.png

When undoing though, it demands three Ctrl+Z. One for each step.

bosinander_2-1632816562819.png

bosinander_3-1632816570196.png

bosinander_4-1632816577603.png

The risk is when making a less visible change and typing Ctrl+Z, it is very easy to not have undone the change as expected. In the rest of the envirnment it is normally one change and one undo.
The only hint is a tiny green corner telling that the cell deviates.

bosinander_5-1632816670472.png

I don't have any other suggestion for the interface - I'm confident that Microsoft have come up with the best solution among alternatives. Just notice that it is an area with a risk for unwanted results.

@bosinander 

It can be something of a pitfall.  As a 365 dynamic array user, I tend to expect consistency and follow Ray Panko (EuSpRIG papers) in treating any individually edited term as a Latent Error (i.e. one that may deliver the correct numbers now but with no assurance that it will continue to do so during the life of the spreadsheet).  I would prefer that all edits should propagate and there should be no option to change a single term, but that would cause howls of protest.  

It is not as if any other aspect of traditional spreadsheet development makes an attempt to be robust to change, so the Microsoft default is probably a good solution, though you are correct to warn against the risk. 

Working my way, I would have

= IF([@precision]="high", 
     PI(), 
     355/113)

which, I agree, is somewhat cumbersome.

@bosinander 

IMHO, that's always the risk to use the tool by the way it's not designed for. Structured table assumes same formula for entire column and keeps it as default formula for the column in background. 

Definately prefer structured tables
When it comes to calculated columns it may be a safer approach to simply delete the column and make a new one. Ctrl+Space and Ctrl+- (minus) and possibly Ctrl++ comes handy.
Microsoft has surely thought about it, but it would be appreciated by some of us to have a setting for calculated columns like
[x] All edits propagate