Count the repeat of numbers from a number in a same cell in excel - excel

I got a bit confusing situation with excel, I would like to give an example
the spreadsheet is with a number unique to the cell and column
colA colB colC
101 102 103
201 202 203
Now, I have to find the repeats like below from above range
0 = 6 times
1 = 5 times
2 = 4 times
3 = 2 times
I have tried with CountIf() family functions, tried various functions from Len() etc.
If somebody can help in it, please.

To count the 0s:
=SUMPRODUCT(LEN($A$1:$C$2)-LEN(SUBSTITUTE($A$1:$C$2,0,"")))
adjust the ranges as needed, and change 0 to 1, 2 etc, or use cell references.

In D1 enter:
=LEN(TEXTJOIN("",TRUE,A:C))-LEN(SUBSTITUTE(TEXTJOIN("",TRUE,A:C),ROW()-1,""))
and copy downward:

Related

Display the column number of the last non-empty cell within a range (if values are not unique)

I have the following Excel spreadsheet:
A B C D E F G H I J K L
1
2
3
4 600 150 80 600 0 0 4
5 200 150 80 80 0 0 4
6
7
In Range K4:K5 I currently use the formula from this question to identify the last non-empty cell within the range and get the the column number of it back:
K4 = LOOKUP(2,1/(D4:J4<>0),COLUMN(D4:J4)-MIN(COLUMN(D4:J4))+1)
K5 = LOOKUP(2,1/(D5:J5<>0),COLUMN(D5:J5)-MIN(COLUMN(D5:J5))+1)
This formula works in the simple example above. However, once I use this formula in a bigger spreadsheet I get a lot of performance issues and numbers are not always updated correctly.
Therefore, I am wondering if there is alternative formula to get the column number of the last non-empty cell no matter if the values are unique or not?
As already described in the comments below the question the following solutions are available:
Option A)
If you want to get column number of the last non-empty cell:
=AGGREGATE(14,7,(COLUMN(D4:J4)-MIN(COLUMN(D4:J4))+1)/(D4:J4>0),1)
Option B)
If you want go tet the value in the last non-empty cell:
=INDEX(D4:J4,AGGREGATE(14,7,(COLUMN(D4:J4)-MIN(COLUMN(D4:J4))+1)/(D4:J4>0),1)
=INDEX(A4:J4,AGGREGATE(14,7,COLUMN(D4:J4)/(D4:J4>0),1)

Sum row in Excel/Google Sheets based on Condition

It seems like this question should exist somewhere, but I can't seem to find it...exactly.
The most similar solution I can find requires the use of SUMIFS or SUMIF, which only seems to add up numbers in a column, not spanning multiple columns. Here's an example sheet with 2 rows:
A B C D E F G H ...
1 2015-01-01 0 1 6 12 45 12 5 ...
2 2016-01-01 256 43 13 35 134 135 12 ...
Now I'd like to have a cell somewhere that adds all of the cells in the row for 2015-01-01. My attempt looks like:
SUMIF(A1:A30,"2015-01-01", B1:BJ30)
But this only yields the sum of the column B, so 0 for the exact formula above or 256 if I were to do this for the year 2016.
When trying something with SUMIFS, I'm told that the criterion range's size should match the sum range size, which isn't the case because my criterion range is only the first column of dates.
How can I add all the values in a row if the first cell's date matches my criterion? It may be worthwhile to note that this is in Google Sheets, not Excel.
In both excel and googlesheets you can use a SUMPRODUCT, for example:
=SUMPRODUCT((A1:A30 = DATE(2015, 1, 1)) * B1:BJ30)
You can try either of these:
=if(A1=date(2015,1,1),sum(B1:F1),"")
=if(A1=A1,sum(B1:F1),"")

Counting unique list of items from range based on criteria from other ranges

I have a file with data in the following format:
text value1 value2
Given value 1 and value 2 meet some criteria, find all the unique text values.
The exact data looks like this:
john 10 20
john 15 35
mark 20 10
mark 25 15
tom 25 40
lee 16 50
If val 1 <=25 and value 2 <=35 the number of unique text = 2 (john and mark)
I have to do this using formulas not filters.
I've been trying combinations of frequency, countifs, sumproducts and a whole range of other methods and can't seem to hit what I'm looking for.
Assuming that text, value1, and value2 are in columns A, B, and C respectively ...
In D1, enter the formula =IF(AND(B1<=25,C1<=35),A1,"") and copy it down the column
Use the formula =SUMPRODUCT((D:D<>"")/COUNTIF(D:D,D:D&"")) for your answer
If you want to list the unique values rather than count them, something like this:-
=IFERROR(INDEX(A$2:A$7,MATCH(0,IF((B$2:B$7>25)+(C$2:C$7>35),1,COUNTIF(E$1:E2,A$2:A$7)),0)),"")
entered as an array formula starting in E2 ( and assuming that you are using columns A,B and C for your data.
See this reference for explanation.
The following formula will do what you are asking:
=SUM(IF(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""),IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""))>0,1))
This is an array formula so confirm it with Ctrl-Shift-Enter.
I referred to this webpage.
Also found a shorter one:
=SUM(--(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,COUNTIF(A2:A7,"<"&A2:A7),""),""),COUNTIF(A2:A7,"<"&A2:A7))>0))
Found and modified from hre.

unique value based in a different columns data

Okay so here’s what I need…. And let me preface this by saying I know this can be done in a pivot table however, I am trying to avoid using a pivot table.
Col J Col M Col Q
origdest weeknum Wks Shipped - Prior 12 Months
AAABBBCCC 48 3
XXXX 44 2
AAABBBCCC 48 3
XXXX 44 2
AAABBBCCC 44 3
XXXX 45 2
YYYY 48 1
AAABBBCCC 3 3
ZZZZZ 48 1
In column Q, I need a formula that will give me the unique value in column M of the matching column J (which should give me the result shown in column Q.. In other words, I need to know how many weeks that “origdest” shipped. It seems like it should be pretty simple but I can’t seem to make anything work and I have had an issue with entering an array formula, it hangs up my computer.
There is a fairly standard method of achieving unique counts involving the SUMPRODUCT function and the COUNTIF function. Your situation demands that more criteria be introduced by substituting COUNTIF for the COUNTIFS function.
In Q2 try this standard formula.
=SUMPRODUCT(((J$2:J$99=J2)*(J$2:J$99<>""))/COUNTIFS(J$2:J$99, J$2:J$99&"", M$2:M$99, M$2:M$99&""))
Fill down as necessary. Your results should resemble the following.
      

Sum the values of if statements on multiple rows? (Excel)

Say I have a spreadsheet which looks like this:
A B C
1 In Actual Predicted
2 Thing One 300
3 Thing Two 564
4 Thing Three 256 1065
I want to be able to get a sum of the "predicted" column which incorporates values from the "actual" column if the "predicted" value is empty.
I.e. in this case, the value would be 300 + 564 + 1065 = 1929.
I know that I can achieve this for any individual row like so:
IF(C2="",B2,C2)
How do I get a sum of these "if" statements for each individual row?
Thanks.
That can be done with Sumifs() and no helper columns
=SUMIFS(B:B,C:C,"")+SUM(C:C)
Cell D2 = IF(C2="",B2,C2)
Cell D3 = IF(C3="",B3,C3)
...drag / copy to all relevant D cells...
Cell E1 = Sum(D:D)

Resources