Modify and transpose large dataset in Excel - 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.

Related

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

Excel: Derive Table column name with formula

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.

Excel Convert Now() to a Number to compare against another Number

I am trying to use some logic in a spreadsheet without any macros.
First I have a sinle cell that gives the date and time. I then used the custom format on that cell to just show the "h". So only hour numbers 1 through 24 appear in this cell. (e.g. at 3:20 p.m. I get 15 in the cell). (Cell # A:1)
=now()
Second, I have a separate single column with 24 rows numbered 1-24 (Cell #'s B1:B24)
I have a third column that has logic that states "Night" shift" for numbers 23 & 0-6; "Day Shift" for numbers 7-14; and "Mid Shift" for numbers 15-22) (Cell #'s C1:C24)
=if($A$1=B1,"Night Shift","")
However, the third columns all appear blank even tough one should appear. I tried changing A1 using text(A1,"#") but I get the serial number. Is there an easy way to dynamically have a value in column C show what shift based off the hour of the day in cell A1. Column D simply concatenates all 24 cells since there will only be one number ever. (Cell # D1). Thanks for any help.
You could use a LOOKUP formula to return the shift based on a time/date value in A1, e.g.
=LOOKUP(HOUR(A1),{0,7,15,23;"Night","Day","Mid","Night"})&" Shift"
Changing the format of the cell containing the date and time does nothing to the actual contents of the cell. It will still contain a value such as 43706.75 (number of days and fractions of days since 1/1/1900).
If what you want to do is determine the shift for the date/time in A1, you could use a formula like:
=IF(AND(HOUR(A1)>=7,HOUR(A1)<15),"Day Shift",IF(AND(HOUR(A1)>=15,HOUR(A1)<23),"Mid Shift","Night Shift"))
And similar logic if you need to apply different multipliers for the salary.
If you need something else, be more specific.
By doing =now() without any formatting you get the Date and the Time. Then in cell A2 do
=(A1-INT(A1))*24
Then in cell A3 do
=INT(A2)
This gives you the hour number extracted from a date format so a comparison can be made in column C against the numbers in column B. Thanks.

How to duplicate and show a specific row in new address in excel 2007

I use excel 2007
i made a table with few columns but too many rows. Each row contains some data and simple formulas.Now I want to duplicate a specific row based on current date [TODAY()] at top of the sheet.I mean whenever I open the file,the right row according to computer date,be shown directly at somewhere else instead of looking through all rows to find it.
thanks
above your table. add an empty row.
First column add =TODAY() // This will show todays date in the column and can be used in your other formulas. We will assume the cell is A1
Second Column add = VLOOKUP($A$1,A2:D8,2,FALSE) A1 being the date, A2:D8 being the table range (A2 top left cell, D8 bottom right cell), 2 is the second column of your table range, false returns the value in the second column as longs as the date (A1) matches the date in the first column on your table range.
Copy the formaula across the columns, changing the lookup column in the formula. ie. Third column VLOOKUP($A$1,A2:D8,3,FALSE)
Glad to help.

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