Counting word "pairs" in excel between different columns - excel

I'm wondering if it's possible to do this in excel:
Let's say I have these columns:
Column A | Column B
Apple | Red
Apple | Green
Pear | Green
Pear | Green
Is it possible for me to count how many times a set of "pairs" appears.
For example -
I want to count how many times "pear" and "green" appeared in my spreadsheet next to each other (not individually).
So for the above I should get:
Apples + Red appears 1 time
Apples + Green appears 1 time
Pear + Green appears 2 times
I tried using the COUNTIF function, but I don't think it can count a set of pairs like this...
If the above is possible... is it further possible to break down the data by time? For example, we have these columns:
Column A | Column B | Column C
3/7/2013 | Apple | Red
3/7/2013 | Apple | Red
3/8/2013 | Apple | Red
3/8/2013 | Pear | Green
3/8/2013 | Pear | Green
3/9/2013 | Apple | Red
3/9/2013 | Pear Green
If I want to organize the data by day, how can I do this? For example:
I want to display that on 3/7/2013, Apple + Red appeared 2 times, but on 3/8/2013, Pear + Green appeared 2 times and Apple + Red only appeared once.
Is it also possible to organize data by weeks or months this way? (During the month of January, I got 20 Apple + Red "pairs"
Let me know if anything was unclear in what I was asking
Thanks for your help!!!!

Add a new column to your data, which concatenates your data (ideally with delimiters to avoid value clashes) e.g. In Col D1 put formula
=A1&"|"&B1&"|"&C1
Give it a heading of Vals, and then create your pivot table from all the data
As an example I created this sample data which has 2 employees, Fred & Bill and a number of rows for each on 2 days. For 3-Jul, both Fred and Bill appear 3 times, but on 4-Jul Fred appears once and Bill 5 times.
My pivot table shows this result (which is hopefully what you're after)
EDIT :
For your situation, you probably need two extra columns, one called 'Pair Name' which concatenates B & C, and another called 'Pairs' which concatenates A, B & C.
Then in your pivot table you can drag 'Pair Name' into the Column Labels, and 'Pairs' into the Sum of Values.

Related

How to map objects in Excel?

I am not sure if the title makes sense, but you can have a look at the example below. Considering I have a 2-column table in Excel like this:
Fruit | Amount
Apple | 2
Grape | 4
Orange | 3
Now I want to have this row:
Apple | Apple | Grape | Grape | Grape | Grape | Orange | Orange | Orange
that when I change the number from "Amount" column in the table, the row changes accordingly as well. For example, if I now have 5 Grapes, it would become:
Apple | Apple | Grape | Grape | Grape | Grape | Grape | Orange | Orange | Orange
Is it possible to do in Excel? I am fairly new with this. Thanks!
This can be achieved with a combination of
REPT - to generate the repated copies of the words
CONCAT - to join those repitions together
FILTERXML - to split the list into cells
TRANSPOSE - to return a row rather than a column
=TRANSPOSE(FILTERXML("<a>"&CONCAT("<b>"&REPT(B5:B7&"</b><b>",C5:C7-1)&B5:B7&"</b>")&"</a>","//b"))
Currently in BETA, but if available through insider's plan, try to use SCAN():
Formula in D1:
=XLOOKUP(SEQUENCE(1,SUM(B2:B4)),SCAN(0,B2:B4,LAMBDA(a,b,a+b)),A2:A4,,1)
Let me try and explain the steps:
The SCAN() functionality can be used to create a running total. A starting value of 0 will continue to grow through recursive LAMBDA() functionality. In the current example this will return {2,6,9}.
Now the idea is to find approximate matches using XLOOKUP(). The input for this function is an array created through SEQUENCE() where the amount of columns will equal the SUM() of all amounts. Thus; {1,2,3,4,5,6,7,8,9} in this case. Using the 5th parameter we can return the position of the exact or nearest higher value in the lookup array we found using SCAN(). The result: {1,1,2,2,2,2,3,3,3}.
The next and last step is also done in XLOOKUP() where we used A2:A4 inside the 2nd parameter to return elements from the previous found numeric indices. Obviously the result will then be {"Apple","Apple","Grape","Grape","Grape","Grape","Orange","Orange","Orange"} .
I tried to visualize the above in a process that may help a little.
And as your amount change, so does the output as required:
Here is a simple function to do a text multiple. You can then stack up the results.
Function TextMultiplier(MyText As String, MyMultiple As Integer)
Dim Output As String
For a = 1 To MyMultiple
Output = Output + MyText + " "
Next a
TextMultiplier = Trim(Output)
End Function
Here is how it looks:

Excel spreadsheet check two conditions along different rows & columns

Hey I'm really stuck on this one, basically tying to get a result of either 'hired' or 'available' (or 0 & 1 to represent) in B2, of BOTH the two conditions in B1 & A2, looking at the log table A6:B10 of when they are 'hired out'. I've tried VLOOKUP and many IF functions but neither quite work correctly.
One option here, though perhaps not the most graceful, would be to use VLOOKUP with the car and date as the key. The issue here is that there are multiple lookup values, namely the car and the particular date. To get around this, you could create a new column C which contains the concatenated car and date, e.g.
A | B | C | D
6 Car 1 | 03-01-2017 | Car 1 03-01-2017 | 0
7 Car 2 | 03-01-2017 | Car 2 03-01-2017 | 0
8 Car 3 | 04-01-2017 | Car 3 04-01-2017 | 0
9 Car 4 | 05-01-2017 | Car 4 05-01-2017 | 0
10 Car 2 | 06-01-2017 | Car 2 06-01-2017 | 0
To create column C, simply enter the following formula into cell C6 and then copy it down the entire column:
=CONCATENATE(A6, " ", B6)
Now you can use the following VLOOKUP formula in cell B2 to calculate whether a given ride is available on a certain date:
=IFERROR(VLOOKUP(A2&" "&B1,C6:D10,2,FALSE), 1)
Here I have hard-coded in column D the value 0 for every entry, to represent that these are rides which are already hired-out for that particular car and date. If our VLOOKUP formula finds a match, then it means the ride is hired-out. If VLOOKUP does not find a match, it would throw an error, in which case we display 1 to indicate availability.

Calculating part time and full time employees

I have three columns in Excel 2010:
Name
Activity
Person_Days
a pattern looks like this:
John | Activity_A | 2
John | Activity_B | 10
John | Activity_C | 5
Mary | Activity_A | 2
Mary | Activity_D | 12
...
I want to make an extra column that tells me if a person is working 1-30% of the time, 30-60% of the time or 60-100% of the time. Maximum number of person days is 18.
How can I make a formula in Excel which calcultes that?
How about try the SUMIF formula?
=SUMIF(A1:A5, "John", C1:C5)
The above would check cells in A1 to A5 for the value "John" and sum the contents of C1 to C5 where the A column value is "John".
Take that and work out your percentage using your 18 person days. Then just throw in some conditional formatting to show colours for your percentage breaks.
Above would need tweaked to give you exactly what you want but the core idea should work.
SF

How to automatically insert a blank row after a group of data

I have created a sample table below that is similar-enough to my table in excel that it should serve to illustrate the question. I want to simply add a row after each distinct datum in column1 (simplest way, using excel, thanks).
_
CURRENT TABLE:
column1 | column2 | column3
----------------------------------
A | small | blue
A | small | orange
A | small | yellow
B | med | yellow
B | med | blue
C | large | green
D | large | green
D | small | pink
_
DESIRED TABLE
Note: the blank row after each distinct column1
column1 | column2 | column3
----------------------------------
A | small | blue
A | small | orange
A | small | yellow
B | med | yellow
B | med | blue
C | large | green
D | large | green
D | small | pink
This does exactly what you are asking, checks the rows, and inserts a blank empty row at each change in column A:
sub AddBlankRows()
'
dim iRow as integer, iCol as integer
dim oRng as range
set oRng=range("a1")
irow=oRng.row
icol=oRng.column
do
'
if cells(irow+1, iCol)<>cells(irow,iCol) then
cells(irow+1,iCol).entirerow.insert shift:=xldown
irow=irow+2
else
irow=irow+1
end if
'
loop while not cells (irow,iCol).text=""
'
end sub
I hope that gets you started, let us know!
Philip
Select your array, including column labels, DATA > Outline -Subtotal, At each change in: column1, Use function: Count, Add subtotal to: column3, check Replace current subtotals and Summary below data, OK.
Filter and select for Column1, Text Filters, Contains..., Count, OK. Select all visible apart from the labels and delete contents. Remove filter and, if desired, ungroup rows.
This won't work if the data is not sequential (1 2 3 4 but 5 7 3 1 5) as in that case you can't sort it.
Here is how I solve that issue for me:
Column A initial data that needs to contain 5 rows between each number -
5
4
6
8
9
Column B -
1
2
3
4
5
(final number represents the number of empty rows that you need to be between numbers in column A) copy-paste 1-5 in column B as long as you have numbers in column A.
Jump to D column, in D1 type 1. In D2 type this formula - =IF(B2=1,1+D1,D1)
Drag it to the same length as column B.
Back to Column C - at C1 cell type this formula - =IF(B1=1,INDIRECT("a"&(D1)),""). Drag it down and we done. Now in column C we have same sequence of numbers as in column A distributed separately by 4 rows.
Figured it out.
Step 1
Put a new column to the left of column1 and copy+paste the following formula
=B2=B3
=B3=B4
=B4=B5
... all the way to the bottom (assume column B here is column1 in the original question).
This formula evaluates whether or not the next row is a new value in column1. Deopending on the result, you will have TRUE or FALSE. Copy and Paste these results as values and then swap "FALSE" for nil and "TRUE" for 0.5
Step 2
Then add that column full of only 0.5's to the column1 which will yield the following table:
newcolumn0 | column1 ("B") | column2 | column3
-----------------------------------------------------
| 1 | small | blue
| 1 | small | orange
1.5 | 1 | small | yellow
| 2 | med | yellow
2.5 | 2 | med | blue
3.5 | 3 | large | green
| 4 | large | green
4.5 | 4 | small | pink
Step 3
Lastly, copy and paste the values from newcolumn0 right below the values in column1 and then sort the table by column1 and you should have a blank row in between each distinct whole number in column1, with the table something like this:
newcolumn0 | column1 ("B") | column2 | column3
---------------------------------------------------------------
| 1 | small | blue
| 1 | small | orange
1.5 | 1.5 | |
| 1 | small | yellow
| 2 | med | yellow
| 2 | med | blue
2.5 | 2.5 | |
| 3 | large | green
3.5 | 3.5 | |
| 4 | large | green
| 4 | small | pink
4.5 | 4.5 | |
Alternative Solutions (still no VBA)
Put a value of 1 Column 1, Row 2 (assume this is A2)
Put this formula in A3 =IF(B3=B2,A2,A2+1) and copy+paste this formula for the rest of column 2
Then copy and paste all the values from column 1 into a new temp excel sheet, remove duplicates, then add 0.5 to all numbers, then paste these values below the values in original spreadsheet below the data in column 1, paste all data in column as values and then sort by that column, delete the temp excel sheet
Just an idea, if you know the categories, as small, medium, and large mentioned above...
At the bottom of the sheet, make 3 rows that only say small, medium, and large, change the font to white, and then sort so that it alphabetizes, placing a blank row between each section.
Insert a column at the left of the table 'Control'
Number the data as 1 to 1000 (assuming there are 1000 rows)
Copy the key field to another sheet and remove duplicates
Copy the unique row items to the main sheet, after 1000th record
In the 'Control' column, add number 1001 to all unique records
Sort the data (including the added records), first on key field and then on 'Control'
A blank line (with data in key field and 'Control') is added
I have a large file in excel dealing with purchase and sale of mutual fund units. Number of rows in a worksheet exceeds 4000. I have no experience with VBA and would like to work with basic excel. Taking the cue from the solutions suggested above, I tried to solve the problem ( to insert blank rows automatically) in the following manner:
I sorted my file according to control fields
I added a column to the file
I used the "IF" function to determine when there is a change in the control data .
If there is a change the result will indicate "yes", otherwise "no"
Then I filtered the data to group all "yes" items
I copied mutual fund names, folio number etc (no financial data)
Then I removed the filter and sorted the file again. The result is a row added at the desired place. (It is not entirely a blank row, because if it is fully blank, sorting will not place the row at the desired place.)
After sorting, you can easily delete all values to get a completely blank row.
This method also may be tried by the readers.

How to merge and sum 2 arrays using excel?

Given a .csv data file as follows
12,green orange
1,good egg
...
5,green orange
I want to sum-up the first column elements if the second column element is the same. Given the example above, now we should have
17,green orange
1,good egg
...
What is the easiest way to do this?
A good option would be to use a Pivot Table (this is practically what they are designed for).
In your case, look into the SUMIF formula - link as it doesn't seem you will need such advanced functionlaity.
Copy the list of "keys" (the items) into a separate worksheet and remove duplicates, then just setup SUMIF like:
key | total sum
green | = SUMIF(dataSheet!B:B, A2, dataSheet!A:A)
where you have this in a sheet, and dataSheet represents the CSV values you just imported.
Assuming you don't want to work with variables.
Count |Color
12 |Green
1 |Blue
5 |Green
7 |Green
3 |Blue
Sort the file by the value "Color"
Count |Color
1 |Blue
3 |Blue
12 |Green
7 |Green
5 |Green
Put Formula in cell C2 and paste down
=IF(B2=B1,(C1+A2),A2)
Harvest the sums at the end of each color (i.e. Blue = 4, Green = 24)

Resources