I have a report for which I need to get the number of bank accounts of each type for each team in my baseball league. I need a listing of the team, player, and account, with a subtotal footer that gives the counts of each kind of account for each team, like this:
Team
Player
Account
Yankees
Babe Ruth
Savings
Yankees
Lou Gehrig
Other
Yankees
Aaron Judge
Loan
Yankees
Joe DiMaggio
Savings
Yankees
Derek Jeter
Savings
Accounts:
Savings 3
Loan 1
Other 1
Total 5
Team
Player
Account
Red Sox
David Ortiz
Other
Red Sox
Pedro Martinez
Savings
Red Sox
Jackie Bradley Jr.
Other
Red Sox
Ted Williams
Savings
Red Sox
Pedro Martinez
Savings
Accounts:
Savings 3
Other 2
Total 5
So far I've done this by creating hide conditions for each of the rows so that they're only visible when there's an account of the designated type, but that gets cumbersome as the number of Account Types increases, and if I add a new account (say, Checking) the report has to be updated. How would I get this report to generate subtotals that only reference data that's present within the group?
To create the Accounts summary section you could use a table. The design would look like this:
This would need to be grouped by the Account column so that there is one row per Account value. You can remove borders and format as needed to make it look how you want.
Related
Hello Stack overflow (and anyone googling similar questions in the future)!
I have a dataset that regularly reports which products are absent on a warehouse stockcheck, which I am trying to use to analyse when stock is or isn’t available. I’m essentially trying to identify “Has a part been reported as missing? -> If so, count the number of days it is missing until another part in the same category is reported as missing, but the original part was not reported as missing on that date (as we can assume it’s back in stock)”.
I’ve managed to make this work in excel, but my spreadsheet began to die from the calculation of 5 locations worth of categories and parts, let alone across the 600+ I’m working on! As a result, I’m trying to set up a similar function in Access to analyse which, and for how long, parts were out of stock.
My dataset looks something like:
Location number
Location
Category
Date reported
Part Number
Part Description
Order number
1
London
Car
03/06/2021
2021
Wheel A
1
2
London
Bus
03/06/2021
1491
Seat C
2
3
Manchester
Car
01/06/2021
2021
Wheel A
3
My assumptions are that:-
• My data is fed by individual workers who each cover a location, and check all stock for a random selection of categories each visit (with the idea that they cover all of their location’s categories within a certain number of visits) and record which parts are missing. There is no particular visit plan – it can be a random number of days between each visit. This data gets fed into a central table, which I have access to.
• As my workers may not check all categories in a location on each visit, I must assume that a previously reported missing part is OOS until they check products in the same category, but do not report that part again.
I made this work on excel by setting up another column that concatenated my location, part number, and date reported, and then set up three tables (all of which are essentially locations, categories, and parts down my X axis, and dates across the Y axis):-
• Table1, to look if my concatenated code was reported for each day (and if so, output 1 – essentially working in days) – essentially, was each part reported as missing for each category and location?
• Table2, to look if any parts were reported for each category, for each location – essentially, how many parts were reported for each category for each location, and a value greater than 0 means we can assume that that category at that location has been checked by my workers for that date.
• Table3, that for each location+category+day asked as a formula – IF(category was checked as per table2 = yes , pull the value of 1 for that part/location/category in table 1 , re-use yesterday’s value for this part/location/day in this table). For the 1st day in my date range, I used the values for table1 for that day as a “starting up” point.
When I look at table 3, I can visually the run of days products were out of stock, and can from there crunch numbers related to that, which is what I want!
My initial Access plan was to set up three crosstab queries, to mirror my three excel tables. I can make Table1 and Table2 very easily, but for the life of me can’t make table3 work (currently have a calculated expression that mirrors the formula I had in table 3, but something has gone amiss…).
I’m looking for a steer/advice on setting up the expression in my crosstab query, or other ideas/approaches I could use to calculate how long each part is missing for. Any help would be greatly appreciated, as I’ve lost my mind going in circles today!
Edit:-
Simplified dataset I'm working with:-
Location
Category
Date Reported
Part number
Part Description
Order number
Concatenate code
Concatenate Code 2
1
London
Car
03/06/2021
2021
Wheel
1
1443502021
1
London
Bus
03/06/2021
1491
Seat
2
1443501491
2
Manchester
Car
05/06/2021
2021
Wheel
3
2443522021
1
London
Car
05/06/2021
2021
Wheel
4
1443522021
1
London
Car
07/06/2021
2021
Wheel
5
1443542021
1
London
Bus
05/06/2021
1860
Seatbelt
6
1443521860
1
London
Bus
05/06/2021
1860
Seatbelt
7
1443521860
2
manchester
Bus
01/06/2021
1860
Seatbelt
8
2443481860
2
Manchester
Bus
06/06/2021
1860
Seatbelt
9
2443531860
2
manchester
Bus
04/06/2021
1491
Seat
10
2443511491
2
Manchester
Bus
06/06/2021
1491
Seat
11
2443531491
I'm trying to output something like (which I've made work in Excel):-
Location
Category
Part code
01/06/2021
02/06/2021
03/06/2021
04/06/2021
05/06/2021
06/06/2021
07/06/2021
1
London
Car
2021
1
1
1
1
1
London
Car
2626
1
London
Bus
1491
1
1
1
London
Bus
1860
1
1
2
Manchester
Car
2021
1
1
2
Manchester
Car
2626
2
Manchester
Bus
1491
1
1
1
2
Manchester
Bus
1860
1
1
1
1
3
Liverpool
Car
2021
3
Liverpool
Car
2626
3
Liverpool
Bus
1491
Or to return the value for how many concurrent days out of stock a part has been, like per day of this version:-
Location
Category
Part code
01/06/2021
02/06/2021
03/06/2021
04/06/2021
05/06/2021
06/06/2021
07/06/2021
1
London
Car
2021
1
2
3
4
1
London
Car
2626
1
London
Bus
1491
1
2
1
London
Bus
1860
1
2
2
Manchester
Car
2021
1
2
2
Manchester
Car
2626
2
Manchester
Bus
1491
1
2
3
2
Manchester
Bus
1860
1
2
3
1
3
Liverpool
Car
2021
3
Liverpool
Car
2626
3
Liverpool
Bus
1491
My Access sql (that I then turned into a crosstab) to identify ordered parts per day:
SELECT DISTINCT T_stores.[Store Nos], T_stores.[Store Name], t_Stands.Brand, t_Productlookup.TPND, t_Productlookup.TITLE, t_gapdata.Quantity, t_gapdata.[Requested Date]
FROM ((T_stores
INNER JOIN t_Stands ON T_stores.[Store Nos] = t_Stands.[Store Nos])
INNER JOIN t_gapdata ON (t_Stands.[Brand] = t_gapdata.[Brand]) AND (t_Stands.[Store Nos] = t_gapdata.[Store No]))
INNER JOIN t_Productlookup ON t_gapdata.[Part Number] = t_Productlookup.[EAN];
And likewise, to identfy is parts were ordered for a location's category:-
SELECT DISTINCT T_stores.[Store Nos], T_stores.[Store Name], t_Stands.Brand, t_Productlookup.TPND, t_Productlookup.TITLE, t_gapdata.Quantity, t_gapdata.[Requested Date]
FROM ((T_stores
INNER JOIN t_Stands ON T_stores.[Store Nos] = t_Stands.[Store Nos])
INNER JOIN t_gapdata ON (t_Stands.[Brand] = t_gapdata.[Brand]) AND (t_Stands.[Store Nos] = t_gapdata.[Store No]))
INNER JOIN t_Productlookup ON t_gapdata.[Part Number] = t_Productlookup.[EAN];
These first two work fine, but I'm struggling to put them together with some sort of Iif calculated field for a third query:-
SELECT First(q_gaps_per_product.[Store Nos]) AS [FirstOfStore Nos], First(q_gaps_per_product.[Store Name]) AS [FirstOfStore Name], First(q_gaps_per_product.Brand) AS FirstOfBrand, First(q_gaps_per_brand_store.[Order Id]) AS [FirstOfOrder Id], First(q_gaps_per_product.TPND) AS FirstOfTPND, First(q_gaps_per_product.TITLE) AS FirstOfTITLE, First(q_gaps_per_product.[Requested Date]) AS [FirstOfRequested Date], First(IIf([q_gaps_per_brand_store]![Requested Date]>=[q_gaps_per_product]![Requested Date],[Quantity],"PREVIOUS DAY")) AS Expr1, [q_gaps_per_product]![Store Nos] & [q_gaps_per_product]![Quantity] & [q_gaps_per_product]![TPND] AS Expr2
FROM q_gaps_per_product LEFT JOIN q_gaps_per_brand_store ON q_gaps_per_product.[Brand] = q_gaps_per_brand_store.[Brand]
GROUP BY [q_gaps_per_product]![Store Nos] & [q_gaps_per_product]![Quantity] & [q_gaps_per_product]![TPND];
Expr1 is supposed to be how many days a product is out of stock, with the idea that "PREVIOUS DAY" would return the same criteria for the previous day, to show either running gaps or that a product was in fact available as a 0, but I haven't got that far yet.
Expr2 is basically something I tried to make up to group the results by, as I had an insane number of results due to my janky table relationships.
I sort of think this query is DOA, and I need to go back to the drawing board to reproduce something like my Excel tables / how many days out of stock products have been concurrently out of stock before.
Sorry for the sheer storm of words!
I want to create a report in access that shows sales forecast in 3 subreports (the next 30 days, 31-60 days and 61-90 days). I haven't been able to figure out how to create a report like that. I have 3 queries for each date range. I would like to group the data for each salesperson showing company, amount and date. Something like below.
Can I do it using subforms or is there a better way? Thanks.
30 days
Bob Smith
Acme $3000 10/31/2019
Detla $2000 11/12/2019
60 days
Julie Brown
Bigly $4000 12/05/2019
90 days
Bob Smith
Acme $2500 01/10/2020
Julie Brown
Bigly $3300 01/12/2020
I am designing a database, and I would like to know;
Can I answer this question with queries, how much skill employees earned from this trainings?
Is this a good structure to do it?
how much money spent per department
how much skill earned per employee
how much skill earned per department
id session_name Skill impact sugg dept function training_value training no
1 PHP Software 3 Sales 2 100usd 1
2 PHP Software 3 Finance 2 100usd 1
3 PHP communication 2 Sales 2 100usd 1
4 PHP communication 2 Finance 2 100usd 1
5 ASP Software 4 Sales 2 200usd 2
6 ASP Software 4 Finance 2 200usd 2
7 ASP database 1 Sales 2 200usd 2
8 ASP database 1 Finance 2 200usd 2
attended training table
id student_id training_no
1 1 1
1 1 2
student table
id name department
1 John 1
2 Mary 2
department table
id name
1 sales
2 finance
In the end I need to find skills for each student
john
software 7
communication 2
database 1
total spent
john 300 usd
total spent by department
sales 300 usd
Your schema looks OK to me.
You should, however, think about entities and relationships.
Your entities seem to be trainings, people, and departments.
You have a many:many relationship for people:trainings. That's good.
You have a one:many relationship for departments:people. That's also good.
It looks like you want some kind of relationship for trainings:departments. I'm guessing here, but you have a sugg dept column in your trainings table. Is that supposed to have a direct relationship to your departments table?
Do you actually need an extra entity called "attendance" rather than just a many-to-many relationship people:trainings. Do you want to record when a person did a training? Do you want to record how much that particular attendance cost? How about what marks they received if there was a quiz?
In that case, you'll want relationships where each person has zero or more attendances, each attendance has exactly one training, and each training has zero or more attendances.
My point: do the hard work of thinking through your entities and relationships, and the result will be a good design for your tables.
If I may put it another way: What part of the real world are you trying to capture in your data base? What's valuable in the real world that you want your data base to hold? In your application ...
Students are people. They are, umm, inherently valuable and persistent entities.
Trainings represent the labor and cost of creating them and presenting them.
Attendances represent the effort of students.
Departments probably pay the bill for attendances. They certainly represent power centers in your application.
What other items of value exist in this corner of the real world? Teachers? Managers? Venues (classrooms)? Equipment? Customers?
My point is, figure out your entities -- the items of value -- and the relationships between them. Then write your table definitions.
Background
I've got a table of price changes tblPriceChanges of various items tblItems (example below - data made up):
[tblPriceChanges]:
Timestamp Item Price
9AM 01/01/2013 Orange 50p
9AM 01/01/2013 Apple 30p
2PM 01/01/2013 Pen 80p
2PM 02/01/2013 Orange 55p
2PM 02/01/2013 Pen 85p
9AM 03/01/2013 Apple 25p
9AM 05/01/2013 Pencil 10p
9AM 05/01/2013 Pen 70p
2PM 05/01/2013 Pencil 15p <- Notice there can be multiple price changes on the same day
...
[tblItems]:
Item Category Ratio
Orange Fruit 1
Apple Fruit 3
Pen Stationary 2
Pencil Stationary 5
...
Problem
The end result is that I want to be able to see how the average price of each category changes through time - for example:
Specifically, the average price series of Fruits, for instance, should be calculated as the weighted average of Orange and Apple prices in a Ratio of 1:3. So in the end I'm looking to generate (via some combination of queries) the following table for the underlying data of the chart:
Timestamp Fruit Stationary
01/01/2013 40.0 80.0
02/01/2013 55.0 85.0
03/01/2013 50.0 85.0
04/01/2013 50.0 85.0
05/01/2013 50.0 75.0
...
(this data is also made up and so probably not consistent with the original example)
I've managed to get an inner join on the two tables, but not too sure how to proceed. My main problem is how to handle days with no prices changes such as 01/04/13. The average prices still exist, but is not getting picked up by any query I try.
So how to use queries to construct data for the chart?
One remark before we start on a solution: be careful not to use reserved words for field names. Timestamp is a reserved word. Access will let you name a column that way, but you may encounter strange issues later on, especially if you ever move to another database in the future or use some other tools that fetch data from your Access database.
So here, I renamed your Timestamp column to DateTimeStamp.
I think that your requirements would be more straightforward to implement in VBA rather than in pure SQL queries: while you can easily build a query that gets you the average of each category per day, you are going to struggle to fill-in the data for the days where you have no data.
Simple but incomplete SQL solution
However, maybe having these holes in your data isn't that much of an issue since the graph will simply skip those missing values (it's not like they would show up as a data value of 0.00).
In that case, the following query should give you the results:
SELECT Dateserial(Year([DateTimeStamp]),
Month([DateTimeStamp]),
Day([DateTimeStamp])) AS NormalisedDate,
tblItems.Category,
SUM([Price]*[Ratio])/SUM([Ratio]) AS AvgPrice
FROM tblPriceChanges
INNER JOIN tblItems
ON tblPriceChanges.Item=tblItems.Item
GROUP BY Dateserial(Year([DateTimeStamp]),
Month([DateTimeStamp]),
Day([DateTimeStamp])),
tblItems.Category
Would result in the following:
NormalisedDate Category AvgPrice
01/01/2013 Fruit 35
01/01/2013 Stationary 80
02/01/2013 Fruit 55
02/01/2013 Stationary 85
03/01/2013 Fruit 25
05/01/2013 Stationary 22.0833333333333
I'm trying to build an SSRS report where the dataset is "presented" to SSRS through the application (Microsoft Dynamics NAV2009). The concept of the report is simple - it's a list of pieces of equipment - computers, cellphones, etc. The table has a "related to equipment" field. So Equipment ID "CELL01" may have a "Related to equipment ID" = "Computer 123". And Equipment ID "CAR456" may also have a "Related to equipment ID" = "Computer 123".
I want to create a report that lists each piece of equipment, and below it, any "related equipment". Many of the pieces have no related pieces, so the listing needs to look like this:
COMPUTER001 Dell Latitude 4mb RAM
COMPUTER002 Dell Latitude 16mb RAM
COMPUTER123 Dell Latitude 8mb RAM
Related Equipment
CELL01 Nokia Cellphone
CAR456 2011 Ford Taurus
COMPUTER135 Sony Laptop 12gb RAM
CELL01 Nokia Cellphone
CAR456 2011 Ford Taurus
Note that the "related items" is only unidirectional - the related items need only to be reported under the "Related to" equipment, and not vice-versa.
I have done some due diligence and investigated recursive hierarchies. It appears that this method depends on every "child" having a "parent". In my case, most "children" are "NULL", i.e. most equipment does not have a "related to equipment" id. So if I try to create the list from the bottom up and use recursive hierarchies, in the example below, only the COMPUTER123 and its children would be listed. None of the the other "Parent" records (e.g. COMPUTER001) have any children.
Has anyone done an SSRS report similar to this? In "Pure" SQL, this would be akin to having a query using a left outer join, and listing the fields in the primary record even if the JOIN'ed results were NULL, e.g. a list of all salesmen with their orders booked for the week:
Select s.Name, i.Invoice_No, i.Invoice_Amt
from Salesperson s
LEFT OUTER JOIN Invoice i on
s.SalespersonID = i.SalespersonID
If Salesperson "Joe" didn't make any sales this week, but Salesperson "Sam" made 3 sales and Salesperson "Bruno" made 2 sales, You might expect a result something like this:
Name Invoice_No Invoice_Amt
Bruno 1287 200.00
Bruno 1289 400.00
Joe NULL NULL
Sam 1281 65.00
Sam 1283 450.00
Sam 1286 175.00
So how would you construct a Report where the output would be:
Bruno
Invoices:
1287 200.00
1289 400.00
Joe
Sam
Invoices:
1281 65.00
1283 450.00
1286 175.00
Any suggestions would be appreciated.
Ron