Excel counting cells based on complex criteria - excel

Hate asking question about something as simple as an Excel formula, but seem to really need and would appreciate the help.
I have a table where the rows headings contains names and the column headings contains week numbers. Within this table I have differents numbers. Both numbers that are plus and negatives.
I want to count each cell where the row heading matches a specific name and then each cell that has a plus value with a week number less than or equal to a certain week.
I have tried to got it to work with at least some function (without it caring about plus and negative values) but haven't even gotten that to work.
I've tried with:
=SUMPRODUCT((Data!F3:F28=I1)*(Data!I2:BI2="<="&A1)*(Data!I3:BI28))
=SUMIFS(Data!I3:BI28;Data!F3:F28;I1;Data!I2:BI2;"<="&A1)
.............1 2 3 4 5
name1 -1 4 3 1 1
name2 0 0 0 0 0
I want a formula that counts for example every column header with a value less than or equal to (for example) 4, but excludes negatives and vice versa. So for the example above, the result of name1 should be 8; counts week 2, 3 and 4.

For your current example:
Formula in H3:
=SUMPRODUCT((B2:F3>=0)*(B1:F1<=4)*(A2:A3="name1"),B2:F3)

Related

Move the value of all cells in a column to their corresponding excel row number

Let's say i have the below list of Whole numbers in Column A. If you observe the list of numbers, you will see that number "5" and 6 is missing.
A
3
2
4
1
7
8
what I want to achieve is to place (sort) the numbers on the column such that each cell value will take its position according to excel row numbering. which means:
I should have something like this
1
2
3
4
7
If it's as simple as stated, this should work.
In column B, say:
=IF(COUNTIF(A:A,ROW())>0,ROW(),"")
Note: It does not account for duplicates, or anything complicated really.
Further Note: To clarify, all this does is check if the row that the formula is in, is in column A. If it is, then it returns the current row.

How do I randomly distribute a set of numbers across a single column?

I have a set of continuous "1" values across column A Eg: 11111. I'd like to distribute this randomly across column B with spaces in between Eg: 1 1 1 1. Not really sure how to go about this. I'd like to do this for 600 values in column B. Any help is appreciated!
This formula could work:
=IF(ROUND(RAND(),0)=1,1,"")
It will generate a random number between 0 and 1, round it to the nearest integer (so 0 or #), return 1 if the result is 1 and nothing if it is 0
Populate as many cells as you need in the column you want
Edit:
To limit the number of 1s appearing use the following formula in cell B2 and copy down:
=IF(AND(ROUND(RAND(),0)=1,COUNTIF(B$1:B1,1)<6),1,"")
Where 6 is the maximum number of ones that will appear, you can change it to any integer or reference a cell that has the maximum number of 1s you want to appear

Excel formula: make the average depending on a cell

I want to make a formula that turns in a VBA code that makes the average for column A even though there are some 0 there. I want to divide it by a the number in a cell that counts the objects in column A.
I used to use this formula, but it divides my sum incorrectly because I have 0's (I want to keep the 0's there):
=AVERAGE(Sheet1!$B$2:$B$10000)
The easiest way to do this, is to get the total of column B by using sum(B:B) (or a more specific range, if you want), and the amount of non-blank cells in column A by using counta(A:A) (in my comment I used count which only counts the amount of numbers in the range, counta should count all non-blank cells). You can then divide the former by the latter to get the number you are looking for, resulting in a formula looking something like
=SUM(B:B)/COUNTA(A:A)
If you already have the count of column A in a cell (e.g. E3), it's even simpler, just use something like
=SUM(B:B)/E3
You can use AverageIf for such a purpose, as you can see in my example:
Row/Column A B C D
1
2 2 =AVERAGE(B2:B5) => value 3
3 4 =AVERAGEIF(B2:B5;"<>0") => value 4
4 0
5 6

How do I make a cell value represent a number in Excel?

I have
Year 1 2 3 4 5 6
I'm trying to make it so that each year number 1-6 is equal to another number value i.e. Year 1 is equal to 5. Year 2 is equal to 6.
You will not be able to store one value in a cell and use a different value for calculation. However you may do this calculation with the help of a lookup from another table,
Assuming you have the years in Column A and the corresponding mappings are in Column E and F, you can use the below formula in Column B,
=INDEX(E:F,MATCH(A1,E:E,0),2) * 2
This formula lookups the value in A1 in the table E:F and returns the corresponding Column F element. That is finally multiplied with the 2 to show your result. Instead of just using just A1 for multiplying by 2, you should be using INDEX(E:F,MATCH(A1,E:E,0),2). Hope this helps.

Using COUNTIFS for a series of values at once

Working a step higher then COUNTIFS, I appose a challenge to write a formula without VBA code. The basic data is combined from 1000s of rows with:
Column A: rows with values from 1 to 3
Column B: rows with values from 1 to 250.
For this purpose lets say, we are looking at all cells of value "1" in column A, that suit value "5" in column B. To find all matches, we'd use COUNTIFS command.
1 1
2 5
1 5
1 7
1 10
3 45
2 12
1 2
2 1
=COUNTIFS(A1:A9;1;B1:B9;5)
The answer here is 1.
Next thing, the "5" in column B belongs to a group, e.g. group from 1 to 9. What would the best way be, to count all the matches in this example, so that for all "1"'s in column A, we'd have to find all matches with values from 1 to 9 in column B?! In the upper example that would result in "4". The obvious solution is with a series of IF commands, but that's unefficient and it easy to make a mistake, that get's easily overseen.
=COUNTIFS(A1:A9;1;B1:B9;"<="&9)
Works only as the upper limit. If I give the third criteria range and condition as ">="&1 it does not work - returns 0.
Gasper
Where the data is in A1:B9, using a lookup table in D1:E10 with letters A-J in column D and numbers 0 to 9 in column E and the following formula in B11 referencing letters entered in A11 and A12:
=COUNTIFS(A1:A9,1,B1:B9,">="&VLOOKUP(A11,$D$1:$E$10,2,FALSE),B1:B9,"<="&VLOOKUP(A12,$D$1:$E$10,2,FALSE))
works, changing the letters in A11 and A12 gives the correct count according to what they correspond to in the looku in D1:E10.
When you say give third criteria range do you mean:
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
If so then try:
=COUNTIFS(A1:A9;1;B1:B9;AND("<="&9,;">=1"))
ie have two conditional ranges with the second range having both conditions combined with AND()
Maybe what you want(ed) is:
=COUNTIFS(A:A;1;B:B;">=1";B:B;"<=9")
Almost there. I noticed that three criteria ranges and conditions work only if I use "=" sign in a condition. As soon as I use
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
it returns 0. My goal is to eventualy replace the number in a condition with a VLOOKUP command, so the final equation should be smth like
=COUNTIFS(A1:A9;1;B1:B9;"<="&VLOOKUP(...),B1:B9;">=VLOOKUP(...)")
But the "<" and ">" signs mess with this. Still looking for a solution.
This is my entire line, if it offers any further indication. The AND() commands is at the end - and it still results in 0
=COUNTIFS(INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));IF(C6="računska";1;0);INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));AND("<="&VLOOKUP($C$5;$K$203:$N$223;4;FALSE);">="&VLOOKUP($C$5;$K$203:$N$223;3;FALSE)))

Resources