Automation of Subtotal range picking - excel

For my internship I am trying to do an analysis of travel patterns in public transport.
Due to privacy reasons I cannot share the file, but I may describe the columns.
This is how it works.
I have a spreadsheet in Excel (2007) and it is called ReizigersData. That contains 15,000 rows of checkins.
The columns are: stopname, stopID, problemStop, D, E, productname, workday, saturday, sunday.
stopID can be seen as a primary key.
As you'll understand, the stops are repeated in several rows, because many different productgroups travel from the same stop.
Using a Advanced filter I have filtered out 3 relevant productgroups, reducing it to approx 300 rows.
The other sheet in the file is called ReizigersData (bundled).
In this sheet I want to get the subtotals per stop, combining the numbers of the three productgroups, although separated by workday/saturday/sunday.
This sheet contains the following columns: stopname, stopID, workday, saturday, sunday.
I have used the following codes:
In ReizigersData (bundled) stopname:
=INDEX(ReizigersData!$A$3:$A$14326;MATCH(B3;ReizigersData!$B$3:$B$14326;0))
In ReizigersData (bundled) stopID:
=SUBTOTAL(109;'ReizigersData (2)'!G174:G205)
These codes work.
The problem though is that I entered that range by hand.
Since it is a big database, I would like the subtotal formula to automatically determine which range he should pick according to the stopID in the bundled sheet.
I have experimented a bit and came up with this formula:
=SUBTOTAL(109;(INDIRECT("'ReizigersData (2)'!G" & Match(B3;'ReizigersData (2)'!$B$3:$B$14326))):(INDIRECT("'ReizigersData (2)'!G" & Match(B3;'ReizigersData (2)'!$B$3:$B$14326))))
Unfortunately this does not work; it returns 0. In Formula evaluator, it looks that the reference in the match part is the issue, because it refers to row 2297, which is not the one it should be.
Has anyone got any idea how to reach my goal?

Related

How do I recieve the number of cells based off of three columns in Excel?

I'm not too sure how to word this problem so, I apologize for the vagueness. Here is what I am trying to do though:
I have a large Excel table with a ton of values, I however, only care about 3 columns. The three columns I have are "Project Name", "Active/Planned", and "Week of Month". Here is an example of some values I would have:
Project Name
Active/Planned
Week of Month
StoreProj
Active
2021-07 Jul-Wk1
SecProj
Planned
2021-07 Jul-Wk2
StoreProj
Active
2021-07 Jul-Wk1
Now, I have used a formula to get the number of projects based on a specific week month and avoiding duplicate values for the project name. The code I used returns an integer of the number of projects. Here is what I used:
=IFERROR(ROWS(UNIQUE(FILTER(Table[Project Name],Table[Week of Month]=2021-07 Jul-Wk1))), 0)
This works as intended. Now the issue I am running into is that I need to filter through these rows as I did previously, but now I need to include the "Active/Planned" column. So, I want to be able to see how many projects I have based off of the week of the month and return a number of projects (excluding duplicate names), but be able to filter through that integer output based off of the active/planned projects. So in a perfect scenario I can choose the week of month and if the project is "Active" or "Planned" and see the amount of projects I have.
This might be an easy fix so I apologize, I am just stumped, any help would be greatly appreciated. Thanks!
Work through that step by step, you've got the FILTER function which is giving data to the UNIQUE function, to the ROWS function, and then your IFERROR. However, the data about whether each line/row is 'Active' or 'planned' isn't passed out beyond the FILTER function, so can't be used by anything further on in the above sequence.
Boring theoretical advice out the way, try this;
=COUNT(IF(UNIQUE(FILTER( Table[[Project Name]:[Active/Planned]], Table[Week of Month] = "2021-07 Jul-wk1"))= "Active", 1))
Explanation:
FILTER(...) outputs records with the relevant date filter, however it outputs Table[[Project Name]:[Active/Planned]] - both columns, to ensure all relevant data is there.
UNIQUE(...) Then narrows that down to unique values, although by this stage I'm not 100% sure you need this.
IF(... = "Active", 1) then replaces the 'Active' outputs with 1s
COUNT() returns the number of cells in the above that contain a number (the 1s from the IF())
Yes, you can't use COUNTIF on arrays (and all except that last bullet point above are outputting arrays not single values) - and no, I didn't know that before attempting to answer this question, found it over at a different question!

