Unique Calculated Totals with Parameters in Access Report - ms-access

I'm working with an access 2003 report that uses an employee, and their points they've accumulated over a period of time. When the report is run, it asks for parameters StartDate and EndDate, then generates a nice report by Supervisor -> Employee -> Each point with a reason.
How can I get a total box next to each employees name to give the total points for each employee? I've thought about writing a SELECT and WHERE statement and adding variables to the VBA, so the source property is:
=(SUM(SELECT [PointValue] WHERE [EmployeeName] = CurrentEmployee AND & _
[Date] <= #StartDate# AND [Date] >= #EndDate#))
Thanks in advance!

The easiest way to do this would be to use grouping. If you create a group header for the employee field (column) you can add a textbox and sum the points in the group header.

Related

Average YTD in SSRS

The image above is a replica of a report that already exist. Now users want to see average Year to Day(YTD) per for each product. The idea is to aggregate the sum of each product and divide by the count of months. This report is group by month by year.
I understand using Window Function but I am running Sql Server 2008 so cannot frame. How do I go about this using SSRS?
Not sure it can be done using SSRS expression, but you can handle it in query level, something like:
select
x.product
, sum(x.prosum) sumbyMonthProduct
, sum(x.prosum)/sum(x.countv) avgv
from
(select monthv, product
, sum(ytd_sale) as prosum
, count(monthv) as countv
from tableName
group by monthv, product
) x
group by x.product

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.

Adding an automatic date range to a query in VBA access

This is my first question, please be kind. I am writing a macro in access and I want a series of reports to run one after another. the problem is all report have a date range that needs to be entered. Some are for the previous week some are for the previous month.
Is there a way in VBA or the macro creator to automatically calculate a date range for the previous month or week and populate the field to fully automate the process without manually entering the date range each time.
I am a new to VBA. Any help would be great, just point me in the right direction. Have a good day.
This query is created using the query design window in MS Access and then cut from SQL view. It will show records for last week, where ww is week number, in table1
SELECT Table1.AKey, Table1.atext, Table1.ADate,
Format([ADate],"ww") AS Week, Month([ADate]) AS [Month],
Year([ADate]) AS [Year]
FROM Table1
WHERE (((Format([ADate],"ww"))=Format(Date(),"ww")-1)
AND ((Year([ADate]))=Year(Date())));
You will notice that one column is called Month. You can use this to set a previous month in a similar way to setting the previous week. For example, both last week and last month:
SELECT Table1.AKey, Table1.atext, Table1.ADate,
Format([ADate],"ww") AS Week, Month([ADate]) AS [Month],
Year([ADate]) AS [Year]
FROM Table1
WHERE (((Format([ADate],"ww"))=Format(Date(),"ww")-1)
AND ((Year([ADate]))=Year(Date())))
OR (((Month([ADate]))=Month(Date())-1)
AND ((Year([ADate]))=Year(Date())));
The SQL could be written much more neatly, but you may as well start with the query design window.
i guess the date has a own field in the database you open
then you can do something like this
strSQL = "SELECT * FROM reports WHERE Date >= " & now() -7
rs.open(strSQL)
' for the last week
strSQL = "Select * FROM reports WHERE Date >= " & now() - 30
rs.open(strSQL)
' for the last month
but you will need to format now() to the same format as it is in your Table
and that is just kinda the rawest code. i had to handle something similar and this worked out quite well

How can I write an MDX statement or query that selects the clients who paid last month but have not paid this(Current Month) month?.

How can I write an MDX statement or query that selects the clients who paid last month but have not paid this(Current Month) month?. I have a data cube designed and deployed on Microsoft SQL Server Analysis Services R 2. I have a customer dimensions and a fact table.
Please help.
I assume you have a [Time] dimension, and a measure that contains a value if the client has paid. I think the Filter() function will help you reduce a set of all clients down to just the clients that you're interested in.
SELECT {Filter({[Client].[SomeLevel].members}, ([Time].[LastMonth], [Measures].[whatever]) > 0 AND ([Time].[ThisMonth], [Measures].[whatever]) = 0} ON ROWS, {[Measures].[whatever]} ON COLUMNS FROM [CubeName]
You trouble might be deciding what to use in place of where I wrote [Time].[ThisMonth] - see other answers here on StackOverflow for selecting 'current' dates.
First of all, you have to identify the current month and the last month. One way to do it is compute it using the VBA!Date function.
So if your dates are stored in the format 12/31/2014 and assuming you have a measure Payment and a Date dimension with a Year-Quarter-Month-Date hierarchy, the below code can help you.
WITH MEMBER [Measures].ValueThisMonth AS
(
[Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT,
[Measures].[Payment]
)
MEMBER [Measures].ValueLastMonth AS
(
[Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT.LAG(1),
[Measures].[Payment]
)
SELECT [Client].[Client Name].MEMBERS
HAVING ISEMPTY([Measures].ValueThisMonth)
AND NOT(ISEMPTY([Measures].ValueLastMonth))
ON 0
FROM [Your cube]
WHERE
StrToMember("[Date].[Year-Quarter-Month-Date].[Date].&[" + FORMAT(VBA![Date](), "MM/dd/yyyy") + "]" + "]")
If instead you would like to pass this "current" value from the front end, use a parameter in the WHERE clause.

Query by month from date field

I have a set of Access d/b's grouped already by year. within a given year, I have a field caleld REPORTDATE which is a standard mm/dd/yyyy field. However, I need to produce queries that return data by the month. For example, I just want to see records for Jan, recs for Feb, Recs for March, etc., so that I can sum them and work wwith thm.
Do I use an expression in the query design view Criteria field?
Thanks in advance.
I just want to see records for Jan, recs for Feb, Recs for March, etc., so that I can sum them and work wwith thm.
You can do all of that in one sql statement:
select month(reportdate), sum( the column you wish to sum )
from tablename
group by month(reportdate);
BUT WAIT THERE'S MORE!
Further say that there are several salepersons selling stuff, and you wish to show each salesperson's sales by month
select month(reportdate), salesperson, sum( the column you wish to sum )
from tablename
group by month(reportdate), salesperson;
That shows the sum per month per salesperson.
You know the Germans always make good stuff!
What it you wanted to see the same sums, but rtaher than comparing salespeople against each other in each month, you wanted to compare, for each salesperson, how they did from one month to another?
Just reverse the order of the group by:
select month(reportdate), saleperson, sum( the column you wish to sum )
from tablename
group by salesperson, month(reportdate);
Tacos, Fettuccini, Linguini, Martini, Bikini, you're gonna love my nuts!
The power of SQL! As seen on TV! Order now!
"select month(reportdate), sum( the column you wish to sum )from tablenamegroup by month(reportdate);" THIS IS VERY HELPFUL, THANK YOU. AND YOU ARE HILARIOUS. HOWEVER, can you clarify for me where the heck this code goes?! In the expresison Builder or what? Thank you SO much. – rick (19 mins ago)
In Access, I think from the graphical Query Builder thing's menu, select edit|SQL, and just type. And never go back to graphical!
You're a hard-charging forward-thinking entrepreneurially-minded man on the move! This is not your father's Oldsmobile! You wouldn't use an on-screen keyboard to type a document, dragging and dropping letters on the page, would you?! So why do that to build a SQL Query? Get into SQL! AS SEEN ON TV! All the cool kids and hep cats are doin' it! Order NOW!
You can use format, for example:
Format([REPORTDATE],"mmm yy")
Or Month:
SELECT * FROM Table WHERE Month([REPORTDATE]) = 10
An outline of query that may suit, paste this into the SQL view of
the query design window, changing table to the name of your table:
SELECT Format([REPORTDATE],"yyyy mm"), Count([ReportDate])
FROM Table
GROUP BY Format([REPORTDATE],"yyyy mm")
I wouldn't do this in the report's recordsource. I'd make the recordsource a regular SELECT statement and use the report's sorting/grouping. If you group on a date field (one that is really date type), you get the choice to GROUP ON:
Each Value (default)
Year
Qtr
Month
Week
Day
Hour
Minute
I think this is faster than a GROUP BY on a function, but someone who was interested should actually try it.
Certainly if your SELECT with GROUP BY has no WHERE clause, it's going to be a lot more efficient if you run the report with filtered values.