Using DateSerial to get a range

GMFTM

New Member
Joined
Nov 4, 2016
Messages
42
Not that familiar with DateSerial, I need to build this so that I am gettting MTD data, current and Previous month.

Can someone start me off with the proper syntax? using beginning of month to current day and previous month.

DateSerial(??
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Ok,

I am this far now, however I am getting an error on the Between and And....

Count(IIf([Sale_Date] Between (DateSerial(Year(Date), Month(Date) - 1, 1) And (DateSerial(Year(Date), Month(Date), 1) - 1),[VIN]))
 
Upvote 0
The IIF() doesn't look complete. Should be IIF(Condition, TruePart, FalsePart) You only have IIF(Condition)

Possibly the condition stuff can go in your where clause so no need for IIF.
 
Upvote 0
Previous VIN: Count(IIf([Sale_Date] Between DateSerial(Year(Now()),Month(Now())-1,1) And DateSerial(Year(Now()),Month(Now()),1)-1,[VIN],0))
Current VIN: Count(IIf([Sale_Date] Between DateSerial(Year(Now()), Month(Now()), 1) And DateSerial(Year(Now()), Month(Now()) + 1, 1) - 1,[VIN],0))


Right, I finished of the condition, however I am getting the same results for both of these?

Any thoughts
 
Upvote 0
See if this works any better:
Previous VIN: Sum(IIf([Sale_Date] Between DateSerial(Year(Now()),Month(Now())-1,1) And DateSerial(Year(Now()),Month(Now()),1)-1,1,0))
Current VIN: Sum(IIf([Sale_Date] Between DateSerial(Year(Now()), Month(Now()), 1) And DateSerial(Year(Now()), Month(Now()) + 1, 1) - 1,1,0))
 
Upvote 0
Yes that was it, I saw it too after I posted it, lol.

Now If I am looking for MTD and today is the 21st, will the below always pull current date and the 1st of the month?

I think that is how I read it and wrote it, but again not 100% on it



See if this works any better:
Previous VIN: Sum(IIf([Sale_Date] Between DateSerial(Year(Now()),Month(Now())-1,1) And DateSerial(Year(Now()),Month(Now()),1)-1,1,0))
Current VIN: Sum(IIf([Sale_Date] Between DateSerial(Year(Now()), Month(Now()), 1) And DateSerial(Year(Now()), Month(Now()) + 1, 1) - 1,1,0))
 
Upvote 0
To get between the 1st of the current month and today, you can just use:
Code:
Between DateSerial(Year(Now()),Month(Now()),1) and Now()
 
Upvote 0
So like this:

Previous VIN: Sum(IIf([Sale_Date] Between DateSerial(Year(Now()),Month(Now())-1,1) And DateSerial(Year(Now()),Month(Now()),1)-1,1,0))
Current VIN: Sum(IIf([Sale_Date] Between DateSerial(Year(Now()), Month(Now()), 1) And DateSerial(Year(Now()), Month(Now()) + 1, 1) - 1,1,0))

I have two here, the first is the previous month which need to pull 1st - 21st
and the second current month need to pull 1st - 21st

so how would that look in the above syntax?


To get between the 1st of the current month and today, you can just use:
Code:
Between DateSerial(Year(Now()),Month(Now()),1) and Now()
 
Upvote 0
I have two here, the first is the previous month which need to pull 1st - 21st
Your "Previous" is returning through February 28, not February 21.

Note: You can easily check to see what your date calculations easily return by using a calculated field in a Query, i.e.
Just put this as a calculated field in any query and see what it returns:
Code:
Test: DateSerial(Year(Now()),Month(Now()),1)-1
So you can use this technique to perfect each date calculation, and then drop them into your equation.
I will leave that for you to work out. If you run into trouble with a particular one, post back on that one.
 
Upvote 0

Forum statistics

Threads
1,221,707
Messages
6,161,416
Members
451,705
Latest member
Priti_190

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top