Below is my Workbook Sheet1
Am expecting sheet2 like below,
Total Item column (Using countifs I can get but Sub_Item1,2 and 3 How do I use Match Index in Excel)
Use countifs to count total_item =COUNTIFS($A$3:$A$12,D3). For sub items use below formula. Then drag down and right as needed. If need to handle errors then use IFERROR() function.
=INDEX($B$3:$B$12,AGGREGATE(15,6,(ROW($A$3:$A$12)-ROW($A$2))/($A$3:$A$12=$D3),COLUMN(A$1)))
Related
C column is sorted from the input data
From the sorted output, the selected range should be with in -0.25 to +0.25
How to add more than one criteria in COUNTIF function or its similar function?
Original syntax:
.Resize(Application.CountIf(.Cells, "<0")).Select
Requirement:
.Resize(Application.CountIf(.Cells, ">-0.25 & <0.25")).Select
Replace CountIf with CountIfs when you want more than one condition. Try this:
.Resize(Application.WorksheetFunction.CountIfs(.Cells, ">-0.25", .Cells, "<0.25")).Select
I want to count the number of cells that meet two conditions:
sheet ABC's A2:A100 should be equal to the value of sheet XYC cell A8
the cell value in range D2:M100 = 1
Originally, I tried to use this formula:
=COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$D$2:$M$100,1)
But this gave me error #VALUE
I then decided to use the following formula to count each column separately and add them together.
=COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$D$2:$D$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$E$2:$E$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$F$2:$F$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$G$2:$G$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$H$2:$H$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$I$2:$I$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$J$2:$J$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$K$2:$K$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$L$2:$L$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$M$2:$M$100,1)
I am wondering if there are any other ways that allows me to shorten my formula?
Thank you.
You can use a boolean structure inside SUMPRODUCT() or just SUM() if your version of Excel supports dynamic arrays (ms365):
=SUMPRODUCT((ABC!A2:A100=XYC!A8)*(ABC!D2:M100=1))
I would like to create a table with products and formulas on a sheet (Sheet2). For different products, different formulas apply.
I would like to retrieve the formula from that table but use the row numbers from the row in Sheet1
How do I enter a formula which is evaluated with the correct row numbers from Sheet1.
I have a UDF eval that can evaluate a text string:
=eval(vlookup(Product;Table;2;false)
The formula retrieved from the Table should use the row number of the actual row that the eval() is on.
I tried the following:
="D"&ROW(Sheet2!$A16)&"/G"&ROW(Sheet2!$A16)&"/F"&ROW(Sheet2!$A16)&"*5"
This retrieves the formula but the eval() does not calculate the result.
In your example, product is located on Sheet2 in the 16th row of the first column of table. If you want the 16th row on the worksheet, you can use the MATCH function on a full column reference, discarding the structured references of the ListObject table or you can use MATCH on the structured table reference and compensate for the 'position within' table by adjusting by the table header row.
That's probably confusing so here is an example.
To find the actual row-on-the-worksheet where bcd resides you would use one of these formulas.
=MATCH("bcd", Sheet2!B:B, 0)
=MATCH("bcd", Table2[a], 0)+ROW(Table2[#Headers])
The first simply returns row 6 on the worksheet. The second returns 2 since bcd is in the second row of the ListObject's .DataBodyRange property and this is adjusted by the row that the .HeaderRowRange property is in; e.g. 2 + 4 = 6.
Now that everything is clear, all you need to do is use the result from one of those formulas as the row_number parameter in an INDEX function.
=INDEX(D:D, MATCH("bcd", Sheet2!B:B, 0))/
INDEX(G:G, MATCH("bcd", Sheet2!B:B, 0))/
INDEX(F:F, MATCH("bcd", Sheet2!B:B, 0))*5
'or,
=INDEX(D:D, MATCH("bcd", Table2[a], 0)+ROW(Table2[#Headers]))/
INDEX(G:G, MATCH("bcd", Table2[a], 0)+ROW(Table2[#Headers]))/
INDEX(F:F, MATCH("bcd", Table2[a], 0)+ROW(Table2[#Headers]))*5
Your own formula could have worked with a series of INDIRECT functions that convert constructed strings to actual cell references. However, INDIRECT is considered volatile and best avoided if possible.
=INDIRECT("D"&ROW(Sheet2!$A6))/INDIRECT("G"&ROW(Sheet2!$A6))/INDIRECT("F"&ROW(Sheet2!$A6))*5
This solution is based on the capability of Excel to reference the cells in R1C1 style. In order to use it, you will have to go to File -> Options -> "Formulas" tab, and check the box "R1C1 reference style" in "Working with Formulas" group.
In addition, your eval() function will have to be able to evaluate such kind of formulas.
Once, all of these is done, you only have to retrieve the formula.
In order to make the things clear, I will focus on an example.
The table below is the contents of Sheet1 (the "Database" of products).
The column "Formula" contains the relevant formula:
for apple: RC[-2]+RC[-1]
for banan: RC[-2]*RC[-1]
for lemon: RC[-2]/RC[-1]
The table below is the contents of Sheet2:
The column "Formula" here contains the formula, retrieved from Sheet1. The formula of the column "Formula" is as follows:
=FORMULATEXT(INDEX(Sheet1!R2C1:R4C4,MATCH(RC[-3],Sheet1!R2C1:R4C1,0),4))
The description of each of the functions, used here (formulatext, index and match) can be found in Excel help.
As it can be seen, the retrieved formula, represented in R1C1 style is correct in context of Sheet2, were the products are arranged differently, and may appear more than once. The only remaining work to do is to apply the eval() function, after it was adapted to evaluate R1C1-style referenced formulas.
I hope it helps.
Google sheets has a filter command with the syntax
=filter(Range, criteria 1, ... criteria n)
It returns an array.
How can I do this in excel?
Example: I have a range 2 columns wide, with Genus in column 1, and the full botanical name in column 2. This range is named bot_name
Elsewhere I have a cell C1 with "Abies", the genus name for the firs.
In Google spreadsheet I can do this:
=UNIQUE(FILTER(Bot_Name,REGEXMATCH(Bot_Name,C1)))
For each row in the range, FILTER includes it if REGEXMATCH returns true.
Filter and Unique are filter functions.
Filter is documented:
https://support.google.com/docs/answer/3093197
From this I should get the following list:
Abies balsamea
Abies concolor
Abies lasiocarpa var bifolia
Abies veitch
I suggest that you use formulas and not the Excel filter feature (which is very different from FILTER function you have mentioned), because I suppose you need that your filtered data change whenever you change the search expression (e.g. Abies).
First you need to check which values match your criteria:
I suggest that you use COUNTIF function - it enables you to use wildcards in your search expression - I add * at the end to find everything that starts with "Abies".
So formula in a helper column looks like this:
=IF(COUNTIF(A2,$C$2 & "*")>0,A2,"")
You can hide the helper column later.
Then you need to remove duplicates - so the next final formula will be a non-array formula:
=INDEX($D$2:$D$15,MATCH(0,INDEX(COUNTIF($E$1:E1,$D$2:$D$15),0,0),0))
Your sheet would now look like this with search expression in the cell C2:
Also use IFERROR to remove cells having error. Also you can use named ranges instead of $D$2:$D$15 to simplify the second formula.
Download the sample Excel sheet here.
This is more complicated than using FILTER function with array and I really miss this feature in Excel.
I have a situation where I need to calculate ontime vs. late in a range of cells.
I use the if statement =IF(N2>K2 +30,"Late","") and this works fine however I would like to combine the countif statement to count the range of cells that contain "late"
Thanks
Try this:
=SUM(IF(N:N>K2+30,1,0))
Enter it as array formula by pressing CTRL+SHIFT+ENTER.
updated if you only need to count the number of lates.
As per Roberto's comment, if you are actually using a formula to put "Late" in column L for each relevant row you can use a simple COUNTIF to count those
=COUNTIF(L:L,"Late")
or if you want to use the source data in column N just use COUNTIF with that
=COUNTIF(N:N,">"&K2+30)