How to substitute values in excel? - excel

I'm working with excel and I want to count how many persons doing some sport or playing computer games. Is it possible? Let's assume that I have this table A:
Person Activity
1 Football
2 Football
3 Football, FIFA 17
4 Hockey
5 Hockey
6 FIFA 17
7 FIFA 17
Now I used pivot table and I know that I can have these values:
FIFA 17
Football
Football, FIFA 17
Hockey
The first question is, could I use some if function for adding new column and translate it to category? By this table?
Activity Category
FIFA 17 PC
Football Sport
Football, FIFA 17 PC, Sport
Hockey Sport
Something like :
if table A column activity is equal value from translation above, assign category. So I expect this result:
Person Activity Category
1 Football Sport
2 Football Sport
3 Football, FIFA 17 PC, Sport
4 Hockey Sport
5 Hockey Sport
6 FIFA 17 PC
7 FIFA 17 PC
And the final is that I want to count if column category contains one values from Sport, PC and if so the +1. So I expect the final result:
Category Count
PC 3
Sport 5
Bot steps (translation to category and containing of text) are really important. Because in general I will have to translate more values to one category. Thanks in advance

You can do the following:
First to insert the category from the table of category use:
=VLOOKUP(B2,$G$1:$H$4,2,FALSE)
G1:H4 is the table with activity and category and keep $ for absolute reference
B2 is the Second column (activity column) where each person (Column A) has an activity
2 to return the second column value in Activity/Category Table
False to return the exact value
You can drag it down
For the Count use:
=COUNTIF($C$2:$C$8,"*"&B11&"*")
C2:C8 the new column of category created by the above formula
$ to have absolute reference
B11 is the Category which you want to count
"*"&... to include all combined category with the simple one
Column A Column B Column C
Person Activity Category
1 Football Sport =VLOOKUP(B2,$G$1:$H$4,2,FALSE)
2 Football Sport
3 Football, FIFA 17 PC, Sport
4 Hockey Sport
5 Hockey Sport
6 FIFA 17 PC
7 FIFA 17 PC
Column B Column C
Category Count
PC 3 =COUNTIF($C$2:$C$8,"*"&B11&"*")
SPORT 5

At the column B Select the all cell you want to fill with activity and "Define Name" to this range.(assume Activity).
Then Go to other cell where you want to display results. Define Name scope for whole sheet, you can display results any other sheet like sheet3 etc...ok.
Put this formula:
for football>> =countifs(Activity,"Football") Enter
repeat this an other cells for hockey, FIFA and other games

Related

Count apple based on common ID between two tables

I have two Excel tables that look like this:
Table 1
A B C
ID Stocked Sale
1 shelf sold
5 display sold
9 shelf sold
12 shelf sold
13 shelf
Table 2
P Q
ID Stocked
a2 apple
88
83
1 apple
9 apple
I need to count the total number of apples by common ID, given that apples are:
stocked on the shelf in Table 1
sold in Table 1
So, the outcome has to be 2 apples.
Here is what I have tried thus far:
COUNTIFS(B:B, "shelf", C:C, "sold", Q:Q, "apple")
I can't figure out how to count by common id...
Something like this should work for you:
=SUMPRODUCT(COUNTIFS(A:A,REPT($P$2:$P$6,$Q$2:$Q$6="apple"),B:B,"shelf",C:C,"sold"))

Excel VBA to find non unique values with multiple conditions

