Sum a Subtotal in MS Access by Date - ms-access

I'm using MS Access 2010
My query has the fields, Date, Market Price, Actual Price
I need to separate out within the query by date Actual Price/Market Price in order to achieve a percentage which I can then average (for that day only, one day at a time)
Each day will have anywhere from 10-50 items.

You'll want to use a standard query, but a totals to the query. On the Home tab, in the Records group, click Totals.
Once you have that field displayed you can put a Sum (in the Totals field) for Market Price and Actual Price; and then make sure the Date field is set to GroupBy.
Then you should be getting totals for the Price fields grouped by Date.
btw., I'd label that date field something else other than just Date (e.g., DateSold, PurchaseDate, etc.) just to avoid confusion and possible conflicts with the Date type.

Related

Count the number of columns in a column group

I need to report the average number of customer visits each engineer makes per month.
My SQL query creates a temporary table of months between the start date and end date and left joins this to the main data table, to ensure rows are returned even for months where no visits were made.
So an example of the data returned from SQL may be:
My report has two column groups, one for year and one for month, and I have a row group for the engineer.
For this report, the date is always returned as the first of the month, even though the actual visit could be on any date.
At the end of each year there is a cell which contains Count(Customer) and totals the number of visits the engineer made in that year. I would also like to have a cell which displays the average number of visits made each month in that year.
For a complete year I could simply divide by 12. However for a partial year I need to count the number of month columns for that year.
I tried CountDistinct(Month) but this only counts months where at least one visit was made, making the monthly average incorrect.
How can I get a count of the number of columns in a column group, including columns with no data?
Thanks.
The way I would do this would be to add a column into your temporary dates table that had the number of months selected in it.
You could do this by either counting the months in the temp table then appending the value to it or, if the dates table contains more than just months then work it out based on the parameters you pass in.
For example
SELECT *, DATEFIFF("m", #startDate, #endDate) as NoOfMonths
INTO #myTempDateTable
FROM myDateTable
WHERE etc...
Then in SSRS you can simply divide your total by this number.

Access Creating sum(iif to get the number of periods which apply

I'm trying to make a sum iif function which checks based on an employee's hire date and the ending pay period date whether they are part of the payroll period. So my idea was sum(iif([table1].[hiredate]<=[table2].[ppend],1,0))
While it works well for some, for some employees the number it gives is ridiculous. To give you an idea, there are 200 records for ppend, but it returns for some employees especially those who are well before the earliest ppend date, a number of 400 upward to 450. I'm also attempting to have it compare relative to the current date as well so I've used sum(iif(table1.hiredate<=table2.ppend<=date(),1,0)) but it largely leads to the same result. Could anybody help. Perhaps there is a factor I've neglected.
For table 1 the column data is in this order: employee ID, name, hire date and table 2 is payroll date, pp beg, pp end.

spotfire multiple over statements in one custom expression

I have a table of travel expenses for analysis.
I would like to create a calculated column with a value for the maximum count of records with a certain category for each employee on any given day.
For example, if the category being reviewed is "dinner", we would like to know what is the maximum number of dinner transactions charged on any given day.
The following custom expression was able to count how many dinner expenses per employee:
count(If([Expense Type]="Dinner",[Expense Type],null)) over ([Employee])
But when trying to get the max count over days, I cant seem to get it to work. Here is the expression used:
Max(count(If([Expense Type]="Dinner",[Expense Type],null)) over ([Employee])) over (Intersect([Employee],[Transaction Date]))
This seems to provide the same answer as the first expression. Any idea on how to get this code to identify the value on the date with the most expenses for each employee?
If i understand your question and comments correctly, you should be able to use intersect.
count(If([Expense Type]="Dinner",[Expense Type],null)) over (Intersect([Transaction Date],[Employee]))
You may need to cast [Transaction Date] as a date if it is an actual DateTime. Otherwise you'd get one for each unique DT.

Filter Count by conditions

I have a table with a start and end date for each record, and a duration between the two that I have calculated. I now need to group these durations by intervals (1-29, 30-59, etc) and count how many durations fall in each category, displayed in a form/report. How should I both count the number of durations as well as filter them by size?
Construct a field with calculation that assigns an identifier for the interval groupings.
Switch([Duration]<30,1, [Duration]<60,2, [Duration]<90,3, True,4)
Or try the Partition() function. https://support.office.com/en-us/article/Partition-Function-1A846A33-60C7-4371-8E77-C94278274DC5?ui=en-US&rs=en-US&ad=US&fromAR=1
Use Report Sorting & Grouping features and do the summary aggregate calcs in textboxes on report.

MS Access 2010: Extract unique values

first off: I know virtually nothing about MS Access but now I'm in a situation where I have to use it (dataset is too big for Excel). The data has column names like Customer_Name, Product Name, Amount, Date
Date refers to the last day of a month, so for example for February it's 28/02/2013. Now I want to compare the amount a customer bought in February to the amount he/she bought in January and calculate the difference. So far, I've been able to this by prompting the user to enter the date.
SELECT Data.Customer_Name,
Sum(IIf(Format(Date,"yymm")=[Startdate (yymm)?],Amount,0)) AS Amount_Startdate,
Sum(IIf(Format(Date,"yymm")=[Enddate (yymm)?],Amount,0)) AS Amount_Enddate,
Amount_Enddate-Amount_Startdate AS Difference
FROM Data
GROUP BY Data.Customer_Name;
This works but is it possible for Access to recognize which dates are in the column "Date" (there are only two distinct dates) so the user does not have to enter anything? Also, I tried to replace "Amount_Startdate" with a field that has the respective date in its name (e.g. "Amount_Feb2013") and played around with ampersand but it didn't work.
If you create a new table called tblValues with just 2 fields; ID and TDate (always try to avoid using reserved words like "Date", "System" or other words that Access already assigns a function to), you can fill it like this:
ID TDate
-- ---------
ST 1/31/2014
EN 2/28/2014
Then you could use the DLookup function to make this code generic:
SELECT Data.Customer_Name,
Sum(IIf(Format(Date,"yymm")=DLookup(Format(TDate, "yymm"), tblValues, "ID = 'ST'"),Amount,0)) AS Amount_Startdate,
Sum(IIf(Format(Date,"yymm")=DLookup(Format(TDate, "yymm"), tblValues, "ID = 'EN'"),Amount,0)) AS Amount_Enddate,
Amount_Enddate-Amount_Startdate AS Difference
FROM Data
GROUP BY Data.Customer_Name;
Then you could just update the table with the values you want to use as start and end dates whenever you want.