Let's say I have an Excel sheet like the below:
states incidents years
1 Texas 1 2000
2 Texas 1 2008
3 Arizona 2 2004
4 California 1 2002
5 California 4 2007
I want to create new rows with the value of 0 for states which had no incidents. For example, I'll create seven new rows for Texas, indicating that it had zero incidents from 2001 to 2007. Arizona will have eight new rows (for all years from 2000 to 2008, except 2004).
How can I do this in Excel? Obviously I can do it manually but I'm wondering if there's a way to automate the process.
Make a new table on Sheet2 that fills up with either data from the first table or with zeros.
For the 2-D version: Put the state in the top row and the year on the left row. Fill the data with an equation like this (starting in cell B2):
=iferror(index(Sheet1!$C$2:$C$6, match(B$1 & "_" & $A2, Sheet1!$B$2:$B$6 & "_" & Sheet1!$D$2:$D$6, 0)), 0)
When you type the formula, accept it by hitting ctrl+shift+enter. This is an array function.
For the 1-D version, put the state in column A and the year in column B. Now make column C:
=iferror(index(Sheet1!$C$2:$C$6, match($A$ & "_" & $B2, Sheet1!$B$2:$B$6 & "_" & Sheet1!$D$2:$D$6, 0)), 0)
(Don't forget to hit ctrl+shift+enter)
If you format the original data as a Table by using Insert > Table, you will see that the formulas you type get replaced with clever column titles... this will make the entire table's data available to the formula, no matter how much data gets added. Very useful.
Related
I have an excel sheet where I need to take an average cost of 7 days. I have two columns, one with a date and the other with a charge. See the attached screenshot for reference and output. The formula I'm using for charges works as expected in column d. I need to find a way to add the date range in column c. Please advise
Date: Need help here - Column c should repeat, and the next cell should have 2022-08-02 and 2022-14-02. The current formula starts on 2022-02-02 if I drag the cell.
Try below formula to google-sheet.
=INDEX(TEXT(A2+SEQUENCE(10,1,0,7),"yyyy-dd-mm") & " " & TEXT(A2+SEQUENCE(10,1,6,7),"yyyy-dd-mm"))
For Excel-365 no need INDEX().
=TEXT(A2+SEQUENCE(10,1,0,7),"yyyy-dd-mm") & " " & TEXT(A2+SEQUENCE(10,1,6,7),"yyyy-dd-mm")
I have a table with two active columns. In Column A I have all the dates between, let`s say, January 1, 2012 to December 31, 2019. In column B I have a corresponding name. For instance:
[
etc.
I want to create ranges based on criteria, like:
The trick is, this should be done by calendar year, which means that during the 8-year period, I should have 8 set of 3 columns (from / to / name), one for each calendar year. If one range covers two years (let's say, November 1, 2012 to February 1st, 2013), the last row of 2012 should read
2012-11-01 to 2012-12-31
while the first row of 2013 will read
2013-01-01 to 2013-02-01
I managed to separate the ranges, but for some reason I am not able to go further and do that for each calendar year. Is there a way to do that?
Let's assume you want to place your 8 set of 3 columns starting from column G and that your list in the range D:F has headers in row 1 and data from row 2 on. In cell G1 write down your first year (2012), in cell H1 "From", in cell I1 "To" and in cell J1 "Name".
Now in cell H2 write this formula:
=IF(IF(OR(IF(AND($E2>=DATE(G$1,1,1),$D2<=DATE(G$1,12,31)),1,0),IF(AND($D2>=DATE(G$1,1,1),$E2<=DATE(G$1,12,31)),1,0)),1,0),MAX($D2,DATE(G$1,1,1)),"")
In cell I2 write this formula:
=IF(IF(OR(IF(AND($E2>=DATE(G$1,1,1),$D2<=DATE(G$1,12,31)),1,0),IF(AND($D2>=DATE(G$1,1,1),$E2<=DATE(G$1,12,31)),1,0)),1,0),MIN($E2,DATE(G$1,12,31)),"")
In cell J2 write this formula:
=IF(AND(H2<>"",I2<>""),F2,"")
Drag the 3 of them all the way down accordingly to your need. You can then copy the G:J range and paste any time you need next to itself; just change the year in the top left cell and it should do the trick.
Report any question you have or bug you have encountered. If, according to your judgment, this answer (or any other) is the best solution to your problem you have the privilege to accept it (link).
I would like to look up a value in a range and return the value in the next row, but can't quite figure out how to do this. I especially would like to do this with formulas rather than VBA, and preferably with built-in formulas than custom (VBA) formulas, due to macro security issues.
I'm using Excel 2010. My workbook has two worksheets, "assessment" and "lookup". In lookup, I have lookup tables.
"lookup" looks something like:
Column A Column B Column C
1 Sales Engineering Manufacturing
2 Alice Bobbie Charlie
3 Dawn Edgar Frank
4 George Holly Isabel
In "assessment," I have some some drop downs from which users select one name from each column in "lookup." Based on some other criteria, I then rank these and create a new, sorted list (using INDEX() and MATCH()) that produce the selected name and corresponding column name a new sort order
Column A Column B
10 Engineering Edgar
11 Sales Alice
What I'd like is to return the name from the next row.
Column C
10 Holly
11 Dawn
But I'm having real trouble figuring out how to get there.
Assuming lookups is located at B2:D5 (change as required) and the result data is at F2:H3 (change as required) enter this formula in cell H2 then copy down.
=INDEX(
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),
1+MATCH($G2,
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),0))
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.
I need to sum the valumes of a column, but I need to identify the column based on two values in the column and I have to filter it by the values in two adjecent columns.
Here is an example:
Reference1 Act. Act. Act. ... Bud. Bud. Bud.
Reference2 Jan Feb Mar ... Jan Feb Mar
Reference3 Reference4
CAR BLUE 1 2 3 4 5 6
CAR BLUE 1 2 3 4 5 6
CAR RED 1 2 3 4 5 6
So, I have to add all the CAR & BLUE & Act. & Jan = 1+1 = 2. And similarly for the other columns.
I would like to achieve something as follows:
Reference3 Reference4 Reference1 Reference2 Value
CAR BLUE Act. Jan 2
CAR BLUE Act. FEB 4
The problem I have is that formula to use in the Value column above. I can not do a SUMIFS as the columns in the original source table change. A VLOOKUP don't work as there is no single column for the lookup_value. I thought about using MATCH to identify the column, but as I have two references(1&2) it doesn't work either.
Any ideas on what formula(s) I could use to achive the above.
Thanks
Try making a pivot table from your data (this will not make formulas, though, but will nevertheless give you the desired results).
Here is a simple guide on doing that in Excel 2003 - http://www.techonthenet.com/excel/pivottbls/create.php
You can create a Key in a column:
= Reference3 & Reference4 & Reference1 & reference2
and after use the Subtotal command (Inside Data).
Every time you modify the data, you need to reuse Subtotal