Combine two rows of strings in a specific order using formulae - excel

I have a column in on sheet like this:
Barbie
HeMan
Superman
Batman
and another column in another sheet like this:
Madrid
Barcelona
Athens
London
Timbuktu
I need output as below (preferably two columns, alternatively space separated in one):
Barbie Madrid
Barbie Barcelona
Barbie Athens
Barbie London
Barbie Timbuktu
HeMan Madrid
HeMan Barcelona
HeMan Athens
HeMan London
HeMan Timbuktu
How can this be done using Excel formulae please?

This solution assumes the following:
Data with “Super Heroes” is located in Sheet1 at B6:B9 (adjust ranges in formulas as required)
Data with “Cities” is located in Sheet2 at B6:B10 (adjust ranges in formulas as required)
Data combined is located in Sheet3 starting at B6 (adjust ranges in formulas as required)
Enter this formula in Sheet3 at B6 and copy till last record (i.e. ~ B31)
=IFERROR( INDEX( Sheet1!$B$6:$B$9,
ROUNDUP( ROWS( B$6:B6 ) / ROWS( Sheet2!$B$6:$B$10 ), 0 ) ), "" )
and this formula in Sheet3 at C6 and copy till last record (i.e. ~ C31)
=IF( EXACT( B6, "" ), "", INDEX( Sheet2!$B$6:$B$10,
1 + MOD( -1 + ROWS( C$6:C6 ), ROWS( Sheet2!$B$6:$B$10 ) ) ) )

Assuming that the first and second of your lists are in column A of Sheet1 and Sheet2 respectively, and that there are no other entries in those columns apart from the data you wish to be returned, then, in cell A1 of your worksheet chosen to house the results:
=IF(ROWS($1:1)>COUNTA(Sheet2!A:A)*COUNTA(Sheet1!A:A),"",INDEX(Sheet1!A:A,CEILING(ROWS($1:1)/COUNTA(Sheet2!A:A),1)))
And in B1:
=IF(A1="","",INDEX(Sheet2!A:A,1+MOD(ROWS($1:1)-1,COUNTA(Sheet2!A:A))))
Copy both down until you start to get blanks for the results.
Regards

Related

Get dollar value from adjacent cell where day of month is in a date range

I have an excel workbook with two worksheets.
One holds static values that lists bill due each month, with a day of month column as an integer (or it can be, right now its attached to a string), a bill name column as a string and a dollar amount. I would like to pull the bill name and the amount if the day of month falls within a date range on the other sheet.
The other sheet lists out a date range of a week for the whole month, and includes the name of the bill, and the amount due during that week. I would like to automatically populate those columns using values from my static sheet, where the day of month in the static sheet falls between the date range in the month sheet. I have attached screen shots of what I am aiming for. This is simply sample data. I would like the month sheet columns(Both bill name and amount) to be auto populated when I enter dates in the header columns from the static sheet.
Assume the static values sheet is named "Static", and the month sheet is named "December".
I would be happy to provide more information/images/sample files as needed. This is a hobby of mine, and questions, discussion, criticism is encouraged.
Update
With the formula posted by mark, this works flawlessly when the date ranges are within the same month.
=LET( st, H1, fn, I1,
expenses, $D$3:$F$10,
na, INDEX( expenses, SEQUENCE( ROWS( expenses ) ), {1,2}), d, INDEX( expenses,, 3),
FILTER(na, (d>=DAY(st))*(d<=DAY(fn)) ) )
However, when the date ranges include a month change for example: December 30 through January 5th, Excel shows an error "Empty arrays are not supported".
With Office 365, you can do:
=LET( st, H1, fn, I1,
expenses, $D$3:$F$10,
na, INDEX( expenses, SEQUENCE( ROWS( expenses ) ), {1,2}), d, INDEX( expenses,, 3),
FILTER(na, (d>=DAY(st))*(d<=DAY(fn)) ) )
where H1 is your starting date of the period, I1 is the finishing date and D3:F10 is the array of Name, Amount and Day of month as you have shown.
This formula will spill the results with Name and Amount. It can be copied to other cells as you have shown in your Sheet2 example (i.e., A3, D3, G3... in Sheet2).
If you don't have Office 365, it will be harder.
Version II - Account for month cross over
This will accommodate the crossover of the month. Did not think about that...
=LET( st, H1, fn, I1,
expenses, $D$3:$F$10,
s, DAY( st ), f, DAY( fn ),
na, INDEX( expenses, SEQUENCE( ROWS( expenses ) ), {1,2}), d, INDEX( expenses,, 3),
b, IF( MONTH(st) = MONTH(fn), (d>=DAY(st))*(d<=DAY(fn)), (d>=DAY(st))*(d<=DAY(EOMONTH(st,0))) + (d>=1)*(d<=DAY(fn)) ),
FILTER(na, b ) )

Excel: Transpose data from rows to column headings

