Formula???

markham

New Member
Joined
May 9, 2004
Messages
12
Hi everyone....

This isn't for me but for a friend... really.

One table that reads:

Dept.
DayIn
DayOut
# of days (day in - day out)

Question is: A query that will create field names that read:

dept. 0 days 1-3 days 4-7 days >7

....looks up the # of days and counts them under the corresponding field.

Can anybody help with this.... thanks a lot.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi

You can do this with a crosstab query - make a new crosstab query, add the table, add the department and make it the "row heading" (must have at least one row heading) of the crosstab query. Add the NumDays field (being the difference between the Day In and Day Out fields), change 'Group By' to 'Count', make it the "value" field of the crosstab query and change the field from "NumDays" (or whatever it is called) to "Incidences : nz([NumDays])" (without the quotes). Add the following expression into the next available field :
Code:
ColHeading: IIf([NumDays]=0 Or IsNull([NumDays]),0,IIf([NumDays]<4,3,IIf([NumDays]<8,7,8)))
make it the column heading, and leave 'Group by' as is. Right click this field and select properties, change the column headings to 0,3,7,8. Save and run.

The SQL for the query looks like this :
Code:
TRANSFORM Count( nz([NumDays])) AS Incidences
SELECT MyTableName.Dept
FROM MyTableName
GROUP BY MyTableName.Dept
PIVOT IIf([NumDays]=0 Or IsNull([NumDays]), 0, IIf([NumDays]<4, 3, IIf([NumDays]<8, 7, 8))) In (0,3,7,8);
This won't give you the exact column headings you are seeking but they will be pretty close, plus if you are using these values on a report, then you can change the column headings to whatever you like.

HTH, Andrew. :)
 
Upvote 0
Why is there a column in the table for no of days?

This calculation should really be done in a query.

You could then use Andrew's idea but based on the query rather than the table.
 
Upvote 0

Forum statistics

Threads
1,221,893
Messages
6,162,659
Members
451,780
Latest member
Blake86

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