Hi again!
I have a question in regards to an approach.
I have a report that servers as a breakdown report. I need to have my report return totals based on different time criterion. For example: - Total Number of sales (Count)
-
Present- 3months
-
4-6 Months
-
7-12 Months
Slightly stumped on my approach. Can anyone offer advice as to how I can achieve this?
Thanks.
My current thought is something along these lines. Maybe I'm off track.
As my ControlSource - =Iff(DateDiff("m",[SoldDate],Date())<4,Count([SoldDate]))
I'm getting a parameter prompt for IIF.
7 1903 NeoPa 32,556
Expert Mod 16PB
Assuming you have a date field somewhere then you would need to convert that into a number of months in the past (Use DateDiff() for this). From that point you can create a field using IIf() that returns one value if the value is less than four, another if less than seven, another if less than thirteen, etc. The result of this field can then be GROUPed by and aggregated across (Count() is an aggregate function) in the usual way.
Thank you, NeoPa. I editied my previous post. (not sure if you had the chance to view my sample code) It looks like I'm on the right track but not quite there. Is it possible/wise to do this all with one expression as I'm trying (Still debugging) or seperate it somehow?
Should I create an Expression field in my query builder for the DateDiff and call that number somehow into my ControlSource then use the iff statement there to complete my calculation?
NeoPa 32,556
Expert Mod 16PB
You haven't used IIf(). You've tried to use Iff() instead.
Your follow-on question or suggestion is not a valid answer by itself, but that's already clear from my answer in post #2. Why not try going forwards from that point.
Thanks, NeoPa.
I have added 2 expression fields to my query. The first [SoldDateDiff] is to find the DateDiff()of [SoldDate]. The second [SoldDateDiffGrp] takes [SoldDateDiff] and assigns a letter based on the monthly conditions. It is a nested IIf statement. - SoldDateDiffGrp: IIf([SoldDateDiff]<4,"A",IIf([SoldDateDiff]<7,"B",IIf([SoldDateDiff]<13,"C","D")))
I'm at a loss of how to implement the GROUP BY clause to get the desired results. Can you provide insight?
Also, These calculations are part of a report summary. The details section of the report will contain all possible situations: Current-3, 6-4, 7-12 and 13+.
NeoPa 32,556
Expert Mod 16PB
You would do a GROUP BY on the expression itself, so your GROUP BY clause might look like : - GROUP BY IIf([SoldDateDiff]<4,'A',IIf([SoldDateDiff]<7,'B',IIf([SoldDateDiff]<13,'C','D')))
Although, I'd use a different expression : - Switch([SoldDateDiff]<4,'A',[SoldDateDiff]<7,'B',[SoldDateDiff]<13,'C',True,'D')
Of course, if [SoldDateDiff] is just an expression then it will not be available to the GROUP BY clause, so you'll need to make it available by providing the data in a Subquery (otherwise the full expression would be required in place of each reference to [SoldDateDiff] - Messy).
As a clairification, a subquery is simply another query that the main query calls data from?
NeoPa 32,556
Expert Mod 16PB
A subquery is a query defined within the current one, that can provide data.
It is not limited to use within the FROM clause, but can be used as criteria and even as data in the SELECT clause itself. See Subqueries in SQL for more ideas.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve Jorgensen |
last post by:
Hi all,
I'm working on the schema for a database that must represent data about stock
& bond funds over time. My connundrum is that, for any of several dimension
fields, including the fund name...
|
by: CrystalDBA |
last post by:
I am using SQL Server 2000. I need to query my database for all the
contracts that came in during a certain time frame (user is prompted
for reportingperiodid).
Table - Periods
Fields -...
|
by: Dave |
last post by:
Hi
I am hoping someone might be able to help me out with this.
I am writing a helpdesk system which records agents logging in and out
of the system.
I need to write a stored procedure which...
|
by: blueyonder news |
last post by:
Can anyone offer any advice. I was wondering whether MS SQL server offered
any facilities to trigger an event after a period of time had lapsed? e.g.
once a week check data and if it is out of date...
|
by: Mayhem05 |
last post by:
I'm hoping someone can guide me on solving this vexing problem I have
with a database I built to track a projects. I'm using MS Access 2003
and here are the basics: the database is designed to...
|
by: itcassy |
last post by:
I would like to pull a random or alphabetical result on the home page
of a site and leave that same result on there for one week. The
closest example I have found online is Random Quote Version...
|
by: dianatokatlidis |
last post by:
Hello. I have 2 separate date fields in a query. One is called Effective_Date and the other is called Expiry_Date.
I want to compare the time period between these 2 fields and select any records...
|
by: Charming12 |
last post by:
Hi All,
I am facing quite a unique problem here with DayLight saving time.
I know Windows handles Daylight saving time internally to sync PC Clock .
But now i need to pass the Information of...
|
by: sasasasa |
last post by:
How can I loop through each date in a given time period so that I can add those dates as a column name in a table.
I want to create datatable with the person's name and hours he worked in a given...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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,...
|
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...
| |