What to use: COUNTIF or Vlookup or combined or else?

I got a big data file where I have to count how many events is per one serial number (in my case P/N) through more sheets (years). Those serials are in Column A (grey). On second picture is lookup table, so the data from where I have to search and Count events looking at (Column O - yellow) and Column A (artikel), using terms from Column P for all the sheets, I mean through different year. All sheets are consistent and looking exact the same.
What I tried to do is: COUNTIFS(A2:A142;VLOOKUP(A2;'Spareparts 2015'!$A$2:$O$164;15;FALSE))+COUNTIF('Spareparts 2015'!O2:O164;"Ersatz im Rahmen einer Wartung") to look for specific term but this is not what I wanted.
Idea is to get all these specific "terms" using P/N through all years (summed), to see how many times serial number (P/N) has been used through years. And I need total number (of 5 years). As you see in main table there are more serials, and everything what is needed is some good positioned function which I cant get...
Hopefully I was clear with my issue, it is a bit hard to explain, but I eager to provide more infos!
UPDATE!
This is actually what I wanted to accomplish (with Pivots is possible)
For every Serial (artikel) that I have in Calculated sheet, I wanna look and count all instances (Grund fur ersatz in Column O) through years and different sheets. Every sheet has mixed serials, and these occurrences, so I have to couple them with main table and to count total number of them, how many times something from Column O appeared in some of Serials through 5 years.
One option is using Pivot tables actually, but I wanted to know how I can solve it with formulas also.
EDIT #2
Given that the relationship between each serial number and the look up term is 'Many to Many' but not 'One to One', one way to count the occurrence of each term for each serial number is to
Firstly put all 5 years of data into one big table, and name the following ranges:
Name_All being names in Column O of the master data table;
SN_All being serial numbers in Column A of the master data table.
Secondly, create a look up sheet to list all serial numbers and associated look up terms as shown below:
Then you can use COUNTIFS to count the occurrence for each term per serial number:
=COUNTIFS(SN_All,A2,Name_All,B2)
See following screen-shot for more clarifications.
A better/quicker approach would be using pivot table as being mentioned by OP.

Excel - If + Index Match + Offset -- VBA or something else?

I made a dummy version (fake names and extremely shortened) of the 2 spreadsheets I'm working with this spread sheets
Background:
I'm automating the data between Contracts and our Accounting Team's template. Note that neither of these spreadsheet's formats can budge so that why I'm stuck. It's a clunky process that I am trying to automate. The main source of data is the "Contracts" tab. Let's say out of the 300 subcontractors projects, in the week of 1/24/2019 my coworker approved 130 of the projects. The logic of what I am trying to accomplish:
In the Contracts tab, if Column R is "Yes"--
In the "Accounting Template" tab (the one with formulas) Column B, pull all the cells of Contracts!A of the vendors we are set to pay.
The same applies to Template! (a nickname for the path) Column M, pull the specific contract ID's of the approved Contract ID's from Contracts!C.
Note I intentionally showed that my fake Puppies program is NOT approved to get their payment, this will help demonstrate how to resolve my issue
My key issue is that the Accounting Template skips every 3 rows for the Project, and the Contracts row has Project day every single row. So, for Template!A5, I am pulling data from Contracts!A2, and Template!A8 I am pulling data from Contracts!A3, etc.
I was able to (sort of) make this work with an offset, row and index match:
=OFFSET(INDEX(Contracts!$C$2:$C$167,MATCH(ROWS(Contracts!$A$2:A17),Contracts!$AB$2:$AB$167,0)),-10,0)
See that negative -10? For each new 3rd row I am starting at template, I'm manually changing it to -10, -12, -14, etc etc. Not exactly sophisticated.
Looking at how offset and row work, it looks as though they heavily rely on the coordinates of cells in the Contracts workbook. However, I ideally am looking to do this:
=IF(Contracts!R2="Yes",OFFSET(INDEX(Contracts!$C$2:$C$167,MATCH(ROWS(Contracts!$A$2:A5),Contracts!$AB$2:$AB$167,0)),-2,0))
However, once I throw a conditional (IF) in the mix, that reorientating the rows of my offset match. Are there better formulas for what I am trying to accomplish? A VBA script that could accomplish this IF, INDEX, MATCH, OFFSET, ROW dream of mine? I'm not married to either of these formulas.
I've perused a few VBAs but nothing seems to have a conditional like IF as a component.
EDIT:
Per a request, adding screenshots. There's also a Google Sheet link:
Contracts tab, purposely hiding irrelevant columns:
Accounting Template Tab:
I'd do it with VBA, but this formula example might help you start. If your issue is basically turning horizontal data into vertical data and you have a fixed interval of 3 rows. You will need to adapt the formulae for your actual set up.
The formulas used are:
F1 and down =IF(MOD(ROW()-1,3)=0,INDEX($A$1:$A$3,(ROW()+2)/3),"")
G1 and down =INDEX($B$1:$D$3,CEILING(ROW(),3)/3,1+MOD(ROWS($G$1:G1)-1,3))
I'm sure there are better ways ...

