Calculating the Difference in Dates in Excel, and Pivot Tables - excel-formula

I'm trying to do the same thing(ish), as in another question, but I'm perplexed by the answer as it doesn't add up for me. It might help if you see this referenced question (Calculate difference from previous date in Excel pivot table). Why is it that in this solution example does the difference in dates show up as 43165 ("days"—I'm assuming)? My model is working to show days between subscription start dates and end dates. So it's should be pretty much the same thing.
Further more, I don't understand why it is when I do a date difference calculation inside the excel table that it works, but when I use it as a calculated field in a pivot table it doesn't work. This is the Formula I used. =ABS(MONTH(J2)-MONTH(D2))+1
I used Absolute because it was showing negatives. I added 1 month to account for the current month and because subs showing less than 30 days, would display 0(zero) months.
Thanks in advance,

Related

Hour calculation based on date excel

I've got a question where I don't know were to start to be honest.
I want to add a function to my sheet where I calculate the total amount of hours based on the date.
So as for my example I want excel to recognize the different dates, regardless of their position, and calculate the amount of hours spent on that date.
Is that something that is even possible?
Or is it impossible and is that the reason why I can't find anything about it?
little note: I'm using excel 2016
29-06-2021 update
got it working with both SUMIFS and SUMIF using the following formula:
=SOMMEN.ALS(B234:B332; A234:A332;"28-06-21")
the current challenge I'm facing is that I want excel to look up the date and determine the day
I already tried with VLOOKUP (with a calendar on another sheet) but that doesn't seem to work
Excel has to use the date in the date column to determine which day it is so I can determine the amount of hours per weekday.
example VLOOKUP
Obviously I'm doing something wrong, but I don't know what
I got it running with specifying multiple criteria in the SUMIF function
I now use the following formula for Mondays which basically is a list of all Mondays in a year
=SOM(SOM.ALS(A218:A316;{"04-01-21”;”11-01-21”;”18-01-21”;”25-01-21”;”01-02-21”;”08-02-21”;”15-02-21”;”22-02-21”;”01-03-21”;”08-03-21”;”15-03-21”;”22-03-21”;”29-03-21”;”05-04-21”;”12-04-21”;”19-04-21”;”26-04-21”;”03-05-21”;”10-05-21";"17-05-21";"24-05-21";"31-05-21";"07-06-21";"14-06-21";"21-06-21";"28-06-21";"05-07-21";"12-07-21";"19-07-21";"26-07-21";"02-08-21";"09-08-21";"16-08-21";"23-08-21";"30-08-21";"06-09-21";"13-09-21";"20-09-21";"27-09-21";"04-10-21";"11-10-21";"18-10-21";"25-10-21";"01-11-21";"08-11-21";"15-11-21";"22-11-21";"29-11-21";"06-12-21";"13-12-21";"20-12-21";"27-12-21"};B218:B316))
SOM=SUM and SOM.ALS=SUMIF in English versions
This works for me, it just takes some time to get all the dates in the formula.

Lookup previous date for the same item in an unsorted table

Trying to create a way to QC daily data before pulling it into Spotfire to automate a monthly report. The data is sourced from the field so the data quality isn't the greatest. Plus some days get missed because there wasn't a guy working in the area that day.
I tried doing all of the calculations in Spotfire and managed to get it but after talking to some folks when I was asking about ways to QC the data. They all suggested doing the calculations, data cleaning, and QCing in Excel before pulling it into Spotfire.
Not sure how to put a table in here but are the important columns.
Column A: unique well identifier
Column G: hours and value that I want to lookup
Column I: date
I managed to get all of the calculations and filtering completed within Spotfire but am wanting to replicate them in Excel.
The first thing I am trying to do is pull the previous dates HOURS value (Column H). Some wells will have a value on the previous date and some might not.
The below formulas are a few that I tried out:
Formula 1: =DATE(YEAR(DATA!$I2),MONTH(DATA!$I2),DAY(DATA!$I2)-1)
Formula 2: =INDEX(A:I,MATCH(1,(I:I=DATA!$I2)*(A:A=DATA!$A2),1),9)
Results:
Formula 1 always yielded the previous day which would work for 99% of
the cases.
Formula 2 yielded #N/A
I don't know why you don't want to do the whole thing using Spotfire.
Here is an example of an expression, using Spotfire, to get the previous date (which seems to be what you want, but without a dataset it is hard to figure out) :
Min([Date_Col]) OVER (Previous([Date_Col]))
You may want to use the DatePart function first to only have the date if you currently have a datetime

Month & Week grouping in excel pivot tables with some empty data

