Excel - How to count the number of distinct texts of a specific date inside a table? - excel

I'm trying to count the number of distinct text from a specific date in a data table.
Data Sample with expect result :
I was able to figure out how to count the distinct element from a range I specify, because I can determine the first and last row containing the date.
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
I have tried to modify my formula so that it determines the cell range by itself but without success.
I searched for an answer, using a combination of CELL and MAXIFS, example below, but Excel does not accept the formula.
=CELL("row",MAXIFS(A2:A15,A2:a15,D2))
I've looked at the INDEX formula, but I can't figure out how to do what I want to do. 😑
Any idea what I'm doing wrong, or what I should be doing instead?
Thanks, I appreciate it!

If you have Office 365 and the new Dynamic Arrays, this sort of formula has become ridiculously easy.
This formula in cell E3:
=COUNTA(UNIQUE(FILTER($B$2:$B$15,$A$2:$A$15=D3)))
Copy down.
You can also generate the unique list of dates with this formula in D3, which spills down automatically and does not need to be copied.
=UNIQUE(A2:A15)

It wasn't easy, but by separating each step of the problem, I was able to solve it.
Note that my solution only works because my dates are sorted.
Here's the final formula in the cell "One formula to rule them all":
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2))),INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)))))
Here are my explanations of my process:
Formula if I select the range :
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
Formula to get the first iteration
=ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2)
Formula to get the last iteration
{=ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)}
Create range from two addresses
=INDIRECT(CONCATENATE(F3,":",G3))
Formula giving me the expect result
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(F3,":",G3)),INDIRECT(CONCATENATE(F3,":",G3))))

Related

Automatic Excel Formula instead of writing by hand

Im trying to count the duplicated values between the 2 row so im using the formula as you can see it in the image =SUM(COUNTIFS(E4:S4,{"1","2","3"}))
so I have to write the numbers so I dont want write the numbers I want select the cells instead, any formula would do that? I already searched and tried many things but nothing seem to work
Put those values in cells - and refer to those cells as condition.
Next level: insert those values in a table, that you eg. call FilterBy and the column values
Then you can us this formula:
=SUM(COUNTIFS(E4:S4,filterBy[Values]))
Hat I don't understand: why are you using SUM - like this, it doesn't make sense, as COUNTIFS returns one value.
If you want to some all filtered values then you need this formula:
=SUM(SUMIFS(E4:S4,E4:S4,filterBy[Values]))

How to manually map columns in Excel with different headers

I want to write a function similar to simple Index-Match or Vlookup-Match.
Problem:
The values of the "Kadabra" columns should be shown in the "Jam" column and the "Shadabra" column in the "Jim" column. Given that the Columns will have consistent headers(Jim, Jam, Kadabra, Shadabra) but their positions may change(which means we cannot use column numbers).
"Abra" and "Jimmy" are the index values.
I'm looking for an excel formula solution. If there isn't one then a Visual Basic solution is also welcome.
One way to achieve this would be to use an Index Match Match formula as below, if you were to enter this formula into cell B8:
=INDEX($A$1:$C$4,MATCH(A8,$A$1:$A$4,0),MATCH("Kadabra",$1:$1,0))
And in C8:
=INDEX($A$1:$C$4,MATCH(A8,$A$1:$A$4,0),MATCH("Shadabra",$1:$1,0))
Then you could fill the formula down and it should bring the appropriate values into your Jimmy/Jim/Jam Table.
First please check below screenshot:
I have created a match table at E:F in order to avoid nested IFs for that condition. You may move the match table to another sheet and change your formula accordingly.
Formula for B8 is as below. You may drag-copy it down and right:
=VLOOKUP($A8,$A$2:$C$4,MATCH(VLOOKUP(B$7,$E:$F,2,0),$A$1:$C$1,0),0)

How do I use an array formula over a whole column or varying range?

