How to resolve Excel IF AND question query formula - excel

Need help with a Excel formula.
I have two sets of data in two tables, with the same number of columns and rows.
One table has data for male, the other one for female.
Each table has a common definer (age). All the other data are different. All data are in numbers. Some are negative.
I aim to use a single cell to get a result coefficient used by a specific equation, and I need to channel the input data by two criteria. One is gender, the other one is age. I am trying the IF AND formula, but it is not working.
Here is an example.
age (D2) coefficient (D2-D4)
Table Female.
18-30 yrs 25
30-60 yrs 35
60-70 yrs 41
So here is the data to process:
D1 F
D2 29
D3 115
(MEANING Gender - female; age 29; weight 115 pounds)
I was trying the IF AND formula
=IF(AND(D1="F";D2>17;D2<30);(D3+H2);IF(AND(D2>=30;D2<60);(D3+H4)))
Now, this works fine when I only calculate the female data, but I can't seem the find the way to include the formula to choose from the MALE table, if the subject is male ("M").
Any help or clues on how to resolve this?

Welcome to stackoverflow. It would be easy to help you if you paste a screenshot of your table etc as it would make us understand your problem clearly.
Anyway, two solution advice from me:
1- you can use nested if operators but not like yours. Before expressing conditions with and operator, add another if to start processing data related to females. Like this: =IF(D1="F";IF(AND(D2>17;D2<30);(D3+H2);IF(AND(D2>=30;D2<60);(D3+H4))).
After processing females, add the same formula strings this time for males. This will solve your puzzle I guess.
2- my second advice would be creating a user-defined function. I often create a user-defined function if my formula gets too long and become hard to read. I strongly recommend you to search for this as it will make you better-understand the logics in excel functions and make you equipped against your puzzles in future.

Related

Of the 10 individuals with the highest income, how many are married males?

Question --> Of the 10 individuals with the highest income, how many are married males?
I want to achieve the same in a single function.
Below is a database.
enter image description here
First I fetched data with Large and the applied vlookup and the used counifs to get the count.
enter image description here
enter image description here
You are close.
Why are you using IFERROR? Are there errors in the data or something else?
In the formula below, I used a Table and Structured references. An advantage is that the range references will automatically adjust. You can switch to normal addressing if you prefer.
I would use:
=COUNTIFS(myTable[Income],">="&LARGE(myTable[Income],10),myTable[Sex],"M",myTable[Married],"Yes")
With regard to your formula, you would think you could just SUM the results. Unfortunately, for any instance where there are duplicates (2 married men with same income in the top 10), your formula would return a 2 and not a 1 and the SUM would therefore be incorrect.
You can avoid that, with your approach, by converting any non-zero into a 1:
=SUM(--ISNUMBER(1/(COUNTIFS(myTable[Income],LARGE(myTable[Income],SEQUENCE(10)),myTable[Sex],"M",myTable[Married],"Yes"))))
However, I think my approach is simpler.

Distribution of time values randomly in a table Excel - Modeling Power Grid

I am working on a model of charging load of electric vehicle. I am attaching a link to an excel workbook for your better understanding.
Column B contains random time values
Column G to P represents houses and each house can have 1 car. So the each time values needs to be distributed in one column. Now when a car is plugged in, its load stays constant for 3 cells.
I want excel to randomly distribute these cars e.g. 4 cars to 4 houses and leave others blank.
what i can think of is, to assign each time a random house then use IF formula with AND function to match random times with time series and second condition to match random houses with columns 1-10.
the problem i am facing is, the formula gives a value error and only works in the rows with has random generated time in front of them screenshot. I know there is a very small thing that i am missing. please help me find it
Regards
workbook
=IF(ISNA(MATCH(G$5,$C$6:$C$9,FALSE)),"",IF(AND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE))>=$F6,INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE))<=$F6+TIME(0,30,0)),11,""))
The two elements in the AND find the house number in column C and return the corresponding time in column B.
The first element compares the time in F to that time. The second element compares the time + 30 minutes to F (three cells). If it's between those two times, it gets an 11.
The ISNA makes sure that the house in question is on the list. You could also use an IFERROR, but I prefer the precision of ISNA.
Update
If you want the values to wrap around, you need to OR compare to the next day.
=IF(ISNA(MATCH(G$5,$C$6:$C$9,FALSE)),"",IF(OR(AND(ROUND($F6,5)>=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE)),5),ROUND($F6,5)<=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE))+TIME(0,30,0),5)),AND(ROUND($F6+1,5)>=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE)),5),ROUND($F6+1,5)<=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE))+TIME(0,30,0),5))),11,""))
That formula structure looks like
=If(isna(),"",if(or(and(today,today),and(tomorrow,tomorrow)),11,"")
This formulas already getting too big. If you triple it for your three voltages, it will be huge. You should consider writing a UDF in VBA. It won't be as quick to calculate, but will probably be more maintainable.
If you want to stick with a formula, you could put the wattage in row 4 above the house number. Then in another table, list the wattages and minutes to charge. So in, say, B12:C14 you have
3.7 120
11 30
22 15
Now where you have 11 in your formula, you'd have G$4 and the two placed you have TIME(0,30,0), you'd have TIME(0,INDEX($C$12:$C$14,MATCH(G$4,$B$12:$B$14,FALSE)),0). I re-arranged some stuff to make it more 'readable' (but it's still pretty tough) and here's the final formula
=IF(ISNA(MATCH(G$5,$C$6:$C$9,FALSE)),"",IF(OR(AND(ROUND($F6,5)>=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE)),5),ROUND($F6,5)<=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE))+TIME(0,INDEX($C$12:$C$14,MATCH(G$4,$B$12:$B$14,FALSE)),0),5)),AND(ROUND($F6+1,5)>=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE)),5),ROUND($F6+1,5)<=ROUND(INDEX($B$6:$B$9,MATCH(G$5,$C$6:$C$9,FALSE))+TIME(0,INDEX($C$12:$C$14,MATCH(G$4,$B$12:$B$14,FALSE)),0),5))),G$4,""))