I am looking for some help trying to create an excel macro. I have a very large sheet that look a bit like this:
Account NAME Address Dealer
68687 Sara 11 Wood 1111
68687 Sara 11 Wood 1111
68687 Sara 11 Wood 1111
12345 Tom 10 Main 7878
12345 Tom 10 Main 7878
54321 Tom 10 Main 7878
10101 John 25 Lake 3232
10101 25 Lake 3232
11111 John 25 Lake 3232
What I need to do is to highlight all the rows on the sheet where each Dealer has more than one unique value in the Account column, but it must also have some value in the name column.
So in the above example I would only want to highlight all the rows for dealer 7878.
I am not certain if I should look at loops or arrays, they might take a long time as the sheet is quite large.
Looking for some help.
Thanks.
James - Dirk gave you a good answer in his comment. It looks like this ...
The format formula is also put into Column F, so you can see the results of the calculation.
If you feel you should still have a VBA solution, this gives you a good starting point for how to layout your code ...
Ignore rows with empty name
Count rows where the dealer is the same as the dealer in the current row, and the account is NOT the same as the account in the current row
If the count found in Step 2 is greater than 0, highlight the current row.

Count X records matching certain conditions and only where there is a corresponding Y record

I am looking for some help with a formula. On my 'data' sheet, I have data in the format below:
A B C D E F G H I J
1 UID RecordType HCode AdmittedDate Forename Surname DOB Sex STDate RDate
2 87962 STAsses STIV1 01/01/2012 Mark Jones 13/07/1978 Male 09/12/2012
3 89658 Transfer GLSI2 01/01/2012 Alison Aitken 20/12/1956 Female 08/07/2013
4 84563 Discharge JHOP1 01/01/2012 David Beckham 09/08/1987 Male 08/07/2013
5 89654 STAsses STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 08/07/2012
6 89867 Transfer KIND1 01/01/2012 George Deas 08/05/1989 Male 08/07/2013
7 87962 Transfer STIV1 01/01/2012 Mark Jones 13/07/1978 Male 04/03/2013
8 89654 Transfer STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 12/08/2012
On my 'report' sheet, I have the following table set up:
B C D E F
4 HospCode RecordType Jul-12 Aug-12 Sep-12
5 STGE1 Assessments
6 Transfers
7 Discharges
8
What I need is a formula in cell D6 of the 'report' sheet, which counts all 'Transfer' records from the 'data' sheet, occurring in the month specified in D4 and with an 'HCode' matching that in B5 of the 'report' sheet. The tricky part is that I need this formula only to count records which have a corresponding 'STAssess' record.
Might be pushing the limits of Excel here, but anything is possible!
Thanks in advance.
You can simply use
=COUNTIFS(Sheet1!B1:B8, "Transfer", Sheet1!C1:C8, Sheet2!B5)
This is an example with 2 criteria, you can add a lot many more for multiple IFS and COUNTIFS will count those.
In case of finding multiple criteria across rows, you are better off making a Pivot Table out of this data range and then doing multiple selections thereof.
If you would like to accomplish this via formula, there is a two-step process.
THe formula described above needs to be placed next to each Person's name in Sheet1 as an additional column. And then run another COUNTIFS on this column and Column B counting that there is >1 Count for the person existing... and counting if the STAssess criterion is fulfilled or not.

comparing two columns in excel (VLOOKUP not working)

