Excel: Derive Table column name with formula - excel

I have an Excel table called weather_data and it has a column for each month, e.g. "Jan", "Feb", etc.
In another sheet, I have one column with various dates listed and in a second column I want to use a formula to extract data from weather_data. Right now this second table looks like this:
Date Avg_Temp
Jun
Jul
Aug
E.g. if I want to fill in the first entry under Avg_Temp using data from weather_data, which again has a column for each month, I could manually enter =AVERAGE(weather_data[Jun]). However, I was hoping I could make the column reference (Jun in this case) formula driven from the Date column, so I could do something like =AVERAGE(weather_data[A2]) and copy it down.
Is this possible?

Assuming your weather_table starts with January in column 1 and has December in column 12, you can do a formula like this in B2 and copy down:
=AVERAGE(INDEX(weather_data,0,MONTH("1/"&A2)))
This has two interesting parts. The 0 in the row argument of the INDEX formula means to select the entire column. And munging "1/" with the month text in column 1 converts it to a date that can be read by the MONTH function, which then returns the month's number. This is used as the column argument of the INDEX function.
EDIT: Here's one that matches the three-letter month abbreviation in column A of your summary sheet to those in the table headers. This removes the requirement that the table contain only ordered months:
=AVERAGE(INDEX(weather_data,0,MATCH(A2,weather_data[#Headers],0)))
If you wanted to take it a step further and match on just a part of the table header, I wrote a post about that.

Related

Modify and transpose large dataset in Excel

I am trying to convert a database that consists of hourly data on annual basis from 00:00 (hour) 01 (month) 2015 (year) to 00:00, 01-12-2021.
Default format of the table:
In the default format, one column contains both hour and date and the second contains the value. There are more than 60000 rows.
What I expect:
In the expected format, the first column contains only the date while the first row contains the hours. I want to write a formula (maybe with transpose?) that transfers for each date and hour the value to the new cell.
For example, for 02-01-2021, at 01:00, the corresponding value is 52.42. To do this I click "TRANSPOSE(AD27:AD50)" and the row is filled. AD is the column location of the default format.
Unfortunately when I click with my cursor to the 3rd row (where 02-01-2021 is located) and drop it down to pass it to the next row, Excel does not recognize the pattern.
While Excel should start from the last selected column and transpose the next 23 cells (AD51:AD74) it goes like this (AD28:AD51).
In the third picture you see:
With the red pen: The old format. Date and time are in the same cell (column AC).
With the black pen: Date has been split from time. Date is in a column A while time is in row 1.
With the blue pen: The cells I want to fill by transferring the data listed in the table (pinpointed by the red pen).
In version 2202, you should have the more recent functions, so a simple method would be:
select some cell in your date/time table
Home/Format as table
Then:
E2: Enter a list of the dates only from your table.
*This can be done in various ways*
F1: Enter a list of the hours from left to right (or use the `SEQUENCE` function to generate them)
F2: =TRANSPOSE(FILTER(Table1[Value], DATEVALUE(TEXT(Table1[DateTime],"m/d/yyy"))=$E2,"")) and fill down as far as needed
The results will spill right.

Reverse array list dynamically

I have an array list in column A (starting in A2) using:
{=IFERROR(INDEX(MonthSpend,MATCH(0,COUNTIF($A$1,A1,MonthSpend),0)),""}`
Where MonthSpend is a named range from a table on a separate sheet.
I have copied the formula down to A300, but inserted blanks in a number of rows.
From the picture you will see that I have each month showing up only on every 6th row. The formula in A8 is:
{=IFERROR(INDEX(MonthSpend,MATCH(0,COUNTIF($A$1:A2,MonthSpend),0)),"")}
and in A3:A7 there is nothing).
I named this range in column A MonthAcc.
In column B (starting in B2), I tried using:
=IF(MonthAcc>10,INDEX(MonthAcc,COUNTA(MonthAcc)+ROW(MonthAcc)-ROW(),1),"")
to reverse this list.
This didn't work because the reversal function in B2 references a row near the bottom of the MonthAcc list, which is blank.
I'm trying to get it so that in B2 (in the picture below) it would have January 1, 2020 and then in B8 it would have December 1, 2019 and then in B14 it would have November 1, 2019 and so on.
The list MonthSpend is dynamic so can be totally different lengths.
How do I reverse my dates but keep it starting at the top and only every 6th row?
In the second picture you will see a column called Month. It uses the function =IF(E3="","",DATE(YEAR(C3),MONTH(C3),1)) starting in F3 and copied down the entire table. This is the named range MonthSpend. It is dynamic in that for a different project, you could have dates ranging from April 2017 to January 2020 etc. So the months that show up in the Month column, are what I want in my new reversed list, spaced 6 rows apart.
With the column Week ending you can use the following formula:
=IF((MOD(ROW()+4,6)=0),LOOKUP(2,1/(COUNTIF(C$1:$C1,$A$2:$A$25-DAY($A$2:$A$25)+1)=0),$A$2:$A$25-DAY($A$2:$A$25)+1),"")
It returns distinct dates from list converted to first day of month (you can also convert to other formats using the appropriate functions.) in reverse order every sixth row. Dates must be sorted in source column in ascending order. BUT! For empty cells it returns first day of XX century, so I enter that date manually to C2, if it bothers, it can be hidden

How do I write an excel formula to count the number of a value in one column based off of a date in another column?

I have a worksheet and I'm trying to do a simple Count function, probably a countif but I'm unsure how to go about writing the formula.
I have two columns that I'd like to use for this formula.
Column N - I would like to filter for the Criteria of "C" or anytime a cell has a value of C
Column 0 - This column has dates filled in (short date format).
I would like to get a count of every C for each month, as simple as that.
In this example I filtered the date for May of 2017 and filtered for C under the Check column. We can see that there are 12 instances of C showing in the month of May 2017.
Does anyone know how to structure a formula that I would be able to Count the Number of C's for every month into the foreseeable future?
I figured out how to count the total present in a date range but unsure of how to add the date range plus Column N (Check) every time "C" is present in the cell.
=SUMPRODUCT((O:O>=DATEVALUE("5/1/2017"))*(O:O<=DATEVALUE("5/31/2017")))
Try this
=COUNTIFS(O1:O100,">="&A1,O1:O100,"<"&B1,N1:N100,"C")
Where A1 has the start date and B1 has the end date for that month. You can use DATEVALUE() instead of A1 and B1. Change as applicable
Screenshot
If you want to use SUMPRODUCT then see this
=SUMPRODUCT((O:O>=DATEVALUE("1/5/2017"))*(O:O<=DATEVALUE("30/5/2017"))*(N:N="C"))
In another column (lets say 'P' for example) I would insert a formula to give you the month number =Month(P7) - this will return 5 for May.
I would then use COUNTIFS (Like COUNTIF but it uses multiple criteria) to count where column N contains 'C' and column 'P' contains '5'.
=COUNTIFS(N:N,"C",P:P,5)
Try this....you need to select the entire Column B and named the column as 'Date'.enter image description here

How to retrieve specific information from a column and show its number of occurrences

I have a column which contains dates. I want to search this column and find the total entries for each month, and summarize the sum in a nice display. Example:
I want to display the number of times 'Disposition Verification Dates' occur in each month and summarize ("count") them in a format which follows:
I want to make several rows with the same concept in the same table for my other columns.
How do I do this? (PivotTables, VBA, IF statements?)
I would suggest adding a helper column which you can hide. See the formula in cell C1.
For the January column I used the following formula:
=COUNTIF($C$1:$C$7, 1)
February is:
=COUNTIF($C$1:$C$7, 2)
and so on. You can also use the YEAR function and convert the countif into a COUNTIFS function based on the other year helper column.
No VBA needed. No helper column needed. No Pivot Table needed.
In addition to Yaegz provided, and my comments, you can use an array formula.
Assuming your data is column A and you type Jan Feb Mar ... Dec into cells B1:N1, you can enter the following formula in cell B2.
=COUNT(IF(TEXT($A$2:$A$13,"mmm")=B$1,$A$2:$A$13))
Then press Ctrl + Shift + Enter (to make it work as an array) and you will have your summary done.

Count number of occurrences by month

I am creating a spreadsheet with all my data on one sheet and metrics on the other.
On sheet 1 in cells A2:A50 I have the dates in this format (4/5/13). On sheet 2 in cell E5 I have April and I want it to total the number of PO's created in F5.
How can I do this?
I have tried using
=COUNTIF('2013'!$A$2:$A$50,'2013 Metrics'!E5).
I have a feeling that since my range is in 4/5/13 format and my criteria is April that won't work.
I was able to use this formula for total spend by month:
=SUM(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
but not luck with how many PO's by month.
Use a pivot table. You can manually refresh a pivot table's data source by right-clicking on it and clicking refresh. Otherwise you can set up a worksheet_change macro - or just a refresh button. Pivot Table tutorial is here: http://chandoo.org/wp/2009/08/19/excel-pivot-tables-tutorial/
1) Create a Month column from your Date column (e.g. =TEXT(B2,"MMM") )
2) Create a Year column from your Date column (e.g. =TEXT(B2,"YYYY") )
3) Add a Count column, with "1" for each value
4) Create a Pivot table with the fields, Count, Month and Year
5) Drag the Year and Month fields into Row Labels. Ensure that Year is above month so your Pivot table first groups by year, then by month
6) Drag the Count field into Values to create a Count of Count
There are better tutorials I'm sure just google/bing "pivot table tutorial".
For anyone finding this post through Google (as I did) here's the correct formula for cell F5 in the above example:
=SUMPRODUCT((MONTH(Sheet1!$A$1:$A$50)=MONTH(DATEVALUE(E5&" 1")))*(Sheet1!$A$1:$A$50<>""))
Formula assumes a list of dates in Sheet1!A1:A50 and a month name or abbr ("April" or "Apr") in cell E5.
Make column B in sheet1 the dates but where the day of the month is always the first day of the month, e.g. in B2 put =DATE(YEAR(A2),MONTH(A2),1). Then make E5 on sheet 2 contain the first date of the month you need, e.g. Date(2013,4,1). After that, putting in F5 COUNTIF(Sheet1!B2:B50, E5) will give you the count for the month specified in E5.
I would add another column on the data sheet with equation =month(A2), then run the countif on that column... If you still wanted to use text month('APRIL'), you would need a lookup table to reference the name to the month number. Otherwise, just use 4 instead of April on your metric sheet.
use count instead of sum in your original formula u will get your result
Original One
=SUM(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
Modified One
=COUNT(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
AND USE ctrl+shift+enter TO EXECUTE
Recommend you use FREQUENCY rather than using COUNTIF.
In your front sheet; enter 01/04/2014 into E5, 01/05/2014 into E6 etc.
Select the range of adjacent cells you want to populate. Enter:
=FREQUENCY(2013!!$A$2:$A$50,'2013 Metrics'!E5:EN)
(where N is the final row reference in your range)
Hit Ctrl + Shift + Enter
Sooooo, I had this same question. here's my answer: COUNTIFS(sheet1!$A:$A,">="&D1,sheet1!$A:$A,"<="&D2)
you don't need to specify A2:A50, unless there are dates beyond row 50 that you wish to exclude. this is cleaner in the sense that you don't have to go back and adjust the rows as more PO data comes in on sheet1.
also, the reference to D1 and D2 are start and end dates (respectively) for each month. On sheet2, you could have a hidden column that translates April to 4/1/2014, May into 5/1/2014, etc. THen, D1 would reference the cell that contains 4/1/2014, and D2 would reference the cell that contains 5/1/2014.
if you want to sum, it works the same way, except that the first argument is the sum array (column or row) and then the rest of the ranges/arrays and arguments are the same as the countifs formula.
btw-this works in excel AND google sheets. cheers

Resources