Removing INDIRECT from dynamic column selection

I have researched thoroughly before posting and still can't figure this out.
I currently have a file that uses an INDIRECT logic to gather information from one worksheet to a summary worksheet. The file works perfectly as is. But I'm trying to make it more efficient as right now calculating times are huge due to so much volatility.
In the data worksheet I have a lot of columns, each with a concept and an account number assigned to it.
So, for example:
5014255 5324232 5566544
Name Store Salary Taxes Other Benefit P1 Weight P2 Weight
John Main 222222 50000 30000 0.4 0.6
Jane Annex 222224 50002 30004 0.3 0.7
Then in the summary page, I use a SUMPRODUCT to gather the information per store per account and separating by period, like this as:
Store Account Concept P1 P2
Main 5014255 Salary 88888.8 133333.2
Main 5324232 Taxes 20000.0 30000.0
Main 5566544 Other Benefit 12000.0 18000.0
Annex 5014255 Salary 66667.2 155556.8
Annex 5324232 Taxes 15000.6 35001.4
Annex 5566544 Other Benefit 9001.2 21002.8
This of course is just a basic example. The real file has several more validations and several categories of weights that are used for different accounts. In order to pull the information I have the following formula.
=IFNA(SUMPRODUCT(
INDIRECT(INDEX("'Sheet1'!"&ADDRESS(6,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4)&":"&SUBSTITUTE(ADDRESS(1,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4),"1","")&$AU$1,1,1)),
--(Sheet1!$C$6:$C$1754=2018),
--(Sheet1!$J$6:$J$1754=$I5),
IF($G5=1,Sheet1!$BN$6:$BN$1754,IF($F5=1,Sheet1!$BA$6:$BA$1754,Sheet1!$AN$6:$AN$1754))
),0)
The important piece of code is:
INDIRECT(INDEX("'Sheet1'!"&ADDRESS(6,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4)&":"&SUBSTITUTE(ADDRESS(1,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4),"1","")&$AU$1,1,1))
This uses string manipulation to generate the column range according to the account number. So for example, the account number 5014255 would generate Sheet1!$C$6:$C$1754, so that the values in that column can be gathered according to weight and validations.
So, I'm trying to change the logic to remove volatiles. But so far I haven't been able to do it.
I basically need my summary to find the column where the account number is, so it can do the sumproduct calculations with that column.
Any ideas or suggestions on how to work around this?
To get the full column without volatiles use:
INDEX(Sheet1!$C$6:$E$1754,0,MATCH($N5,Sheet1!$C$1:$E$1,0))
This will return the correct column to the SUMPRODUCT formula

AverageIf and Multiple data strings