I have been breaking my head with this problem since morning and I haven't found a solution. Please give your valuable pointers if possible, so that I can try to find the solution.
I basically have two sets of data- an old list and a new list. I wish to compare the new list( comparing name and country together) with an old list, since the new list has a few additional entries. Later on, I would like to create a new list with common entries from both old and new list and add all the new entries below the common ones ( if possible, else I will do that manually later on but I would like Excel to tell me that this is a new entry). Sorry, if this has not been well explained, but maybe the following illustration helps
Old List
Item No. Name Country
1 Apples Italy
3 Banana Spain
4 Grapes Slovakia
5 Pineapple Greece
8 Banana Czech Republic
14 Apples India
23 Pineapple Hungary
19 Peach USA
2 Strawberries France
New List
Item No. Name Country
4 Grapes Slovakia
Mango Pakistan
14 Apples India
Oranges Mexico
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Avocado Netherlands
Expected Output:
List with common serial No.s based on common names from both lists
Item No.Name Country
4 Grapes Slovakia
14 Apples India
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Mango Pakistan
Oranges Mexico
Avocado Netherlands
As can be seen in this attachment, I have an old list with Item No., Name and Country. Let's assume that the item numbers have been classified based on some code words. In the second list, there are again Item No.s, Name and Country but some item numbers haven't been filled ( since they are new and have not yet been sorted). Now, I want Excel to compare the names AND countries of both data and provide the common Item No. output if there is a match. If there is no match, then I would like Excel to tell me that this is a new entry. I looked up on various forums and I realized that VLOOKUP command only allows me to search on Name OR Country would give me the common entries of Names/Countries respectively but not Item No.s. Is there any formula that could help me solve this problem?
Just paste the list together, then sort it, and then remove the duplicates. Removing duplicates is built-in into Excel starting from version 2007, you will find it in the Data ribbon (see http://office.microsoft.com/en-001/excel-help/filter-for-unique-values-or-remove-duplicate-values-HP010073943.aspx).
To use VLOOKUP just concatenate Name and Country, for example, B2 & "-" & C2. You can then do a lookup on the concatenated values in your source table:
VLOOKUP(B2 & "-" & C2,NewList!D2:E100,2,False)
This assumes that the concatenated column is in D in your new table, and that you've copied the numbers to column E (VLOOKUP can't look to the right). I put in the dash for readablility and to avoid the chance that a Country ends with a number, unlikely as that might be.

Count and average data inside categories under two types of conditions

I'm working on Excel with a lot of data and I'm having difficulty with knowing how to sort through it to get some important numbers. I have minimal Excel experience.
Right now I'm struggling with knowing how to get the average in the difference between two columns. The trick is that I have to get the average in difference when column A is less that column B and then, the same when it's more. And all that within a category.
So for example let's say I have 3 categories: Football, Soccer, and Basketball (these are just made up ones).
So in column A, I have: Soccer, Football, Basketball. Then, in column B and C, I have the scores for John and Adam for the last 3 months, respectively. Lastly, in column D, I have the differences between their scores.
So, for example:
Category John Adam Differences
Soccer 5 3 2
Soccer 6 2 4
Soccer 3 5 2
Soccer 4 0 4
I want to create a table for within each category I have a table like below:
NÂș of cases Avg. Difference between John and Adam
When John's score is >
When John's score is <
When they are equal
Is there some type of formula where I can say something like this:
If the category is Soccer (the category being in column A), take the difference between John's score (column B) and Adam's score (column C) when John's score is larger than Adam's score, then calculate the average of those differences? Then, I would use the same formula but tweak it when John's score is smaller.
Additionally, would there be a formula where I can also, calculate within the category Soccer, how many times John's score is bigger than Adam's?
My data is much larger and I can't do this manually.
A B C D
1 Sport John Adam Differences
2 Soccer 5 3 2
3 Soccer 6 2 4
4 Soccer 3 5 -2
5 Soccer 4 0 4
6 Basketball 20 15 5
7 Basketball 7 13 -6
8 Basketball 26 10 16
9 Basketball 8 11 -3
Type in D1:
=B1-C1
Drag the formula in Column D to all rows which there are values in columns A, B and C.
Create the PivotTable.
Drag Sport to "Row Label" field. Drag Differences to "Row Label" field under Sport.
Drag Differences to "Values" field as: Count of Differences (same way the previous question)
Drag Differences to "Values" field (below Count of Differences), and set the mathematical operation as "Average" of Differences (left-mouse click Differences, choose "Values fields settings" and select "Average").
Give a right-click mouse in cell A5 (see picture bellow) and select "Group" option.
Set "Starting at" = 0; "Ending at" = 1000; "By" = 1000 (as in the picture below). Click ok.
You will have in each Sport, the count (frequency) and average Differences values for two groups:
When the Difference B1-C1 is negative; and
When the Difference B1-C1 is zero or positive.
The average of Differences when the score is equal will be always zero.

Resources