+ Reply to Thread
Results 1 to 7 of 7

Filter-sort formula results?

  1. #1
    Registered User
    Join Date
    06-06-2006
    Location
    English(UK)
    MS-Off Ver
    2019
    Posts
    93

    Filter-sort formula results?

    I have a large table of generated results.

    When I use the basic filter sorting doesn't work. Which is probably due to the relative nature of the formulas.

    See the attached workbook.

    Is there a way to make the sorting work?

    ...while also not making the workbook a nightmare to maintain?
    Because, when you make the cells absolute references sorting starts working again. But it makes the table a nightmare to change and maintain. I don't know of a way to bulk-change the references of a large area of cells(a regex replace function would be so handy here). But the fill function stops working then. And excel doesn't even have a "Find/replace in selection".
    Keep in mind that I CANNOT touch the source.
    Attached Files Attached Files

  2. #2
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Filter-sort formula results?

    Hi

    I do not know if this helps you but I try

    Use a helper column with the address of each cell of source and the copy of source is given by INDIRECT function

    Suppose your Source in F3:F6

    Use in A2:A5 the values {"F3","F4","F5","F6"}

    use in B2:B5 the formula =INDIRECT(A2) (drag down)

    Sort A2:B5 on column B to get the sorted source or on A to get the original source in B

    See the file for clarification
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-06-2006
    Location
    English(UK)
    MS-Off Ver
    2019
    Posts
    93

    Re: Filter-sort formula results?

    This breaks down if you move column A.

    But I have had an epiphany!

    Text below used for rubber-duck debugging.
    (Disclaimer: explanation somewhat mathy.)

    See, you have to have some absolute value somewhere in the table.
    That may be an absolute cell reference or a primitive value, it doesn't matter.

    The trick then, is to tie your formula to that absolute value.

    You see, even with relative references, excel DOES sort the table. Problem is, once sorted, the formulas update, and all that is relative returns to its old values(if you combine formulas with both you might get some really weird results and hard to track down bugs).

    The solution is simple once you realize what the problem is, and it involves a helper column you might want in your table anyway - an ordinal column(you might want it, because excel has no "turn off sort" functionality - once you sort a table, you can't go back, unless the original ordering is also a valid sort of your table).
    So you don't use relative references, you use OFFSET with ROW and COLUMN. This nets you at most 3 parameters(down to 1 in the ideal case) - a reference point to your source, and potentially translational offsets for your ROW/COLUMN(which you can avoid by having your reference point to the top left corner of the source).

    This makes it both extensible(you can copy the formula over and it will work without having to change it) and maintainable(if you need to change it, you only need to worry about at most 3 parameters, not 3000 cells you need to manually change).

    So... do I get a cookie for solving my own problem?
    Last edited by martix; 11-19-2018 at 10:46 AM.

  4. #4
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Filter-sort formula results?

    Hi

    I'm glad you solved your problem. I think your cake already got it.

    Note however that you are solving a problem that you had not placed.
    Quote Originally Posted by martix View Post
    I have a large table of generated results. ...
    Keep in mind that I CANNOT touch the source.


    Do not forget to mark the thread as solved.

    Regards

  5. #5
    Registered User
    Join Date
    06-06-2006
    Location
    English(UK)
    MS-Off Ver
    2019
    Posts
    93

    Re: Filter-sort formula results?

    Quote Originally Posted by José Augusto View Post
    Note however that you are solving a problem that you had not placed.
    Not sure what that's supposed to mean...
    I haven't touched the source data at all in what I described.

    You may have misunderstood the problem.
    We have 2 tables - table A with generated results we wanna filter, and another table B where the source data for table A lives.
    We take data from table B and do things with it, to make it presentable and put it in A. But we cannot modify B.

  6. #6
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Filter-sort formula results?

    Hi

    The solution I proposed uses the table 'A1:B5' and not individual columns or individual cells. You can change the table to where you want to be without any kind of problem, adjusting the references in case you opt for another sheet.

    When you sort, you must do this for the table and not for a column isolated from the other. You can see at post #2 where I say that

    Sort A2:B5 on column B to get the sorted source or ...

  7. #7
    Registered User
    Join Date
    06-06-2006
    Location
    English(UK)
    MS-Off Ver
    2019
    Posts
    93

    Re: Filter-sort formula results?

    Seriously, what are you talking about?
    What does this have to do with the statement I quoted in my last reply?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Filter using a formula to return results on different worksheet
    By johnmitch38 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-24-2018, 10:14 PM
  2. cant sort table differently without changing formula results
    By Tlarkin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-09-2018, 06:54 AM
  3. Replies: 5
    Last Post: 05-09-2017, 08:48 AM
  4. Formula to filter results from data
    By iantix in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 04-11-2017, 10:36 AM
  5. Sort array formula results in descending order
    By OLLY-7 in forum Excel General
    Replies: 8
    Last Post: 12-19-2016, 02:47 PM
  6. Replies: 3
    Last Post: 03-31-2010, 11:47 AM
  7. Replies: 2
    Last Post: 07-25-2006, 01:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1