I have a spreadsheet that I'm importing data into. I need to find the value within a column that is closest to zero. The column contains both positive and negative values, and the value closest to zero will be used in another formula. I've found an answer using an array formula, but it will only work for a fixed range (e.g. K2:K10), and the number of records imported into my sheet will vary each time I use it.
Here's what I have so far:
=INDEX(K:K,MATCH(MIN(ABS(K:K)),ABS(K:K),0))
Is there a way to apply an array formula over an entire column and just include non-zero cells other than the column title? Or possibly just cells with numerical values? Or is it possible to control the range that it applies to?
We can dynamically find the last cell in the range by using another INDEX/MATCH formula that is not an array:
=INDEX(K:K,MATCH(1E+99,K:K))
This will find the last cell that has a number in column K.
So we now use this as the last cell in the range:
=INDEX($K$2:INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K)))),ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K))),0))
And now the formula is dynamic.
This formula is still an array formula and must be confirmed with Ctrl-Shift-Enter when exiting edit mode. If done correctly then Excel will put{} around the formula.
If as you pointed out there is a chance of deleting row 2 then all the K2 references will also be deleted.
In place of K2 we can use INDEX(K:K,2) It will now always look at the second row and will not error when row 2 is erased. So use this instead:
=INDEX(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(INDEX(K:K,2):INDE‌​X(K:K,MATCH(1E+99,K:K)))),ABS(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K))),0))
There is nothing wrong with the Offset() function in small amounts, but it is a volatile function. Which means that it will calculate EVERY TIME excel calculate whether the data to which it is dependent has changed or not.
For the benefit of anyone reading this post, I ran into another issue and found a way around it. Scott Craner's answer above worked well until I ran a macro that I had for that sheet, which would delete certain rows. If row 2 got deleted, the formula would give a #REF error, because it was trying to call $K$2.
My solution was to replace $K$2 with
OFFSET(K1,1,0)
Therefore, the complete formula would be:
=INDEX(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)))),ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K))),0))
And as Scott mentioned, remember to hit Ctrl-Shift-Enter to execute the array formula.

Excel how to SUMIF with multiple criterias in Range of Column

Above picture is just a simple Files that I created, My original file is complicated and has a range of numbers in Criteria field.
NOTE: I just want only one Formula to get final Answers, not many Formulas then sum again those lines. (Using EXCEL)
Thanks and appriciate
p/s: Sorry for my rip English
Your formula in the upper right is close. You can use:
=SUM(SUMIF(C3:C23,K5:K10,D3:D23))
However, this in an array formula, so you must confirm this formula with CTRL+SHIFT+ENTER for it to work properly
And if you don't want to have a range that contains your criteria, you can list it right in the formula like this:
=SUM(SUMIF(C3:C23,{20,22,24,25,26,28},D3:D23))
(Same thing - must confirm with CTRL+SHIFT+ENTER)

Excel DSum function multiple criteria

Hello guys, I have been trying to implement the DSUM function but failed to figure it out. I looked through the previous DSUM posts on here and still don't understand. This is my problem:
on I8:L9, i have to implement the DSUM to calculate the "calculated quantity sold" for each item, ie Textbook, Novel,notepad and laptop. from A9-A16
I am supposed to use these values on B20 - B23. I don't know how to make sure i have multiple criteria for the DSUM function.
I tried this and it worked only for the first function: =DSUM(bookstore,J8,I8:I9)
This gave me the correct value only for Textbook, It summed up the quantities for textbook. What I want to do now is replicate it down so that it is the same for all the other elements.
Please help. thank you
With the setup you have then using this formula in B20 copied down will give the cumulative total of the categories
=DSUM(Bookstore,J$8,I$8:I9)
so that will give the sum for Textbook only in B20 but then in B21 it will be the sum for Textbook and Novel combined....then in B22 Textbook, Novel and Notepad (A22 should be "Notepad" to match I11)
To get the sum for the item in question only you could subtract the previous values above, i.e. use this version in B20 copied down
=DSUM(Bookstore,J$8,I$8:I9)-SUM(B$19:B19)
....but all things being equal I agree with user667489, except SUMIF is usually preferable for a single condition, i.e. in B20 copied down
=SUMIF(A$9:A$16,A20,D$9:D$16)
Is there any particular reason that you need to use DSUM to do this? You're making life very hard for yourself. You could do this much more easily via SUMPRODUCT or by using a pivot table.
When you create a column of conditions on the same variable, and you specify that as your constraint range for DSUM, excel sums over your database range where any of those conditions are true. You can't make it apply the constraint from just one row, unless that's the only row other than the column headings. So you need to put your different constraints for the same variable in different columns. This gets very messy.
Here is a sumproduct formula that will accomplish what you're trying to do, which can be copied down:
=SUMPRODUCT(($D$9:$D$16)*($A$9:$A$16=I9))
Paste that into cells J9:J12 (or B20:B23).
Another alternative having entered the DSUM formula in B20 is to select the range B20:B23 and choose Data > What If Analysis > Data Table... Column Input Cell: I9, OK. This should give the formulas below:
B20: =DSUM(bookstore,J8,I8:I9)
B21:B23: {=TABLE(,I9)}
Note: the Table formula cannot be entered from the formula bar, it is automatically generated by the Data Table command. (The same procedure could also be used to enter formulas in J9 and J10:13.)
I'd also recommend using SUMIF, or looking at PivotTables which could be used easily for this and create the list of categories for you.

Resources