My problem, as the title states, has to do with transposing data from rows to columns
The original data came into a csv format where in the second column 'Dates and Rank' semicolons and spaces acted as delimiters.
Country Dates and Rank
Switzerland [2014-03-07] 7;[2014-10-17] 7;
USA [2011-07-01] 7;[2012-02-17] 7;[2012-09-30] 7;[2013-01-31] 7;
France [2011-07-01] 4;[2012-02-17] 4;[2012-09-30] 4;
China [2015-01-16] 7;[2015-03-06] 7;[2015-10-16] 7;[2015-10-23] 7;
So, by using the Text to Columns function from excel I separated the data within 'Dates and Rank' column into different cells. And now the result looks like this:
Country Dates and Rank C D E F G H I
Switzerland [2014-03-07] 7 [2014-10-17] 7
USA [2011-07-01] 7 [2012-02-17] 7 [2012-09-30] 7 [2013-01-31] 7
France [2011-07-01] 4 [2012-02-17] 4 [2012-09-30] 4
China [2015-01-16] 7 [2015-03-06] 7 [2015-10-16] 7 [2015-10-23] 7
*I have also deleted the square brackets from the dates and I assigned them as YMD cells.
But what I need to do now is to use the dates as headings while I use the rank (1-7) as their allocated data within the cells. For example:
Country 2011-07-01 2012-02-17 2014-03-07 2014-10-17
Switzerland 6 7
USA 5 7
Any suggestions please?
Thank you.
I'll assume your data starts in cell A1 (i.e. A1 contains "Country").
First, create a new worksheet where your newly ordered data will come. You first need to fill in the column header row. You can do this by
manually copy-pasting all the date columns from your original data to a single column in the new worksheet, so that all dates are in one column
Remove duplicates (in the ribbon: Data > Data Tools > Remove Duplicates)
Sort the list if you want (Data > Sort & Filter > Sort)
Select the resulting data, copy, and transpose-paste in cell B1 (Home > Paste > Paste Special, and check the box "transpose"). Now you can also remove the data you just copied.
Second, copy-paste column A of the source worksheet into column A of the destination worksheet.
Finally, for each country and each date you want to look up the data right next to the date. You can do this by using the following formula in B2:
= IFERROR( INDEX( Sheet1!2:2, 1, MATCH( B$1, Sheet1!2:2, 0 ) + 1 ), "" )
Finally, copy this formula down and across.
This should do the trick just fine, but it is not a very flexible solution and you need to follow the steps exactly as explained. For example, if the countries are in a different order than they are in your original data sheet, it won't work.

Count If with multiple criteria and unique values

I have a sheet of data and want to run a count on the values in Raw data with the following criteria:
If the value in raw data is repeated FOR EXAMPLE London No1 and London No1 AUTO only to be counted once, but if the value in raw data is London No1, London No2 and London No1 Auto then only to count 2 (to count London No1 and London No2 only).
Raw data
London No1
London No2
London No1 Auto
London No2 Auto
Bristol No1 Auto
Cardiff No1
Cardiff No2
In this example Result should be: London - 2, Bristol - 1, Cardiff - 2.
This solution uses only one "working column" and assumes the following:
The list of Raw Data is located at A1:A16 (adjust as required)
The Raw Data records follow this syntax City NoX string all separated by a blank space. X is one digit number (do let me know if there will be larger numbers in order to adjust the formula)
(All ranges include header)
With the list of results located in the same worksheet at B1:D16
(adjust as required) and including the following fields:
Site: List of Cities to count in Raw Data
Unique Record: Used to list unique "clean" city records before counting. Enter this FormulaArray in D2 and copy till last record
(Formulas Array are entered by pressing [Ctrl] + [Shift] + [Enter]
simultaneously)
=IFERROR( INDEX(
MID( $A$2:$A$16, 1, 2 + FIND( "No", $A$2:$A$16 )),
MATCH( 0, COUNTIF( D$1:D1,
MID( $A$2:$A$16, 1, 2 + FIND( "No", $A$2:$A$16 ))), 0 ) * 1 ), "" )
Result Count: Enter this FormulaArray in C1 and copy till last record
=IF( EXACT( $B2, "" ), "",
IFERROR( COUNTIF( $D$2:$D$16, $B2&"*" ), "" ))
Assumptions
So if I understand your clarifications, you have a list of cities, and each city might have a different "No" on it. ie: some will be "No1", "No2", etc. Also, some might have "Auto" on it. There are sometimes duplicates, ie: "London No1" might appear twice. Also, whether or not the word "Auto" appears, it will be a duplicate if that "No" already appears. ie: "London No1" is identical to "London No1 Auto".
Helper Columns
To count how many unique instances of each city there are, I propose you use a helper column which first removes the word auto, and then only displays itself if it is not a duplicate of a prior entry.
With your data in column A, starting at A2, enter this formula in B2 and copy down:
=IF(ISERROR(MATCH(TRIM(SUBSTITUTE(A2,"Auto","")),$B$1:$B1,0)),TRIM(SUBSTITUTE(A2,"Auto","")),"")
This formula works as follows:
-First it takes the text in A2, and it replaces the word "Auto" with "". Then it TRIMS the resulting text, which means it earases any trailing spaces at the end. It takes that trimmed text, and attempts to MATCH it with the previous rows in column B. If it doesn't find a match, it results in an error. IF it ISERROR, then it shows the text (because it's the first time it has appeared). Otherwise, it shows "".
Array Formula
Now that you have this in column B, we will use Array Formulas to count how many unique instances of each city appeared. An Array Formula is a specific formula which calculates many time over an entire range, instead of just one cell. It then returns an Array of results, which we need to collapse into a single answer. For example:
=SUM(IF(A1:A5>5,B1:B5,""))
[Confirmed with CTRL + SHIFT + ENTER instead of just ENTER]
In the above example, the Array Formula will check if each individual cell from A1:A5 is a number larger than 5. If it is, it will return the cell from column B in that row. It then takes all resulting answers from column B (where A was > 5), and SUMS them to a single number.
In this case, the Array Formula will be as follows [Starting in D5 in your image and moved one column to the right, immediately to the right of the first city name, and copied down for each city; I am assuming that your raw data goes from A2:A100]:
=SUM(--NOT(ISERROR(SEARCH(C5,$B$2:$B$100))))
Confirm this formula with CTRL + SHIFT + ENTER instead of just ENTER. Then copy down for each city name in column C.
It works by attempting to search each unique value in column B for the city name shown in that row of column C. Wherever it the city name is not present, ISERROR returns TRUE for that element of column B. Then NOT turns all TRUEs to FALSEs and vice versa. Then the -- tells excel to convert TRUE and FALSE to their numerical equivalents [1 and 0, respectively]. So we will have a TRUE [AKA 1] for each match, and FALSE [AKA 0] for everything else. The sum of all 1's is the number of matches of that city name in your list of unique entries.