I am working to group data in excel and I am trying to sort the input dates by month and week. I've found a number of ways to group by weeks (including grouping the date by 7 days and adding a helper column in the pivot table that numbers the weeks), but I'm having a problem viewing months and weeks without data.
For example, in my data set during the month of October, 2 of the weeks have no input. When I try to make the pivot table "show rows with no data" it shows every week in the year, not only the weeks during the month of October.
I would like be able to show every week during the month of October, including those without data, without showing every week in the year. Has anyone encountered a similar issue? I'm on Excel 2016 but my colleague has the same issue on Excel 2013.
Thanks!
Here is a quick screenshot of the pivot table from the data. I am trying to make all of the weeks in the month of October show up regardless of whether or not there is data, but I don't want to see all of the weeks in the date range. I have sample data input from September 16th, 2018 to January 1st, 2019
Update for anyone looking to do this themselves:
I couldn't figure out a way to do this with Pivot Charts. They lack the ability to group by multiple days as well as by months and years. Instead, I used VBA to select the desired data from the pivot table by checking for the number of the month in each row. (mm/dd/yyyy - mm/dd/yyyy is the format pivot tables use to group days).
I added a dummy row which copied the date ("Date 2") and used that, grouped in 7 days, as the rows for the pivot table. Because I wanted to show items with 0 data I selected that option, which shows every group of 7 days from the first day entered until the last day entered. I used the original Date with Month and Year auto groups to insert Slicers to sort the data.
In VBA you can check which Slicers are selected and use that to determine the range of months you want to display on the inserted chart. This way you can look at one or two months at a time but still show weeks with no data.
While this solution is not particularly elegant, it did allow for a dynamic use of the data that can be adjusted to view specific months or years as was desired. Some useful resources for this method are included below. Again, it is an ugly way to get the desired result but if it works it works!
https://peltiertech.com/referencing-pivot-table-ranges-in-vba/
https://peltiertech.com/create-update-chart-using-partial-pivot-table/

Summing Daily Sales Data between two ranges

We have been having this problem for a little while, but I know that once I figure out the solution it will save me loads of time. I have a data pull of sales from a chain of grocery stores with dates on top and products on the side. Shown here: View of the data
We would like to show sales for these products between specific date ranges. These ranges are shown for Current Year and Last Year. I tried the Last Year's sales with a sumif, but sadly that is the #VALUE that you see here: Hopeful Output
I thought this equation would solve my problem, but no:
=SUMIFS(Input!B2:NB51,Input!A2:A51,Output!A2,Input!B1:NB1,">="&Output!D2,Input!B1:NB1,"<="&Output!E2)
Google Docs of the spreadsheet here: https://docs.google.com/spreadsheets/d/1rdoGKliu3suu7mfDTB7Ckj83EzeZGmhw5yZnQ7u5X94/edit?usp=sharing
Thank you so much for your help!
That happens because column array and row array are different and can't be used together in these formulas even if they have the same length.
You can use this formula at your Output F2 (close it with ctrl+shift+enter)
=SUM(INDIRECT("Input!"&ADDRESS(MATCH(A2,Input!A:A,0),MATCH(D2,Input!$1:$1,0))&":"&ADDRESS(MATCH(A2,Input!A:A,0),MATCH(E2,Input!$1:$1,0))))
Sheet Output
F2=SUMPRODUCT((Input!$A$2:$A$1000=Output!$A3)* (Input!$B$1:$ABA$1>=Output!D3)* (Input!$B$1:$ABA$1<=Output!E3)*(Input!$B$2:$ABA$1000))

Return all cell values in a row if Month & Year match a dd/mm/yyyy formatted date cell in that row

This is possibly a tough one so forgive me while I spell out the exact circumstances and what is needed:
We have a workbook which is populated with data from our support calls (most of it is text) which is then analysed for certain criteria which are just Yes/No options (i.e. incorrect information received, late notice, etc). One of the columns is the date the support call was raised, formatted as dd/mm/yyyy. All of this data is on sheet 2.
What I have been asked to do is to have a management-friendly interface on sheet 1:
two boxes on sheet 1 labelled 'Month' and 'Year' - a manager can enter say January in Month and 2014 in Year and if they match the dd/mm/yyyy of any calls which were raised, this will then extract the whole row of values and place on sheet 3.
On sheet 1, a graph will then be populated from the data on sheet 3 to show things like how many support calls had incorrect information.
Any ideas? I've tried going through VLOOKUPS, MATCH and INDEX and can't find anything which makes any sense to me.
UPDATE
Thanks for all the input in such a short time frame. Apologies for not providing more information first time around - was on a tight deadline and had limited time to write the original post. Many thanks to both user2140261 and Scott Gall for the hints and explanations concerning pivot tables. I think that has given me enough information to head in the right direction (I ended up having to do the first graph manually, but seem to have some promising results with my first attempts with pivot tables and charts) so thank you once again.
When I have this properly worked out, I'll post some dummy information showing how it works in case anyone with a similar problem finds it useful.
May I suggest the use of a pivot table?
First break the Date Field into multiple columns on sheet two (which do not need to be visible btw).
Formula for Month: = Text(,"mmm")
Formula for Year: = Text(,"yyyy")
Then insert a pivot table on Sheet 1 using the whole data range on sheet two as the source.
Set the two new Columns (Month and Year) as Filters and the user can simply pick a month and year to view (multi select should also be available)
You will need to play around with what to put in the rows and columns and values a bit...
Keep in mind the default "Value" calculation excel will do is Count this is rarely the desired measure for the "Values" usually want SUM.. this can be changed by clicking the small down arrow for the value field and editing the field properties.
Note your graph can then be fed from the resulting pivot table.
Hope you find this helpful... if so please vote up.

Resources