I'm involved with a youth football tournament on the referee side, with assessing/coaching the referees. I've just taken over doing the data entry for the referees assessment scores which we then use to determine who gets finals etc and am looking to extract more usable information from the data to help us identify trends.
I've got (up to) 200 referees, each receiving from none to two assessment scores each day for 5 days. The scores are entered as both the raw mark and the weighted mark based on match difficulty (along with a host of other data about the match that isn't relevant to this issue.
I can extract the average mark (raw and weighted) across all referees without issues and have done so using the below formula, which is the raw average mark:
=AVERAGE(Working!AK4:AK200,Working!BK4:BK200,Working!CL4:CL200,Working!DL4:DL200,Working!EM4:EM200,Working!FM4:FM200,Working!GN4:GN200,Working!HN4:HN200,Working!IO4:IO200,Working!JO4:JO200)
But I also want to extract the average mark (raw and weighted) across two subsets - Academy and non academy referees, to help plot trends and determine where resources need to be utilised.
I've attempted to use an AVERAGEIF formula, but am getting a #VALUE! return. This is the formula that I've attempted to use to return the average raw mark for those referees in the academy:
=AVERAGEIF(Working!G4:G200,Working!G4:G200="Yes",(Working!AK4:AK200,Working!BK4:BK200,Working!CL4:CL200,Working!DL4:DL200,Working!EM4:EM200,Working!FM4:FM200,Working!GN4:GN200,Working!HN4:HN200,Working!IO4:IO200,Working!JO4:JO200))
If I do the same formula as above, but without the brackets around the [average_range], I get a 'you've used too many arguments, and it highlights BK200.
From what I've been able to find so far online, it seems that the formula I'm trying to use would only work if ALL the cells in (Working!G4:G200) returned "Yes". However if there are only 50 academy referees as indicated by "Yes" in G column, then I want those specific scores to be averaged, and the inverse for the non-academy referees.
I thought about having another sheet, which would simply contain populate from Column G (a simple =G4 and then populated down to =G200 next to all of the scores), consolidated into a block of raw marks columned under Assessment 1, 2, 3, 4.... and then the same for all of the weighted marks which would populate from the equivalent cell on the working sheet, but there's a lot of filtering, and re-sorting that goes on on the working sheet, and I'm not 100% certain that that wouldn't cause issues.
Any feedback on how to work through this problem, so that I can display the overall average mark for academy and non-academy referees in both raw and weighted form would be much appreciated, and I apologize if this post is rather convoluted.
I don't think there is a neat solution if the scores are in several columns which are not consecutive.
My suggestion is:-
(1) Work out the sum for each column separately and total them up
(2) Work out the count for each column separately and total them up
(3) Divide Sum by Count to get Average.
In my small example below with 3 referees and 3 columns:-
(1) In K2:-
=SUMIF(H2:H4,"Yes",B2:B4)+SUMIF(H2:H4,"Yes",D2:D4)+SUMIF(H2:H4,"Yes",F2:F4)
(2) In K3:-
=COUNTIFS(B2:B4,">=0",H2:H4,"Yes")+COUNTIFS(D2:D4,">=0",H2:H4,"Yes")+COUNTIFS(F2:F4,">=0",H2:H4,"Yes")
(3) In K4:
=K2/K3
This would include any zero scores (if this is possible) but exclude any blanks.
You can then scale it up to your data.
Beyond this, you would have to change the data structure either
(1) Add a row to label the columns that you want to average e.g.
Score 1 Score 2 Score 3
3 0 3
so you could pick up only the columns labelled 3 say
Here's how it would be in my small example:-
In K3:-
=SUM((B$2:F$2=3)*($H3:$H5="Yes")*B3:F5)
Which is an array formula and must be entered with Ctrl-Shift-Enter
In K4:-
=SUM((B$2:F$2=3)*($H3:$H5="Yes")*(B3:F5<>""))
another array formula
In K5:-
=K3/K4
This is how the columns you want are labelled with a 3 in row 2, so it ignores the other columns:-
(2) Consolidate them into another sheet as you suggest.

Excel what method use to calculate time and age

I have got a table with 2 columns:
AGE between 10 and 90 lets say :]
and Time (spent on mobiles)
What I need to do is- count how long people spent time on mobiles between 16 and 40.
First part may be seemingly simple because we can count by countif how may people is using mobiles between 16 and 40 but how evaluate spend time on mobiles by the particular age groups.
I will appreciate aaany help
regards
If you need to analyze your data more than creating a static function to count, you may consider using Pivot tables.
Build a simple pivot table with age in rows and time in values. Once this simple pivot table built, you can filter on the rows values, group them together among specific grouping criteria, select specific values by hand, etc.
I like the idea given by Boud of using Pivots but if you specifically want a formula then you can use SumProduct()
=SUMPRODUCT((A2:A13>16)*(A2:A13<40)*(B2:B13))
Do remember to format the cell as [h]:mm:ss since you are adding up times.
SNAPSHOT
You can for example add additional column, with formula like:
=IF ( AND(A1>16, A1<40), B1, 0 )
where A is column with AGE, and B is column with Time, and then simply sum it!

Resources