Excel CountIf with Multiple Nested If Statements - excel

I have a table of Data in Excel on one tab that I have created a report for on another tab. The Report is a table filled with calculations which are fed from the data tab. Right now all results are shown for the week ending date I select. I am now trying to add code to the formula calculations that allows me to further progressively filter the table results.
For example From:
"All" Default Data for selected Week Ending
-->Filter by column F in data tab
--> Filter by column F & G, but if F is blank show all values in column F and filter only on G
--> Filter by column F, G and H, but if F or G is blank filter only on column G- and for any combination of blanks and selected values there should be.
I have the extra filters set up as drop down selections from the data validation tab and the lists are all in a 3rd tab away from the report and master data. I have 8 columns right now that I am trying to be able to filter on in any combination.
This is an example of the code I started with for the filter:
(1) =IF($Q$4="",COUNTIFS(Master!A:A,B$2),COUNTIFS(Master!$A:$A,B$2,Master!B:B,$Q$4))
(2)=IF($Q$5="",COUNTIFS(Master!$A:$A,B$2),COUNTIFS(Master!$A:$A,B$2,Master!C:C,$Q$5))
Breakdown of Formula 1 (same concept for the remaining):
Q4 refers to the cell that the dropdown list resides for this particular filter
Master!A:A is the master data file
B2 is the Date being searched for in the Master Data
Master!B:B is the column to be filtered by the Q4 selection
So far when trying to combine two or more of the Q selections (there are several, Q4,Q5,Q6,Q7,Q8,Q9,Q10,Q11 which filters columns B:B,C:C,D:D,E:E and so on in the master data. I need the table formulas to be able to handle receiving input from the dropdown and progressively filter down the data for each selection, or allow all data from that column (not already filtered out) to pass through to the next criteria.
So far when I try to combine the Q dropdown formulas I end up with a value of 0, since even if I have a
countifs(if(OR(Q2="", Q3="") followed by the filter criteria
if one of the filters is not selected, the formula drops the total value to "0" when it gets to the blank in the Q criteria.
Someone please help! Is there another way to do this? I feel like I am so close and am just missing something small.
TIA,
Jesse

So something like this:
=COUNTIFS(Master!$A:$A,B$2,Master!B:B,IF($Q$4<>"",$Q$4,"*"),Master!c:C,IF($Q$5<>"",$Q$5,"*"),...)

Related

Condensing nested if-statements with multiple criteria

The blue columns is the data given and the red columns is what is being calculated. Then the table to the right is what I am referencing. So, F2 will be calculated by the following steps:
Look at the Machinery column (D), if the cell contains LF, select column K, otherwise select column L
Look at the Grade column (E), if the cell contains RG, select rows 4:8, otherwise select rows 9:12.
Look at the Species column (A), if the cell contains MS, select rows 5 and 10, otherwise.......
Where every the most selected cell is in columns K and L, copy into column F.
Multiply column F by column C.
I don't want to make another column for my final result. I did in the picture to show the two steps separately. So column F should be the final answer (F2 = 107.33). The reference table can be formatted differently as well.
At first, I tried using nested-if statements, but realized that I would have like 20+ if statements for all the different outcomes. I think I would want to use the SEARCH function to find weather of not the cell contains a specific piece of information. Then I would probably use some sort of combination of match, if, v-lookup, index, search, but I am not sure how to condense these.
Any suggestion?
SUMPRODUCT is the function you need. I quickly created some test data on the lines of what you shared like this:
Then I entered the below formula in cell F2
=SUMPRODUCT(($I$4:$I$9=E2)*($J$4:$J$9=LEFT(A2,FIND(" ",A2)-1))*IF(ISERROR(FIND("LF",D2,1)),$L$4:$L$9,$K$4:$K$9))
The formula may look a little scary but is indeed very simple as each sub formula checks for a condition that you would want to evaluate. So, for example,
($I$4:$I$9=E2)
is looking for rows that match GRADE of the current row in range $I$4:$I$9 and so on. The * ensures that the arrays thus returned are multiplied and only the value where all conditions are true remains.
Since some of your conditions require looking for partial content like in Species and Machine, I have used Left and Find functions within Sumproduct
This formula simply returns the value from either column K or L based on the matching conditions and you may easily extend it or add more conditions.

Missing Data in Excel between 2 columns

I'm working with a fairly large data set, I have a list of names which appear more than once in column B and in column C i have the team they are part of.
In column C which displays there team name most the data is there but I do have a few 1000 where no team name is not present. Is excel smart enough to go for example Jamie#soso is part of design because it case in "B36" "C36" and then assign design to the missing field?
Here is an example of the data with the missing team names
And here is a view with what im looking for end result wise.
If I need to explain this better please let me know and thank you in advance.
On the assumption that there are no ambiguous entries, you could do the following:
if the order of the data is important, add an index column and insert ascending numbers for all rows of data (hint: enter the first two values manually, then select the first two cells and double click the fill handle to fill all the way down to the end of the data)
Sort the data by name and then by team as secondary sort
select column B
hit F5 to open the Go To dialog
click Special button
tick the option Blanks and click OK
now all blank cells in column B are selected
without changing the selection start typing a = sign, then hit the up arrow on your keyboard.
hold down the Ctrl key on your keyboard and hit Enter
now each previously blank cell in column B will have a formula that references the cell above.
copy column B
paste special on column B and paste values to get rid of the formulas
use the index column created in the first step to return to the original sort order
If you want this exercise to be repeatable, you could also use Power Query. Load the data into the Power Query editor, sort by name (ascending) and team (descending), select the Team column and click Transform > Fill > Fill down. The screenshot shows the result
To do without VBA, add a helper column in column C and insert this array formula:
{=INDEX($B$1:$B$17,MATCH(A1 & "?*",$A$1:$A$17&$B$1:$B$17,0))}
To create an array formula, type in the formula without the curly brackets, then press CTRL+SHFT+ENTER. Excel will add the curly brackets.
When you have your column C results, you can copy and paste values to overwrite column B if you want to get rid of your helper column.
This formula looks for rows with a value in A that matches the current row (i.e. same name), and any value in B that isn't blank; "?*" ensures at least one character. The match look up value is therefore A & non-blank B, and the array it's looking in is both A column range and B column range. The INDEX part provides the value from column B if it exists.
Names with no matching column B already completed will give you #N/A so you can manually enter those.

Count of distinct values with several criteria

I want to be able to count distinct values with several criteria. As presented here below on the screenshot, I would like to know, how many POs do I have per month depending on the PO type (service or material).
Initial data:
Desired result:
All the data is in text format.The difficulty is that the initial data table will be updated every month (I will be adding lines), so the formula has to consider possible updates. Pivot table will not work for me.
The solution I'm offering involves one helper column, but you'll be able to use it quite flexibly. I make the following assumptions:
You can add columns to your original table
The table starts in cell A1
Steps:
Convert your data range into a dynamic excel table (select the range, press Ctrl+t, tick "Table Has Headers" - you get a blue table as a result). This way if you add more data, formulas will drag themselves down.
type "HELPER" into cell D1, and "Number of POs" into cell E1 - this will create 2 new columns (they should turn blue like the rest of table)
paste this formula into cell D2:
=[#[Month/Year]]&[#[Mate/Serv]]
Paste this formula into cell E2:
=SUMPRODUCT(
( [HELPER]=[#[Month/Year]] & [#[Mate/Serv]] ) /
COUNTIFS([Month/Year],[Month/Year],
[Mate/Serv],[Mate/Serv],
[PO No.],[PO No.]
)
)
Add a pivot table, put Number of POs into values area, it will sum values by default.
As in this picture:
Right-click inside the values area, select Summarise Values By.. => MAX (as in second picture below).
You will see that values in pivot have changed.
this way you won't have to manually maintain the header in your summary table as pivot table will pick up any new entries/months.
IF YOU WANT TO STICK TO YOUR ORIGINAL DESIGN:
The same formula can be used (with minor change to add table name to column names), but it still needs the table and helper - follow steps 1-3. Make sure you're set up is as in picture below:
=SUMPRODUCT(
( Table2[HELPER]=H$1&$G2 ) /
COUNTIFS(Table2[Month/Year],Table2[Month/Year],
Table2[Mate/Serv],Table2[Mate/Serv],
Table2[PO No.],Table2[PO No.]
)
)
If anyone would like to change my formula to avoid creating a helper, please do.
I created a dummy table so your results won't be like mine.
How to test:
Copy your data on a new sheet
Go to Data menu ribbon => Remove Duplicates
Pivot the remainder
Put met/serve into rows, month/year into columns, Helper into Values.
That will give you a count you should expect.
Assuming your data is in Columns J:L, you can add a helper column in M, entering this formula in M2 and dragging down:
=COUNTIF(J:J,J2)
Then, assuming your desired result table is in columns N:P enter this formula in O2:
=COUNTIFS($K:$K,O$1,$L:$L,$N2,$M:$M,">0")-MAX((COUNTIFS($K:$K,O$1,$L:$L,$N2,$M:$M,">1")-1),0)
You can then drag this cell over to column P and drag them both down.
This also assumes you Desired result table headers are formatted as text as well.

How to add groups based on conditions in Excel?

I have a large set of data where I need to calculate the sum of groups for specific columns in a table. Here is an example of the table:
I need to sum up column H for each date group (column A) such that it will keep display this sum on the last row of the group. In other words, on the first group that we can visibly see here for 3/21/13, we would sum up 38 + 2 + 21 and display 61 to the right of cell H4930. This would be repeated throughout the data so as to display the sum of each group's H column entries at the lowest item in the group as aforenoted.
I am assuming that some VBA will be required here, but I am not sure how to attack this. How would this be done?
Yes as suggested by Idevelop ..you can get this done using pivot table
Select all the data -> goto Insert menu ->Pivot table > say ok
in Row field >Place A column title
in values field >place H column title
that's it
Let me know if you need more details.
Image :
I added 2 working columns before your Sum column.
Add: =NOT(ISNA(MATCH(C2,$Q$2:$Q$3,0))) to column N, where the Q2:Q3 are the numbers you wanted to check. Can be hidden.
Add: =IF(N2,COUNTIFS(A3:$A$7416,A2,N3:$N$7416,TRUE)=0,"") to column O. Can be hidden.
Add: =IF(AND(N2,O2),SUMIFS(H2:$H$2,A2:$A$2,A2,N2:$N$2,TRUE),"") to column P. This is your sum.
If you don't actually need to display all the data like this then a pivot table would be a lot clearer. You can filter based on numbers and so on easily.
edit: edited to check for specific codes in column C, per comment.
edit2: completely changed per comment. Requiring it to be inline with the last highlighted row is more complex.

Excel: If Cell in Column = text value of X, then display text (in the same row, but different column) on another sheet

This is a confusing request.
I have an excel tab with a lot of data, for now I'll focus on 3 points of that data.
Team
Quarter
Task Name
In one tab I have a long list of this data displaying all the tasks for all the teams and what Quarter they will be on.
I WANT to load another tab, and take that data (from the original tab) and insert it into a non-list format. So I would have Quarters 1,2,3,4 as columns going across the screen, and Team Groups going down. I want each "task" that is labeled as Q1 to know to list in the Q1 section of that Teams "Block"
So something like this: "If Column A=TeamA,AND Quarter=Q1, then insert Task Name ... here."
Basically, if the formula = true, I want to print a list of those items within that team section of the excel document.
I'd like to be able to add/move things around at the data level, and have things automatically shift in the Display tab. I honestly have no idea where to start.
If there is never a possibility that there could be more that 1 task for a given team and quarter, then you can use a formula solution.
Given a data setup like this (in a sheet named 'Sheet1'):
And expected results like this (in a different sheet):
The formula in cell B2 and copied over and down is:
=IFERROR(INDEX(Sheet1!$C$2:$C$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$B$2:$B$7=B$1),),0)),"")
I came across this situation. When I have to insert the values into a table from an Excel sheet I need all information in 1 Column instead of 2 multiple rows. In Excel my Data looks like:
ProductID----OrderID
9353510---- 1212259
9650934---- 1381676
9572474---- 1381677
9632365---- 1374217
9353182---- 1212260
9353182---- 1219361
9353182---- 1212815
9353513---- 1130308
9353320---- 1130288
9360957---- 1187479
9353077---- 1104558
9353077---- 1130926
9353124---- 1300853
I wanted single row for each product in shape of
(ProductID,'OrdersIDn1,OrderIDn2,.....')
For quick solution I fix it with a third column ColumnC to number the Sale of Product
=IF(A2<>A1,1,IF(A2=A1,C1+1,1))
and fourth Column D as a placeholder to concatenate with previous row value of same product:
=IF(A2=A1,D1+","&TEXT(B2,"########"),TEXT(B2,"########"))
Then Column E is the final column I required to hide/blank out duplicate row values and keep only the correct one:
=IF(A2<>A3,"("&A2&",'"&D2&"'),","")
Final Output required is only from Column E
ProductID Order Id Sno PlaceHolder Required Column
9353510 1212259 1 1212259 (9353510,'1212259'),
9650934 1381676 1 1381676 (9650934,'1381676'),
9572474 1381677 1 1381677 (9572474,'1381677'),
9632365 1374217 1 1374217 (9632365,'1374217'),
9353182 1212260 1 1212260
9353182 1219361 2 1212260,1219361
9353182 1212815 3 1212260,1219361,1212815 (9353182,'1212260,1219361,1212815'),
9353513 1130308 1 1130308 (9353513,'1130308'),
9353320 1130288 1 1130288 (9353320,'1130288'),
9360957 1187479 1 1187479 (9360957,'1187479'),
9353077 1104558 1 1104558
9353077 1130926 2 1104558,1130926 (9353077,'1104558,1130926')
You will notice that final values are only with the Maximum Number of ProductSno which I need to avoid duplication ..
In Your case Product could be Team and Order could be Quarter and Output could be
(Team,Q1,Q2,....),
Based on my understanding of your summary above, you want to put non-numerical data into a grid of teams and quarters.
The offset worksheet function will work well for this in conjunction with the match or vlookup functions. I have often done this task by doing the following steps.
In my data table, I have to concatenate the Team and quarter columns so I have a unique lookup value at the leftmost column of your table (Note: you can eventually hide this for ease of reading).
Note: You will want to name the input range for best formula management. Ideally use an Excel Table (2007 or greater) or create a dynamically named range with the offset and CountA functions working together (http://tinyurl.com/yfhfsal)
First, VLOOKUP arguments are VLOOKUP(Lookup_Value,Table_Array,Col_Index_num,[Range Lookup]) See http://tinyurl.com/22t64x7
In the first cell of your output area you would have a VLOOKUP formula that would look like this
=Vlookup(TeamName&Quarter,Input_List,Column#_Where_Tasks_Are,False)
The Lookup value should be referencing cells where you have the team names and quarter names listed down the sides and across the top. The input list is from the sheet you have the data stored. The number three represents the column number the tasks are listed in your source data, and the False tells the function it will only use an exact match in your putput.

Resources