Excel 2007 Find number of days, based on current date, only if < or > then 2 different dates of same year & month - excel-2007

I have a question for Excel2000 want to do a simple calculation.
I need only one formula if possible include question in the formula to solve it.
Question Condition:
Date 01/Aug/2013 till 31/Aug/2013 in format 08/01/2013 till 08/31/2013 & the current date is 25/08/2013.
Question: Repeated several time for better understanding.
Excel should only do days calculation, based on current date only if the current date is within two date, from 08/01/2013 not less than or greater than 08/31/2013 if <> should remain blank, if within the period to find number of days, for the current month Aug of the year 2013.

Assuming a setup like this:
_____A____ _____B____ ______C_____ _______D______
1 Start Date End Date Today's Date Days Remaining
2 08/01/2013 08/31/2013 08/25/2013 6
This formula in cell D2 should work:
=IF(OR(C2<A2,C2>B2),"",B2-C2)

Related

Convert a weeknumber to month and generate an chart

I have an sheet with the Table, having Column A in Calendar Week. I would like to generate an chart with x axis as month with the data available in the table.
Could anyone help me to code it ? I am struck how I can convert an weeknumber in the column to month.
Could anyone suggest, how I can generate a chart for these data with month in my x/axis. I am not getting an clue to do this. Any lead would be helpful.
This is a formula to convert the week number in cell A1 into month
=MONTH(DATE(2017,1,-2)-WEEKDAY(DATE(2017,1,3))+A1*7)
Note that you also need to know the year the week number refers to, because it can differ from year to year. In this example it is fixed to 2017.
Note that week number != week number.
There are different methods how week numbers are calculated.
This formula example is based on ISO week numbers, with a week starting on Monday and the week containing the 1st Thursday of the year is considered week 1. For example, in the year 2016, the first Thursday is January 7, and that is why week 1 begins on 4-Jan-2016.
Here is some info about week number calculation based on different week numbers: Week Numbers In Excel
You need to use the formula
=TEXT((((A1-1)*7)+DATE(2017,1,1)),"m")
This will turn the week number into a date, then extract the month number

How do I summarise month to date forecast for current month in Power Pivot?

I have a table in a data model that has forecast figures for the next 3 months. What I want to do is to show what the forecast number for the current month to date is.
When I use the DATESMTD function like this:
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]),DATESMTD(DateTime[DateKey]))
I get the last month of my data summarised as a total. I assume that is because the DATESMTD function takes the last date in the column and that is 3 months away.
How do I make sure I get this current month MTD total rather then the end of the calendar? The formula should be clever enough to realise I am in May and want the May MTD not the August MTD.
Any ideas?
The way to do this is to do this:
Forecast_Transaction_MTD:=CALCULATE(sum('ATO Online'[2017 Transaction Forecast]), DATESINPERIOD('ATO Online'[Current Year],TODAY(),-day(TODAY()),day))
the last -day(TODAY()) gets the day number for the current day and subtract it from today's date. So, today is the 25 May. the -day(TODAY())),day)) extracts the day (25) and subtracts it from the current date to get me to the 1 May.
The rest of the formula just adds the total for the dates.

Trying to format date to save worksheet

