Displaying a Crosstab Query with Variable Fields in a Subform - ms-access

Microsoft Access 2010 here. Working with reports (and forms).
I have a crosstab query that transforms (w/ UNION ALL, thank you Bluefeet!) and pivots another "source query" with the purpose of making the results more coherent to the reader. The source query has fields that do not change, but rows that do, as the source query only selects results from the past 30 days; the fields of the subsequent crosstab query are not expected to stay the same upon requery as the rows have become the fields and vice-versa. What I am wondering is how one would display such a crosstab query in a subform as-is; i.e. as a simple reference with no record-dependence.
An example of the variable fields in the crosstab query:
Criteria | 11/26/2012 | 11/27/2012 | 11/29/2012 | 12/6/2012 ...
# Insp | 7 | 8 | 8 | 9
# Passed | 5 | 4 | 5 | 7
# Failed | 2 | 4 | 3 | 2
% Acceptance | 71% | 50% | 63% | 78%
I have successfully tied the crosstab query to a subform "child" for display through it's "Source Object" property, and achieved the desired end-result, but there was the record selection bar which is undesired for a reference, and the option to display it, normally found on forms/subforms is gone on the subform "child."
This leaves me wondering if there is another way to do display crosstab queries in subforms, or if I am looking in the total wrong direction to achieve the task. The report includes a graph based on the source query and below that is to be the crosstab query, displayed purely for reference. Thank you for the help!

Related

mySQL - Reiteratively Count rows that have particular CSV string

