473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Populate Previous Month

cori25
83
Hello...

I am attempting to create code in a query to state: If the [LastDate] occurred in the previous month then 1, otherwise 0.

This is what I attempted to do:
[PHP]OTLast Mth:iiif([LastDate]=DateSerial(Year(Date()), Month(Date()), 1, 0) [/PHP]

It is not working.....anyone have any suggestions?

Thanks
Feb 29 '08 #1
3 1729
Stewart Ross
2,545 Expert Mod 2GB
...
I am attempting to create code in a query to state: If the [LastDate] occurred in the previous month then 1, otherwise 0.

This is what I attempted to do:
[PHP]OTLast Mth:iiif([LastDate]=DateSerial(Year(Date()), Month(Date()), 1, 0) [/PHP]
Hi Cori. Could you clarify what you need to do? Is it that you are checking whether the value of LastDate is in the current calendar month? I am not clear what you need to calculate. if, for instance, you wanted to know whether or not the LastDate had the same month as the current month you could use the DatePart function or the Month function:
Expand|Select|Wrap|Line Numbers
  1. IIF(Month(Date())=Month([LastDate], 1, 0)
but this is just an example pending clarification of what you really need to compare.

-Stewart
Feb 29 '08 #2
cori25
83
Hi Stewart,

Like I stated in the original post, it is looking for the previous month.

I actually was able to figure it out using this code:

[PHP]WorkedPrevMth: IIf(Format(qry_WorkedPrevMth_1!Date,"m")-1=Format(qry_WorkedPrevMth_1!LastDate,"m"),1,0)[/PHP]

Thanks for the response!
Mar 3 '08 #3
NeoPa
32,556 Expert Mod 16PB
Hi Stewart,

Like I stated in the original post, it is looking for the previous month.
...
Unfortunately your original post was not expressed very well - hence clarification was required.
Consider - What does "the previous month" mean when there is no relative item? Prior to what?
I looked at your code to try and reverse engineer the question. This latest one seems to refer to two fields from the query, yet your original post referred to the Date() function. Consider how confusing this is for someone who can only understand what you need from what you say in your posts.

Anyway, assuming that the fields used in your latest post are what you need (you stated after all that this works) then your code would probably be something like :
Expand|Select|Wrap|Line Numbers
  1. WorkedPrevMth: IIf((Month(qry_WorkedPrevMth_1.Date) - 1) = Month(qry_WorkedPrevMth_1.LastDate), 1, 0)
I assume that [qry_WorkedPrevMth_1] is one of the data sources in the query you're working with.
Mar 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: eddie wang | last post by:
How to convert a month to previous month in a very easy way? For example, I have AUGUST, but I want JULY to return. Thanks. *** Sent via Developersdex http://www.developersdex.com *** Don't...
1
by: Wharfrat | last post by:
Hey all, I have a query that pulls data based on the month. I'm using MONTHNAME(CURDATE()) to get the current month. I need to get the previous month. Is there a way to do this using MONTHNAME?...
11
by: laurenq uantrell | last post by:
I want to take the contents from a table of appointments and insert the appointments for any given month into a temp table where all the appointments for each day are inserted into a single row...
5
by: Ray via SQLMonster.com | last post by:
Hi there, See if you can help me with the following: I need to write an SQL code that will return me: The 1st day & the Last day of the Previous Month in the following format...
1
by: Finlay | last post by:
Hi Group I am designing a report that should show a meter reading for each month and the previous meter reading for the previous month. The months are text stored in a field tMonth. The...
2
by: TB | last post by:
HI, is there a formula(function) you could use to the display the previous month's name in a report. i know there is a function(formula) that returns the previous month's value (ie 4 for the...
9
by: brymcguire | last post by:
Hi, I have a requirement to design a query that identifies items sold between two dates. There is a 'SoldDate' datetime field used to register what date the item was sold. The query needs...
10
by: Massimo30 | last post by:
Looking for answers and have done a search in books and websites and still can't find the answer: I am setting up a Market Trend DB on housing figures. I have the following fields in my table: My...
3
MattFitzgerald
by: MattFitzgerald | last post by:
My Forms & Tables:- Main form is Frm_LE_List (contains Customer Details) Stored in Tbl_LE_List Which contains subform Frm_VOL_References (Contains Orders known as VOL's) Stored in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.