Column static grouping in Matrix - reporting-services

I'm trying to create a technical indicator in Microsoft SSRS. I have a dataset that has a table that tells me whether or not my product has passed various stages in testing and I want to take one of those stages and break it into two sub columns statically. So for instance I have temperature and want to break it out into min and max operating temp so the columns will look like:
| Weight | Height | Temperature | Length |
| min | max |
However I can't find any way to statically define the column breakdowns for Temperature, and one of my main problems is I need to pull the min max data from a different database than the rest of the information and therefore need to make it it's own dataset. Do you have any ideas on what I could group on or how to get this to split up?

I ended up figuring how to do this by creating a new row and then stretching the group over two columns. Then I just hid the unwanted columns with an if statement.

Related

Lookup on 2 datasets in SSRS

I am having a problem using Lookups in a ssrs report. The report takes in 3 datasets that I do not have the opportunity to edit or merge (three different cubes)
It is a sales report that should be grouped by Sales Manager and show the potential for sales and a "discounted potential" of sales. The problem I face is that I have to loop my table on DataSet1 since it is the only on that holds Sales Mangers.
Using LookupSet and LookupSum it is easy enough to get the potential from DataSet2. Something like:
=Code.LookupSum(LookupSet(Fields!Country.Value, Fields!Country.Value, Fields!Potential.Value, "DataSet2"))
The problem arises when I try to calculate the Discounted Potential form DataSet3
Namely because I need to perform the lookup based on a value that is not in DataSet1! Is this somehow possible?
The datasets and the desired report look like this
You should be able to change the dataset of the tablix to DataSet2 to get the desired results. Dataset2 is the only dataset that directly relates to both of the other datasets, and since nested Lookups are not allowed, and also since you cannot modify your datasets, this is necessary for this situation.
I'm not sure exactly what calculation you are using to end up with your "Discount" column, I couldn't figure out any formula that worked with all of your sample data shown. For my test I just took the Sum to make sure it was working, but you should be able to modify that to fit your needs.
I set up a tablix like so:
+---------------------------------------------------+
| Manager | Country | Potential | Discount |
| <Expr1> | [Country] | [Sum(Potential)] | <Expr2> |
+---------------------------------------------------+
With 2 row groups, the first grouping on Expr1, and the child group grouping on Country, where Expr1 is =Lookup(Fields!Country.Value, Fields!Country.Value, Fields!Manager.Value, "DataSet1") and Expr2 is =Sum(Code.SumLookup(LookupSet(Fields!Customer.Value, Fields!Customer.Value, Fields!Discount.Value, "DataSet3"))). I sorted the parent row group by Country to keep the sorting the same as you had it in your screenshot. Again though, you would likely have to modify Expr2 to fit your needs. If the discount is a percentage for that particular customer, then the following code should work for that, but the results don't match your screenshot so I'm not sure if this is what you are looking for:
=Sum(Fields!Potential.Value - (Fields!Potential.Value * Code.SumLookup(LookupSet(Fields!Customer.Value, Fields!Customer.Value, Fields!Discount.Value, "DataSet3")) / 100))
Results from using the modified Expr2 if Discount is a percentage:

MS Access order table by order in which records were entered

I have a table in Access that I use as a progress tracker/to do list, with one field containing the date (short text) and what I did that day (long text). An example would be like this
date | progress
----------------
6/20 | did item1
| tomorrow do item2 and item3
6/21 | long text I continue in the next line for visibilty
| continued
| to do tomorrow
6/22 | item6 completed
etc. I enter these things manually. the past 3 weeks or so that I have been updating this table, it opens in the same order every time -- the order in which I created the records. Recently, the table opened in a completely random order, and continues to open in that new order.
I know now that it would have been good to create an autonumber field and order it by that, or have the date field's default value =Now(). I ahve far to many fields to make a new ID field and manually number each record in the order I created them.
Is it at all possible to force the table to order the records in either the order I created the records, or at least the previous configuration (which was just ordered by the time created)?
Also, is there a better way to be doing this...? I want to just have a record for other people who will work with this in the future. In addition, I am new to SQL, and the Access SQl has weird/unique ways of doing things, so for some queries I know I may need in the future I keep a table with the query name and some documentation for what exactly it does and some notes about the syntax (the SQL editor does not allow for -- comments). Is there a better way to do this, too?
Thanks for any help!
one field containing the date (short text)
Dates should never be stored as anything else than date values. No exceptions.
So change the data type of the field to Date, sort on this, and your troubles are gone.
To order Null dates last:
Order By Abs([DateField] Is Null), [DateField]