2-column MySQL Table:
| id| class |
|---|---------|
| 1 | A,B |
| 2 | B,C,D |
| 3 | C,D,A,G |
| 4 | E,F,G |
| 5 | A,F,G |
| 6 | E,F,G,B |
Requirement is to generate a report/output which tells which individual CSV value of class column is in how many rows.
For example, A is present in 3 rows (with id 1,3,5), and C is present in 2 rows (with id 2,3), and G is in 4 rows (3,4,5,6) so the output report should be
A - 3
B - 3
C - 2
...
...
G - 4
Essentially, column id can be ignored.
The draft that I can think of - first all the values of class column need to picked, split on comma, then create a distinct list of each unique value (A,B,C...), and then count how many rows contain the unique value from that distinct list.
While I know basic SQL queries, this is way too complex for me. Am unable to match it with some CSV split function in MySQL. (Am new to SQL so don't know much).
An alternative approach I made it to work - Download class column values in a file, feed it to a perl script which will create a distinct array of A,B,C, then read the downloaded CSV file again foreach element in distinct array and increase the count, and finally publish the report. But this is in perl which will be a separate execution, while the client needs it in SQL report.
Help will be appreciated.
Thanks
You may try split-string-into-rows function to get distinct values and use COUNT function to find number of occurrences. Specifically check here

MS Access: How to compare and filter data in a column

I am a new user and here is my first question,
I have newly started working on MS access and I am having problems to filter maximum of a column data but according to the data in an another column as well.
Let me explain the situation with a test data:
Table consists of Column A, is a short text, and column B is an integer,
Test Data
With a query, i want to filter out only AA-02, BB-04 and CC-06,
I can compare values in a column very easily in excel however i am having problems in Access,
Thanks for your time in advance.
Best Regards,
M.ER
assuming you want the last instance of column B this is a simple sql Totals query. Using the Query Designer:
In the SQL Tab (not shown but bottom right of the query designer)
SELECT Test.ColumnA, Last(Test.ColumnB) AS ColumnB
FROM Test
GROUP BY Test.ColumnA;
Result:
| ColumnA | ColumnB |
| AA | 2 |
| BB | 4 |
| CC | 6 |

SSRS Calculating Totals

In SSRS I have a report generated from a stored procedure. I have one column that is named "Price" and the report has various groupings (shown below). So because there are so many groupings there are a lot of totals for price. I need to roll these totals up into the parent grouping of TimeRange as an average. This is so I can know the average price of Z product was X. I obviously know that this is done by adding up all those totals and dividing by the amount of totals but I don't know how this can be done in SSRS. Is it possible to dynamically add up all those totals? Or maybe set some kind of global variables to handle this?
EDIT: I described the problem a bit wrong. It seems the main problem is the fact that the price data returns all positive "prices" then the report uses the other columns to define if the price is negative or not(if we bought something or sold something). Since I didn't think there was a way to compensate this through the microsoft code. I Grouped them together based on the rules and multiplied the prices that should be negative by -1. I Now want to figure out a way to take these individual totals and combine them into one Subtotal. It would do this by taking a Sum of the totals. Just doing a straight Sum(Price) doesn't help because that will just get all of the values directly from the query before the report touches them and those values are all positive which throws off the report data.
So i guess there are three solutions here:
1.There is some magical SSRS code that allows me add together data that is outputted from an expression instead of the initial database value and does that dynamically..
2.There is some kind of way to define and assign global variables in the report then I could use some kind of psuedo code to add and subtract data from the variable and then take the average of the total
3.This is currently not possible and I will have to completely rewrite the source data's process or come up with another solution that's not SSRS.
TimeRange
_
| Product
| _
| |
| | Time Unit
| | _
| | |
| | | TransactionType
| | | _
| | | |
| | | | Pay Status
| | | | Price Total Calculated Here [Sum(Price)]
| | | |_
| | |
| | |_
| |
| |_
|
|
|
|_
Reporting Services makes this very easy - in fact, if you were to just use the wizard (table wizard in Report Builder, report wizard in Visual Studio/BIDS), and add all of your grouping fields to the "groups" section, and then enable subtotals, the summing would be done for you, and you could then alter the field using an expression to divide the two summed fields.
Here's a link to some more useful information on grouping and aggregates:
http://technet.microsoft.com/en-us/library/ms170712.aspx
Use the Avg function to get an average of all the values in your grouping:
=Avg(Fields!Price.Value)

"You cannot add or change a record because a related record is required", but related record exists?

I have two related tables, results and userID.
results looks like this:
+----+--------+--------+
| ID | userID | result |
+----+--------+--------+
| 1 | abc | 124 |
| 2 | abc | 792 |
| 3 | def | 534 |
+----+--------+--------+
userID looks like this:
+----+--------+---------+
| id | userID | name |
+----+--------+---------+
| 1 | abc | Angela |
| 2 | def | Gerard |
| 3 | zxy | Enrico |
+----+--------+---------+
In results, the userID field is a lookup field; it stores userID.id but the combo box has userID.userID as its choices.
When I try to enter data into results by setting the userID combo box and entering a value for result, I get this error message:
You cannot add or change a record because a related record
is required in table `userID`.
This is strange, because I'm specifically selecting a value that's provided in the userID combo box.
Oddly, there are about 100 rows of data already in results with the same value for userID.
I thought this might be a database corruption issue, so i created a blank database and imported all the tables into it. But I still got the same error. What's going on here?
Both tables include a text field named LanID. You are using that field in this relationship, which enforces referential integrity:
The problem you're facing is due to the Lookup field properties. This is the Row Source:
SELECT [LanID].ID, [LanID].LanID FROM LanID ORDER BY [LanID];
But the value which gets stored (the Bound Column property) is the first column from that SELECT statement, which is the Long Integer [LanID].ID. So that number will not satisfy the relationship, which requires results.LanID = [LanID].LanID.
You must change the relationship or change the Lookup properties so both reference the same field value.
But if it were me, I would just eliminate the Lookup on the grounds that simple operations (such as this) become unnecessarily confusing when Lookup fields are involved. Make results.LanID a plain numeric or text field. If you want some kind of user-friendly drop-down for data entry, build a form with a combo or list box.
For additional arguments against Lookup fields, see The Evils of Lookup Fields in Tables.
If you are using a parameter query, make sure you have them in the same order as the table you are modifying and the query you have created. You might have one parameter inserting the conflicting data. Parameters are used in the order they are created...not the name of the parameter. I had the same problem and all I had to do was switch the order they were in so they matched the query. This is an old thread, so I hope this helps someone who is just now having this problem.

ReportViewer Table

Any idea how can i accomplish the next scenario in a rdlc?
I have some rows (PrimaryKey,col1,col2,col3)
I want to display a table like this:
Labels of my fields | FirstRowValues | SecondRowValues |
___________________________________________________________________
Label for Primary key | PrimaryKey1.Value | PrimaryKey2.Value |
Label of col1 | Col1.Value(row 1) | Col1.Value(row 2) |
Label of col2 | Col2.Value(row 2) | Col2.Value(row 2) |
In other words, instead of having my database rows being repeated on diferrent rdlc rows, i would like to have them repeated on different columns.
I hope i was clear enough about what i'm looking for.
Thanks in advance
You can use the Matrix control (instead of the Table), or use PIVOT and do it in your database query.
I think are using the VS report designer, not SSRS (SSRS does not create RDLCs that can be viewed in the VS 2008 ReportViewer control).
10x 4 ur response, but i wasn't looking for that. Solved my issue by using a matrix with a column group by expression "1", and then added multiple rows on this group. Not the most elegant solution, but works.