How Can I Change Repeating date to one in excel?

I have below question:
On column A1: A16, I have some repeated dates.
On column B1:B16, I have the numbers which are assigned each one only to a date on column A. For instance, B1 to A1, B2 to A2 and etc.
I copy column A to column C and use from Data – Remove Duplicates.
Now, I want to have total sum of numbers which are assigned to each exact date on column D (front of column C).
I have attached an example of excel sheet.
How can I do?
4/4/2015 20000000 4/4/2015 94010000
4/4/2015 9510000 4/9/2015
4/4/2015 50000000 4/13/2015
4/4/2015 14500000 4/14/2015
4/9/2015 200000000 4/19/2015
4/9/2015 200000000 4/27/2015
4/13/2015 672716000
4/14/2015 28448000
4/19/2015 26168000
4/19/2015 26168000
4/19/2015 18568000
4/19/2015 18568000
4/27/2015 41368000
4/27/2015 13500000
4/27/2015 200000000
4/27/2015 52926000
Extract Unique Items and Corresponding Totals
Assuming that your data is located as follows:
Dates range B7:B21 and Amounts range C7:C21
To extract a list of unique dates enter this FormulaArray in E7 and copy till last record:
(Formulas Array are entered by pressing [Ctrl] + [Shift] + [Enter] simultaneously)
=IFERROR( INDEX( $B$7:$B$21, MATCH( 0, COUNTIF( $E$6:$E6, $B$7:$B$21 ), 0 ) * 1 ), "" )
Then to have the total amount for each date in the next column enter this formula in F7 and copy till last record:
=IF( EXACT( $E7, "" ), "", SUMIF( $B$7:$B$21, $E7, $C$7:$C$21 ))

Formula to pull all data for Top 25

I've following data set and I've used Index- Large function
=LARGE(INDEX(($A$2:$A$99)*($B$2:$B$99={"x","y"}), , ), ROW(1:1))
... to find out Top 25 of x and y combined. How would I pull the Column that has listed fruits? I can't use Large since it's for Numbers only. I've 20 more columns that have text only. Any thoughts?
apple 100 x
banana 50 y
grapes 6 z
watermelon 89 x
cantaloupe 5 x
orange 24 y
You need to adjust the formula you provided for the correct columns first.
=LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))
When that is done, it can be used as matching criteria in a larger formula that also matches column C for x, y.
=IFERROR(INDEX(A$2:A$99, MIN(INDEX(ROW($1:$98)+(($C$2:$C$99<>{"x","y"})+($B$2:$B$99<>LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))))*1E+99, , ))), "")
In the sample image below, that formula would go into E4. Fill both right and down as necessary.
      
If the values in the nmbr column may be duplicated (while still matching {x, y}) then one formula cannot be used for the entire lookup table. Use the following in F4.
=LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))
E4 would be,
=IFERROR(INDEX(A$2:A$99, SMALL(INDEX(ROW($1:$98)+(($C$2:$C$99<>{"x","y"})+($B$2:$B$99<>LARGE(INDEX(($B$2:$B$99)*($C$2:$C$99={"x","y"}), , ), ROW(1:1))))*1E+99, , ), COUNTIF($F$4:$F4, $F4))), "")
Copy and paste E4 to G4 then select E4:G4 and fill down.
      
Note that when transcribing the formula for your own use, ROW(1:98) is the position within A2:A99, not the actual row on the worksheet.

Resources