SSRS Show a percentage of a a total value

I have a regular Table in SSRS. With 3 Groups...
(Parent) STORE - CLERK - PRODUCT (Child)
I have some regular aggregations. How many PRODUCTS Sold by a CLERK , How Many CLERKS Per STORE and Eventually How many PRODUCTS Per STORE
On top of the Regular Sums And Avgs, I need To Find Out The Percentage of PRODUCT (Type) Meaning a Particular value of that Group.
Example STORE 001 Has Sold 10 RADIOS (a PRODUCT) and There has Been 100 RADIOS sold by all Stores
So Basically What I Need is to show STORE 001 is Responsible for 10% of all RADIO Sales.
(A note: Ideally , I would Like to show this To adjust to the Data - So if I add new products It will group those as products (Naturally) but still give me those percentages)
= fields!product.value / sum(fields!product.value)
in its most basic form you would want to use something like this.
The first will give you the total of the current row of data and the second will give you the total of all rows of that product.
Thus you would have 10 / 100 (per your example).
This is assuming that you have your data structured correctly. Depending on the structure of you report you may need to add a scope to your total summation to make sure that you are not totaling any other datasets that may reference the same product or field.
sum(fields!product.value, "--your dataset here--")

MySQL group multiple(variable) rows into one row with multiple columns

I'm looking for a query that will return me several rows into columns but without knowing the number of rows beforehand. I have searched and the only solutions I found involve knowing how many rows there are.
Here's an example table:
parentID colA colB
2 aaaaaa 1000.00
2 bbbbbb 1500.00
3 cccccc 500.00
3 dddddd 700.00
3 eeeeee 2000.00
and i need it to look like:
parentID colA(n) colB(n) colA(n+1) colB(n+1) colA(n+2) colB(n+2)
2 aaaaaaa 1000.00 bbbbbb 1500.00 NULL NULL
3 cccccc 500.00 dddddd 700.00 eeeeee 2000.00
I realize this should be done in PHP but I need it to be in mysql for a third party excel exporter plugin I'm using.
Edit: Is there a way to do this if I know the maximum number of columns I'll need?
You cannot do a query in SQL without knowing the number of columns.
The columns of a SELECT-list must be fixed at the time of parsing the query. What you're asking for is that the state of data, which is not known until the query executes, determines the number of columns. That is not the way SQL works.
To accomplish a pivot-type operation, or any query where the data determines the columns, you have two choices:
Do a preparatory query to discover how many distinct groups you want to fetch, and use this to build the query with a matching number of columns.
Query all the data in rows, fetch it back into your application, and then transform the result set wholly within data structures (i.e. arrays) within your code.
Either way, you need to write application code, either before or after fetching the data.
Re your comment: You're right, this isn't a traditional pivot, but it's similar in that data is driving the number of columns. That is, you need as many columns as 2x the number of rows in the largest group. But they won't all be filled, because the number of rows per group varies. You don't have a fixed number of row per group, therefore you can't fill a fixed number of columns per group.
I'd really recommend you use the latter strategy: fetch the data as rows, as they are stored in the database. Then post-process it in your application code. Loop over the result set and build your data structure incrementally as you fetch rows from the database.
For example, in PHP:
while ($row = $stmt->fetch()) {
$data[$row['parentID']][] = $row['colA'];
$data[$row['parentID']][] = $row['colB'];
}

How to get MYSQL to show Zero results when left joining to self? (eg: Monthly Stats)

I have a table with typical statistics on page view and emails. An email creates a row and page view creates a row...
I want to chart the page views and emails on a daily basis for the past 30 days (for example) so I need to show the day and the value... even if it ZERO. I cannot have missing days from my results or the chart breaks.
PageViews Table:
UniqueID | PageID | DateTime
Emails Table:
UniqueID | SenderEmail | RecipientID | RecipientEmail | DateTime
I don't need this to be one query but the problem remains the same for either query... If there are days (or hours, or months.. depending on the group by range) where a specific page was not viewed it is simply omitted from the results array.
Similarly, if there there are days where there were page views but now emails, then the email count query has holes in it...
Essentially, I am trying to create a Google Analytics type chart and need the lines to show ZERO for the days where there are no data in my stats tables...
I think some kind of left self join might work but cannot seem to make it work. I even messed around with an integer table with only one column (values) and rows for 1-31
Can any of you MYSQL gurus help?
The standard solution for this problem is to create a helper table and populate it with all of the dates relevant to your anticipated queries.
Here's an applicable SO Q&A:
How to fill date gaps in MySQL?