150 likes | 290 Views
Day 18: Access Chapter 3. Tazin Afrin Tazin.Afrin@mail.wvu.edu March 18, 2014. objectives. Chapter 3 Order of operation Calculated field Expression syntax Expression builder Built-in functions Date arithmetic Aggregate function. Calculated field.
E N D
Day 18:Access Chapter 3 Tazin AfrinTazin.Afrin@mail.wvu.edu March 18, 2014
objectives • Chapter 3 • Order of operation • Calculated field • Expression syntax • Expression builder • Built-in functions • Date arithmetic • Aggregate function
Calculated field • Create a calculation based on the fields from one or more tables. • Use expressions – • Identifiers (the names of fields, controls, or properties) • Arithmetic operators (e.g., * , / , + , or –) • Functions (built-in functions like Date() or IIf()) • Constants (numbers such as 30 or .5)
Expression syntax • Entered in the first row of the query design grid. • Must follow the correct syntax. • Create expressions to perform calculations using field names, constants, and functions. • Assign descriptive field names to the calculated fields. • MonthlyInterest: [Balance] * .035 / 12 • NewBalance: [Balance] + [MonthlyInterest]
Expression builder • Expression builder provides graphical tools for looking up operators (functions and arithmetic operators) and operands (existing fields, constants). • Open query in design view -> design tab-> Query setup group -> builder • Right click on field -> build
Built-in function • PMT • IIF • Date, DatePart, DateDiff
Create new query • Create a query that shows Agent’s FirstName, LastName, Properties’ DateListed, ListPrice, SqFeet, and Sold fields. • Show only properties Not sold. • Sort ListPrice in ascending order. • Run • Save as TargetHouses
Create a calculated field • Go to design view • Click on top row of first blank column • Type PricePerSqFt: ListPrice/SqFeet • Press enter • Set as Currency in Property sheet • Caption – Price Per Sq Ft • Run
Wrong Calculated field • Add another calculated field • WrongPrice: xListPrice/xSqFeet (shortcut : Shift+F2) • Run • xListPrice– 100000 • xSqFeet – 1000 • Fix the calculated fields by removing ‘x’
Functions with builder • Add a new calculated Field • Open expression builder • Query toold design -> Builder in query setup group • Payment: • PMT(0.06/12, 360, -[ListPrice]*0.9) • Set as Currency • Run
Aggregate Functions • An aggregate function performs calculations on an entire column of data and returns a single value. • Sum, Avg, Min etc. • Almost every database need to use aggregate function.
Adding Aggregate Functions • Two methods – • Add a Total Row in a Query or Table • Create a Totals Query
Add a Total Row • Displays as the last row in the Datasheet view of a table or query. • Provides a number of aggregate functions. • Go to datasheet view ->Home -> Records group -> Totals
Create a Totals Query • Contains an additional row in the design grid. • Used to display only aggregate data when the query is run. • Create a query -> Query Tools -> Show/Hide group -> Totals
Thank You Log Off