How do I calculate a Sum based on multiple If's in Excel?

Background is that I'm making a budget spreadsheet. I have different bills due on different days. (ie. bill due on Monday and bill due on the 10th)
I want a function that will place the appropriate amount of money going in/out in column D and the description of why the money is going in/out in column E.
Currently I have two different formulas that I created (probably incorrectly).
Formula for Column E: (Already is in the document and seems to work fine other than that fact that I cant add additional text to the cell)
=IF(DAY(C36)=7," Amy Pay","")&IF(DAY(C36)=22," Amy Pay","")&IF(DAY(C36)=8," Family Bills","")&IF(DAY(C36)=6," Dollar Shave Club","")&IF(DAY(C36)=2," Amy Cap One VISA","")&IF(DAY(C36)=3," Chase VISA","")&IF(DAY(C36)=8," Being Smart","")&IF(DAY(C36)=17," Gym","")&IF(DAY(C36)=11," Netflix","")&IF(DAY(C36)=19," Cap One MC","")&IF(DAY(C36)=29," CenturyLink","")&IF(DAY(C36)=6," Haley Cap One Visa","")&IF(DAY(C36)=10," SRP","")&IF(DAY(C36)=23, "Car Payment","")&IF(DAY(C36)=30, "Rent","")&IF((B36)="Mon"," Monday","")&IF((B36)="Fri"," Friday","")&IF((B36)="Fri"," Haley Pay","")
Formula for Column D: (not in the column yet, as it doesn't work how I want)
=IF(DAY(B40)=7,"1474.22","")&IF(DAY(B40)=22,"1474.22","")&IF(DAY(B40)=8,"-100","")&IF(DAY(B40)=6,"-9","")&IF(DAY(B40)=2,"-100","")&IF(DAY(B40)=3,"-100","")&IF(DAY(B40)=8,"-400","")&IF(DAY(B40)=17,"-20.05","")&IF(DAY(B40)=11,"-8.63","")&IF(DAY(B40)=19,"-450","")&IF(DAY(B40)=29,"-50","")&IF(DAY(B40)=6,"-150","")&IF(DAY(B40)=10,"-200","")&IF(DAY(B40)=23,"-325","")&IF(DAY(B40)=30,"-500","")&IF((A40)="Mon","-125","")&IF((A40)="Fri","-325","")&IF((A40)="Fri","400","")
http://imgur.com/IBINweh
      
The problem is that in column D, rather than providing a sum of the numbers, it lists the numbers in the column.
http://imgur.com/rPDS5h2
      
I had a suggestion to add =SUM( in front of the IF( function, but when I do, #VALUE! is what results in the field. Using this formula: (view image by changing appended text to /CVs0f1v )
=SUM(IF(DAY(B40)=7,"1474.22","")&IF(DAY(B40)=22,"1474.22","")&IF(DAY(B40)=8,"-100","")&IF(DAY(B40)=6,"-9","")&IF(DAY(B40)=2,"-100","")&IF(DAY(B40)=3,"-100","")&IF(DAY(B40)=8,"-400","")&IF(DAY(B40)=17,"-20.05","")&IF(DAY(B40)=11,"-8.63","")&IF(DAY(B40)=19,"-450","")&IF(DAY(B40)=29,"-50","")&IF(DAY(B40)=6,"-150","")&IF(DAY(B40)=10,"-200","")&IF(DAY(B40)=23,"-325","")&IF(DAY(B40)=30,"-500","")&IF((A40)="Mon","-125","")&IF((A40)="Fri","-325","")&IF((A40)="Fri","400",""))
Any ideas on how I can get all the to populate and sum appropriately?
Forgive my Non Excel Guru knowledge - trying to learn. :D
-Amy
If you take all of the options from your first working formula and change the method retrieving them, you will have a much more versatile worksheet that can easily accept new additions and schedule modifications.
    
In a couple of unused columns to the right, pit in the day-of-month and the action that occurs. I'm using columns Y & Z. You have two events occurring on the 6th so I put them together.
In a couple of other unused columns use the day-of-the-week and associated text.; I've used columns V & W. The default for Sunday is 1.
In E36 use this formula,      =TRIM(IFERROR(VLOOKUP(DAY(C36),$Y:$Z, 2, FALSE), "")&" "&IFERROR(VLOOKUP(WEEKDAY(C36),$V:$W, 2, FALSE), "")) 
Fill down as necessary.
If you want the day-of-the-week in column B, use =C36 and use a custom number format of ddd or dddd.
References:
  VLOOKUP function  WEEKDAY function
You are concatenating text strings that look like numbers. You probably want to be adding real numbers:
=SUM(IF(DAY(B40)=7,1474.22,0) + IF(DAY(B40)=22,0) + ...
although, whenever I see a formula as complex as what you have, I would consider looking for a different solution -- Vlookup comes to mind.
In addition, with a VLOOKUP table, you would have seen that you have some conflicts -- e.g: you list the same condition of B40=8 to return two different values; and the same condition of A40 = Fri, to also return two different values.

Grouping rows by area codes

I have a table of customers to which my company ships products. The problem is that these customers need to be sorted by their area codes, so that the products can be sent to the appropriate shipping companies (we have two partner companies that ship to certain parts of the country). Each company sent us a list of area code numbers to which they can ship and I need to divide the Excel sheet into two sheets, each containing the customers with the area codes compatible with the respective company.
I tried to solve this problem with VLOOKUP function, but it only works on individual row basis, and I need a solution that will find all rows that contain a number from the specified group of area codes.
Another way would be IF function that would put a True or False (one IF function for each company) value in new column and then I could sort by that value, and copy the data into a new sheet. This approach would work, but the IF function would be extremely long and hard to control.
Can you suggest a way to solve this problem?
Edit to incorporate details provided via Comment:
Presently I have about 5,000 rows but in future it might be more though I doubt over 10,000 rows.
A VLOOKUP seems very promising, of the kind =VLOOKUP($B2,F:G,1,0) in C2 copied across and down as required, with a layout as below:
This does not group as you say you require (but do you really need to?) because it seems possible some locations will be served by both shippers. You might resolve this by flagging those rows where both are viable and then by sorting to split into three groups (Shipper1 only, Shipper2 only, both) before transferring the ranges as desired.
Edit in response to OPs comment
If you can be certain there is no overlap between Shippers, a single column with this formula, say in E2copied down, might be preferable:
=IF(ISERROR(MATCH(B2,F:F,0)>0),"Shipper2","Shipper1")
and would not routinely show #N/A. (This assumes no area is outside the range of both shippers.)

Resources