Sunteți pe pagina 1din 4

11/3/12

Ho

to Sort Data in Reports Automaticall Using E cel Formulas

Home Subscribe ExcelUser Blog Insight for business users of Microsoft Excel

Ho to Sort Data in Reports Automaticall Using E cel Formulas


by Charley Kyd on October 10, 2009 Many Excel reports include tables that show sorted results. Usually, these tables were sorted manually in Excel, using the Data, Sort command. However, reports would be a lot easier to maintain and update if formulas (no macros) could sort the data automatically. There s a simple way to do this. But to make the method work reliably, you ve got to fix the behavior of the RANK function. This figure shows a partial solution, and illustrates the problem with RANK. Columns A, B, and G show actual data. Enter the following formulas for the cells shown, and copy the formulas down their columns as needed: C3: E3: H3: I3: =RANK(A3,$A$3:$A$6,0) =MATCH(G3,$C$3:$C$6,0) =INDEX($B$3:$B$6,E3) =INDEX($A$3:$A$6,E3)

Sorting Excel data with formulas without fixing the RANK function. The formulas in column C rank the sales values, where the largest value is ranked 1 and the smallest in the table is ranked 4. The easiest way to understand column E is with an example. Look at cell G6. This marks the fourth sorted row in the table at the right. Cell E6 tells us that the values for this row can be found in the second row of the table at its left. The other values in column E provide similar information. Columns H and I use the information in column E to return the appropriate values. The reason row 4 of the spreadsheet has #N/A values is because the RANK function assigns identical rankings to identical values. This is a problem because Coats and Pants have identical sales this month. So the
e celuser.com/blog/225/ho -to-sort-data-in-reports-automaticall -using-e cel-formulas.html 1/4

11/3/12

Ho

to Sort Data in Reports Automaticall Using E cel Formulas

RANK function assigns the same #1 ranking to both products in column C, and assigns no #2 rank value at all. Therefore, when the formula in cell E4 looks for a #2 ranking, it returns #N/A. This problem is easy to fix, however. Just insert a new column for an adjusted sales value and then rank those adjusted values. Here are the formulas for the cells shown: B3: =A3+0.000001*ROW() D3: =RANK(B3,$B$3:$B$6,0)

Sorting Excel data with formulas after fixing the RANK function. Column B adds a tiny amount to each Sales value, an amount based on the number of each row in the table. This forces each value in Sales2 to be unique, which forces the Rank values in column D to be unique. And this gives us our automatically sorted values in columns H:J. When you use this technique, be sure to estimate the maximum number of rows in your table when you choose the decimal fraction shown in the formula for cell B3. That is, if you re going to have hundreds of thousands of rows of data (which New Excel allows) make sure that you still have a small number when you multiply your decimal fraction by a row number of about one million. Tagged as: Excel reporting, INDEX function, MATCH function, RANK function, Sorting with formulas

{ 1 comment }

Jon Peltier October 11, 2009 at 5:52 am If you don t want tied items to switch places in the sorted list (that is, you want to keep Coats above Pants), adjust your formula in B3 to something like: =A3+0.0000001*(100000-ROW()) Previous post: Don t Let Bad Spreadsheet Design Hurt Your Career, Part 2 Next post: Excel Was NOT Originally Designed as a Personal Productivity Tool

e celuser.com/blog/225/ho -to-sort-data-in-reports-automaticall -using-e cel-formulas.html

2/4

11/3/12

Ho

to Sort Data in Reports Automaticall Using E cel Formulas

Main E celUser Site


ExcelUser Home Page Excel Catalog Excel Dashboards Excel Solutions Exploring Excel Using Business Tools

Categories
Select Categor

e celuser.com/blog/225/ho -to-sort-data-in-reports-automaticall -using-e cel-formulas.html

3/4

11/3/12

Ho

to Sort Data in Reports Automaticall Using E cel Formulas

Recent Comments
Mr. Hotel Finance on Introducing Excel s Three Types of Spreadsheet Databases Five Really Useful Excel Keyboard Shortcuts | EdTech Tools | Scoop.it on Five Really Useful Excel Keyboard Shortcuts Patrick M on Good Examples of Bad Charts: Chart Junk from a Surprising Source Charley Kyd on Why INDEX-MATCH Is Far Better Than VLOOKUP or HLOOKUP in Excel Pete_B on Why INDEX-MATCH Is Far Better Than VLOOKUP or HLOOKUP in Excel Get smart with the Thesis WordPress Theme from DIYthemes. WordPress Admin

e celuser.com/blog/225/ho -to-sort-data-in-reports-automaticall -using-e cel-formulas.html

4/4

S-ar putea să vă placă și