SOLVED

Filtering out account codes based on other data

%3CLINGO-SUB%20id%3D%22lingo-sub-3065831%22%20slang%3D%22en-US%22%3EFiltering%20out%20account%20codes%20based%20on%20other%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3065831%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20my%20spreadsheet%20tab%201%20%22Codes%22%20shows%20a%20list%20of%20%22INT%22%20%26amp%3B%20%22MIN%22%20codes%20with%20their%20corresponding%20name%20for%20each%20item.%20Beside%20them%20I%20have%20ten%20columns%20for%20account%20codes%201-10.%20On%20tab%202%20%22Codes%20Used%22%20is%20a%20list%20I%20pulled%20from%20our%20database%20that%20shows%20each%20INT%20%26amp%3B%20MIN%20with%20a%20corresponding%20account%20code.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20am%20hoping%20to%20do%20is%20run%20a%20formula%20that%20will%20pull%20out%20the%20various%20account%20codes%20from%20tab%202%20and%20place%20them%20in%20the%20Account%201-%2010%20fields%20on%20tab%201.%20I%20am%20thinking%20some%20type%20of%20SUMIF%20formula%20may%20be%20needed%20but%20because%20there%20are%20so%20many%20variables%20on%20tab%202%20I%20am%20not%20sure%20how%20to%20proceed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20the%20caveat%20with%20all%20this%20is%20each%20INT%20%26amp%3B%20MIN%20code%20on%20tab%201%20should%20only%20have%204%20different%20possible%20account%20codes%20but%20because%20of%20how%20things%20were%20done%20in%20the%20past%20or%20errors%20made%20at%20certain%20times%20of%20the%20year%20it%20may%20have%20more%20or%20less.%20This%20is%20why%20I%20listed%20the%20account%20codes%20out%20to%2010%20but%20more%20could%20be%20added%20if%20necessary.%20My%20goal%20with%20this%20will%20be%20to%20eventually%20incorporate%20this%20data%20into%20another%20spreadsheet%20we%20use%20to%20error%20check%20ourselves.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3065831%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

In my spreadsheet tab 1 "Codes" shows a list of "INT" & "MIN" codes with their corresponding name for each item. Beside them I have ten columns for account codes 1-10. On tab 2 "Codes Used" is a list I pulled from our database that shows each INT & MIN with a corresponding account code. 

 

What I am hoping to do is run a formula that will pull out the various account codes from tab 2 and place them in the Account 1- 10 fields on tab 1. I am thinking some type of SUMIF formula may be needed but because there are so many variables on tab 2 I am not sure how to proceed.

 

Now the caveat with all this is each INT & MIN code on tab 1 should only have 4 different possible account codes but because of how things were done in the past or errors made at certain times of the year it may have more or less. This is why I listed the account codes out to 10 but more could be added if necessary. My goal with this will be to eventually incorporate this data into another spreadsheet we use to error check ourselves.

13 Replies
best response confirmed by kerry590 (Occasional Contributor)
Solution

@kerry590  here is the formula and fill down:

=TRANSPOSE(UNIQUE(FILTER('Codes Used'!C:C,(A2='Codes Used'!A:A)*(B2='Codes Used'!B:B),"")))

see attached

Interesting, is the transpose function how you get it into the other fields without having a formula? I have never seen something like this before.

@mtarler 

I'd modify as

=IFERROR(
   UNIQUE(  TRANSPOSE(
   FILTER(
      'Codes Used'!C2:INDEX( 'Codes Used'!C:C, COUNTA('Codes Used'!C:C) ),
      ('Codes Used'!A2:INDEX( 'Codes Used'!A:A, COUNTA('Codes Used'!A:A) )= A2 ) *
     ('Codes Used'!B2:INDEX( 'Codes Used'!B:B, COUNTA('Codes Used'!B:B) )=B2) ) ),
    0),
 "no such")

that significantly improves the performance.

Hmm, I think the first way worked a little better. It looks like this formula is returning each instance of the account code. I only need to see which code is used on any given coding, not how many times it is used. See line 34 as an example.

@kerry590 

Oh, yes, took not updated file. It shall be 1 as parameter for UNIQUE

=IFERROR(
   UNIQUE(  TRANSPOSE(
   FILTER(
      'Codes Used'!C2:INDEX( 'Codes Used'!C:C, COUNTA('Codes Used'!C:C) ),
      ('Codes Used'!A2:INDEX( 'Codes Used'!A:A, COUNTA('Codes Used'!A:A) )= A2 ) *
     ('Codes Used'!B2:INDEX( 'Codes Used'!B:B, COUNTA('Codes Used'!B:B) )=B2) ) ),
    1),
 "no such")

@Sergei Baklan that is a good point but I would recommend going for formatting as a table:

=TRANSPOSE(UNIQUE(FILTER(Codes_Used[ACCOUNT],(A2=Codes_Used[INT])*(B2=Codes_Used[MIN]),"")))

That said I also notice you reversed the UNIQUE and TRANSPOSE functions in your version.  I'm not seeing why and wondering if there was a specific reasoning for that. 

@mtarler 

1) Yes, table is much better. However, Code Used are pulled from the database, I'm not sure which technique is used for that and is it worth compare to dynamic range. Plus, form performance point of view dynamic range are more preferable. At least that was before, perhaps it is improved in modern Excel.

2) Order of functions - nothing is behind. Just started with this variant, when had phone call and after return your post is appeared. Decided to post my one accenting on performance.

in response to how both Sergei's and my formula works is basically filtering the list for only rows that have both the INT and MIN values that are the same as the INT and MIN values on the corresponding line. The UNIQUE then filters out duplicates and the TRANSPOSE changes it from rows to columns.

@Sergei Baklan Ok here is another question maybe you can answer.  Is there a performance difference between your dynamic range:

A2:Index(....last cell...) 

and

OFFSET(A2,0,0,...number of rows...)

 

@mtarler 

In many cases yes. OFFSET() is so called volatile function Excel Volatile function | Exceljet which is recalculating on any change. 

That's VBA discussion, but applied to the formulas as well

image.png Excel performance - Tips for optimizing performance obstructions | Microsoft Docs

@Sergei Baklan 

Oh thx. I knew INDIRECT was volatile but forgot that OFFSET is also volatile.

 

sry about the multiple post/edit/post

I believe you need to correct the above formula to use a FIXED row 2 in each case as shown here:

=IFERROR(
  UNIQUE( TRANSPOSE(
    FILTER(
      'Codes Used'!$C$2:INDEX( 'Codes Used'!C:C, COUNTA('Codes Used'!C:C) ),
     ('Codes Used'!$A$2:INDEX( 'Codes Used'!A:A, COUNTA('Codes Used'!A:A) )= A2 ) *
     ('Codes Used'!$B$2:INDEX( 'Codes Used'!B:B, COUNTA('Codes Used'!B:B) )=B2) ) ),
  1),
 "no such")
you all are fine, I have no idea what you two are talking about but glad the question has sparked a convo between people who do. As it stands I am going to have to leave to formula as is I think. Trying to change it with so many lines is lagging the program. Plus it makes it easier to read with just the number i need to see and not the "no such" on every line.