473,387 Members | 1,528 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,387 software developers and data experts.

Report : Problem using Count(IIf ...

I made a report concept from a simple query that contain as follow

Expand|Select|Wrap|Line Numbers
  1. SELECT [Table1].[Date], [Table1].Reason
  2. FROM [Table1]
  3. GROUP BY [Table1].[Date], [Table1].Reason
  4. HAVING ((([Table1].[Date])>=[FirstDate] And ([Table1].[Date])<=[LastDate]) AND (([Table1].Reason) Is Not Null));
When I click the view button, the query shows the date and the reasons record. Well, I assume the query works well.

Now, I want to make a report using that query, but is not a regular kind of report, I wanted to be like this :

Expand|Select|Wrap|Line Numbers
  1. No   Date         On Leave     Sick      Present      Business Trip
  2. 1    October'09   1            4         50           5
  3. 2    November'09  2            10        48           0
To get the Reason value, I enter this to it control source =Count(IIf([Reason]="On Leave",0)), that also for all 4 kind of reason type.
The strange is for the other report using this model I have no problem, but somehow for this one it came with warning like this :
"
This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables."

Please help me on this one. I try to remake the report that's work but still not working for this 2 table.
Dec 9 '09 #1

✓ answered by MikeTheBike

Hi

To achieve what you have illustrated I think something like this should do it
Expand|Select|Wrap|Line Numbers
  1. SELECT Format([Table1].[Date],"mmm yy") as [Date], Sum(IIF([Reason]="On Leave",1,0) as [On Leave], Sum(IIF([Reason]="Sick",1,0) as [Sick], Sum(IIF([Reason]="Present",1,0) as [Present], Sum(IIF([Reason]="Business Trip",1,0) as [Business Trip]
  2. FROM [Table1]
  3. GROUP BY Format([Table1].[Date],"mmm yy")
  4. HAVING ((([Table1].[Date])>=[FirstDate] And ([Table1].[Date])<=[LastDate]) AND (([Table1].Reason) Is Not Null));
??

I would suggest (if you havn't done it this way) is to have a Lookup table containing the 'Reasons' for the absences and create a relationship with Table1 based on the Reason_ID (long integer) contained in the new table. This would change the query to look something like this.
Expand|Select|Wrap|Line Numbers
  1. SELECT Format([Table1].[Date],"mmm yy") as [Date], Sum(IIF([Reason_ID]=1,1,0) as [On Leave], Sum(IIF([Reason_ID]=2,1,0) as [Sick], Sum(IIF([Reason_ID]=3,1,0) as [Present], Sum(IIF([Reason_ID]=4,1,0) as [Business Trip]
  2. FROM [Table1]
  3. GROUP BY Format([Table1].[Date],"mmm yy")
  4. HAVING ((([Table1].[Date])>=[FirstDate] And ([Table1].[Date])<=[LastDate]) AND (([Table1].Reason_D) Is Not Null));
The other thing is that it is a VERY bad idea to use "Date" as a field name (or any other keyword). Believe me; this advice is based on experience (having ignored vague recollection of this advice previously!!!).


MTB

1 2432
MikeTheBike
639 Expert 512MB
Hi

To achieve what you have illustrated I think something like this should do it
Expand|Select|Wrap|Line Numbers
  1. SELECT Format([Table1].[Date],"mmm yy") as [Date], Sum(IIF([Reason]="On Leave",1,0) as [On Leave], Sum(IIF([Reason]="Sick",1,0) as [Sick], Sum(IIF([Reason]="Present",1,0) as [Present], Sum(IIF([Reason]="Business Trip",1,0) as [Business Trip]
  2. FROM [Table1]
  3. GROUP BY Format([Table1].[Date],"mmm yy")
  4. HAVING ((([Table1].[Date])>=[FirstDate] And ([Table1].[Date])<=[LastDate]) AND (([Table1].Reason) Is Not Null));
??

I would suggest (if you havn't done it this way) is to have a Lookup table containing the 'Reasons' for the absences and create a relationship with Table1 based on the Reason_ID (long integer) contained in the new table. This would change the query to look something like this.
Expand|Select|Wrap|Line Numbers
  1. SELECT Format([Table1].[Date],"mmm yy") as [Date], Sum(IIF([Reason_ID]=1,1,0) as [On Leave], Sum(IIF([Reason_ID]=2,1,0) as [Sick], Sum(IIF([Reason_ID]=3,1,0) as [Present], Sum(IIF([Reason_ID]=4,1,0) as [Business Trip]
  2. FROM [Table1]
  3. GROUP BY Format([Table1].[Date],"mmm yy")
  4. HAVING ((([Table1].[Date])>=[FirstDate] And ([Table1].[Date])<=[LastDate]) AND (([Table1].Reason_D) Is Not Null));
The other thing is that it is a VERY bad idea to use "Date" as a field name (or any other keyword). Believe me; this advice is based on experience (having ignored vague recollection of this advice previously!!!).


MTB
Dec 9 '09 #2

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

Similar topics

3
by: mark | last post by:
How do I get all fields on one page of a report? I have a report that has a column for each day of the week and 6 records for each day. I need each weekday's records returned on only one detail...
4
by: Paul | last post by:
I have a query with a numeric field called BALBOOK. I have a form (we'll call it Form1) that runs this query. On this form is a text box (we'll call it Text1). When the query is run, I want is...
1
by: Terri | last post by:
I have an A2K database with linked tables to SQL Server 2000. I am trying to use an iif statement in a query. IIf(!! Is Null, "*",!!) This will return records when !! is not null but will...
0
by: Sheldon | last post by:
I have a query (query1) that contains a number of result fields. One of those fields (field1), can contain any or all of the following values: 1, 2, 3, 4, 5, 6, 7 or 8. I also have a field...
1
by: Michael R | last post by:
Hello all. I'm currently writting a query that would be able to filter a table by a form's control value. If the value is null, the query should select all the rows of the table. The condition...
15
by: Bernice J | last post by:
I'm trying to count the number of records in a table with the field STATUS that have a Y value. I'm using the expression "=Count(IIf(="Y",1,0))" . It counts all the values not just the Y's. Any...
6
by: plaguna | last post by:
I’m creating a Microsoft Access Report of 6 different questions with “Yes” and “No” answers. I have no problem to count the Yes and Nos with the following formulas for each question in the Report...
1
by: cwby1966 | last post by:
Hi I have a form that has a sub form. Want to add a text box that would didplay a message depending on different cirteria. The sub form list items to be followed up on, so if there was an item that...
8
by: RonnieG | last post by:
I'm trying to create a function in a query but not sure how or if it's the most effecient way. Here is what I'm wanting to do: If the = Yes and the > use the , if the is not null and the > use...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.