I am looking to save an individual worksheet from a workbook with today's date in the filename. ex. (c:\HotDogS\sales\Daily_12_04_16.xslx)
The problem I am encountering is getting the date to show right in the filename.
I have 1 cell that has the simple formula of =TODAY(). The cell is formatted for mm/dd/yy.
The formula I am trying to use to save the date for the sheet is:
=left(B3,2)&"_"&mid(B3,4,2)&"_"&right(B3,2)
So I am expecting a date of 12/04/16 to come out as 12_04_16, but I am getting is, 42_08_08.
Can somebody shed some light on this??
Thank you!!
Assuming TODAY is 4 December 2016, i.e. serial day number 42708, your formula is:
=left(B3,2)&"_"&mid(B3,4,2)&"_"&right(B3,2)
Left(B3,2) is 42. Mid(B3,4,2) is 08. Right(B3,2) is 08.
So your final result is 42_08_08.
You probably want to use (as an Excel formula):
=TEXT(B3,"mm\_dd\_yy")
Or in VBA you could use
Format(Range("B3").Value, "mm_dd_yy")
Excel stores dates as the number of days (and fractions of a day) since 0 January 1900. Therefore
1 January 1900 is day 1
31 January 1900 is day 31
1 February 1900 is day 32
29 February 1900 (even though it doesn't exist - but the bug has been maintained for backward compatibility) is day 60
1 January 1901 is day 367
4 December 2016 is day 42708
NOW() is day 42709.328 (it's about 7:52am on 5 December 2016 at the moment)
Referencing a cell formatted as date returns the underlying date serial number.
To get a date formatted as you want use
=TEXT(B3,"dd\_mm\_yy")

Dateadd error when subtracting from 0:00

I am trying to convert column with GMT hour to the specified time zones from the user.
I get an error when VBA attempts to subtract 18000 secs (GMT-5) from 01:00.
Selected_GMT = -18000
CellValue = "1/0/00 01:00"
New_Time = DateAdd("s", Selected_GMT,CellValue)
Is this error happening because VBA is unable to determine the hours before 00:00?
I have figured out the seconds for Selected_GMT, how can I use that to determine New_Time?
As ooo noted in a comment above, 1/0/00 is an invalid date code. However even if that was a typo in your question, the fact that the date uses a 2 digit year code begs the question "WHICH year 00?" Apologies if you already know this, but below I've extracted a recap of how Excel dates work from something that I've written elsewhere. The relevant part is "Day Zero And Before In Excel"; if the "00" actually represents *19*00 in the cell (as it will if you've just punched in "01:00 as the cell entry), you're going to run into problems subtracting from that. In which case, perhaps explicitly enter the date and time (perhaps using the current date) but hide the date component using formatting):
Excel uses a "date serial" system in which any date that you use in
calculations is represented as a positive integer value. That integer
value is calculated from an arbitrary starting date. Adding whole
numbers to a specific serial date moves you forward through the
calendar a day at a time, and subtracting whole numbers moves you
backwards... as long as you don't go past the starting date of the
serial number system and end up with a negative value. Times are
represented as fractions of a day; 0.25 for 6am, 0.5 for noon, 0.75
for 6pm and so on.
Excel Dates
In the case of Excel for Windows, the starting date is 1 January 1900. That is, if you enter the value 1 into a cell in Excel
and format it as a date, you'll see the value as 1 January 1900. 2
will be the 2nd of January 1900, 3 the 3rd of January, and so on. 367
represents 1 January 1901 because Excel treats 1900 as having been a
leap year with 366 days. In other words, every full day that passes
adds 1 to the serial date.
It's important to remember that the above relates to Excel only, and
not to Access, SQL Server or other database products (or Visual Basic,
for that matter). In Access, for example, the range of valid dates is
1 January 100 to 31 December 9999, the same range that can be stored
in a VB or VBA variable with a Date data type.
Excel And The Macintosh
Macintosh systems use a start date of 1 January 1904, neatly bypassing the 1900 leap year issue. However that
does mean that there's a 4 year discrepancy between the serial date
values in a workbook created in Excel for Windows, and one created in
Excel for the Mac. Fortunately under Tools -> Options-> Calculation
(on pre-2007 versions of Excel) you'll find a workbook option called
1904 Date System. If that's checked, Excel knows that the workbook
came from a Macintosh and will adjust its date calculations
accordingly.
Excel Times
As noted in the introduction, times are calculated as a
fraction of a day. For example 1.5 represents noon on 2 January 1900.
1.75 represents 6pm on 2 January 1900.
(Snipped a bit about the leap year bug in 1900)
From 1 March 1900 onward Excel's dates are correct, but if you format
the number 1 using the format dddd, mmmm dd, yyyy you'll get the
result Sunday, 1 January 1900. That is incorrect; 1 January 1900 was a
Monday, not a Sunday. This day of week error continues until you reach
1 March, which is the first truly correct date in the Excel calendar.
Day Zero And Before In Excel
If you use the value zero and display it
in date format you'll get the nonsense date Saturday 0 January 1900.
If you try to format a negative value as a date, you'll just get a
cell full of hash marks. Similarly if you try to obtain a date serial
number using Excel functions like DateValue, you can only do so for
dates on or after 1 January 1900. An attempt to specify an earlier
date will result in an error.
The 1904 (Macintosh) system starts from zero. (1 January 1904 has a
value of 0, not 1. Excel's on-line help describes the Mac system as
starting from January 2, but that's probably easier than explaining to
users why a serial date value of 0 works on the Mac but not Excel.)
Negative numbers won't generate an error, but the number will be
treated as absolute. That is, both 1 and -1 will be treated as 2
January 1904.

Access query (SQL) to return records sorted (grouped by) WEEKS

Greetings SQL gurus,
I don't know if you can help me, but I will try. I have several large databases grouped by year (each year in a different database). I want to be able to compare values from a particular week from one year to the next. For example, "show me week 17 of 2008 vs. week 17 of 2002."
I have the following definition of weeks that ideally I would use:
Only 52 weeks each year and 7 days a week (that only takes 364 days),
The first day of the first week starts from January 2nd - which means we do not use January 1st data, and
In leap year, the first day of the first week ALSO starts from the January 2nd plus we skip Feb. 29.
Any ideas?
Thanks in advance.
Best to avoid creating a table because then you have to update and maintain it to get your queries to work.
DatePart('ww',[myDate]) will give you the week number. You may run into some issues though deciding which week belongs to which year - for example if Jan 1 2003 is on Wednesday does the week belong as week 52 in 2002 or week 1 in 2003? Your accounting department will have a day of the week that is your end of week (usually Sat). I usually just pick the year that has the most days in it. DatePart will always count the first week as 1 and in the case of the example above the last week as 53. You may not care that much either way. You can create queries for each year
SELECT DatePart('ww',[myDate]) as WeekNumber,myYearTable.* as WeekNumber
FROM myYearTable
and then join the queries to get your data. You'll loose a couple days at the end of the year if one table has 52 weeks and one has 53 (most will show as 53). Or you can do it by your weekending day - this always gives you Saturday which would push a late week into the following year.
(7-Weekday([myDate]))+[myDate]
then
DatePart('ww',(7-Weekday([myDate]))+[myDate])
Hope that helps
To get the week number
'to get the week number in the year
select datepart( week, datefield)
'to get the week number in the month
select (datepart(dd,datefield) -1 ) / 7 + 1
You don't need to complicate things thinking about leap years, etc. Just compare weeks mon to sun
SInce you havea a specifc defintion of when the week starts that is differnt that the standard used by the db, I think a weeks table is the solution to your problem. For each year create a table that defines the dates contained in each week and the week number. Then by joining to that table as well as the relevant other tables, you can ask for just the data for week 17.
Table structure
Date Week
20090102 1
20090103 1
etc.
I needed to create a query that shows BOTH year AND week numbers, like 2014-52. The year shows correct when you use the Datepart() formula to convert week 53 to week 52 in the previous year, but shows the wrong year for the week that was week 1 previously that should be week 52 now. It show that week as 2015-52 instead of 2014-52.
Furthermore, it sorts the data wrong if you only use only the week number, eg:
2014-1,2014-11,2014-2
To overcome this I created the following query to insert a 0 and also to check for days in week 1 that should still fall under week 52.
ActualWeek: IIf(DatePart("ww",[SomeDate],1,3)=52 And DatePart("ww",[SomeDate])=1, DatePart("yyyy",[SomeDate],1,3)-1,DatePart("yyyy",[SomeDate],1,3)) & "-" & IIf(DatePart("ww",[SomeDate],1,3)<10,"0" & DatePart("ww",[SomeDate],1,3),DatePart("ww",[SomeDate],1,3))