SSRS 2008 Matrix - Column Data Incorrect - reporting-services

I am trying to convert an old local Crystal Report. Basically, for a given order, there are multiple line items. The report needs to show Order and Vendor in the left two columns, then a variable number of columns (that fit on a page) to display the line numbers.
To do this, I added a Matrix, and adding the groupings and all that. However, I get only one line item for each Order/Vendor combination, even though each combination has at least two line items.
Current:
============================================
+ Order + Vendor + Item 1 + Item 2 ...
============================================
+ OrdValue1 + VendValue1 + Value + [blank]
============================================
+ OrdValue2 + VendValue2 + [blank]+ Value
============================================
Desired:
============================================
+ Order + Vendor + Item 1 + Item 2 ...
============================================
+ OrdValue1 + VendValue1 + Value + Value
============================================
+ OrdValue2 + VendValue2 + Value + Value
============================================
Edit:

I would go back to the source Dataset (assuming it is SQL) and add a Column_Number calculation which resets to 1 for each Order + Vendor combination, e.g.
ROW_NUMBER () OVER ( PARTITION BY Order , Vendor ORDER BY Line_Number ) AS Column_Number
Then I would edit the Column Group defintion to use that Column_Number column.

Related

How to remove specific number in string that is in random order?

Lets say that I have data rows that look like this:
+----------------------------+
+ test_table +
+----+--------+--------------+
+ id + word + updated_word +
+----+--------+--------------+
+ 1 + g00gle + ggle +
+ 2 + bread0 + bread +
+ 3 + 0bject + bject +
+ 4 + d0d0 + dd +
+-------------+--------------+
What statement could I use to take out the zeroes in the word column, so that it looks like the updated_word column? I thought of using substring, but didn't know how to proceed after that.
try:
UPDATE test_table
SET word = REPLACE(word, '0', '');
replace the 2nd blank '' with anything you want to change with.

Multiple definitions in a single Mysql Trigger

I have created a multi-page survey form that collects a value of 1 to 10 on each page.
With that data I need to insert 3 different calculations into 3 different columns in the database.
I have created a trigger that adds up all the numbers from the 20 pages and inserts it into the total score column but I need 2 other subscale scores and my version of mysql limits 1 trigger with the same action per table.
is it possible to have one trigger that can insert values into 3 different columns?
I am trying to do this via phpMyAdmin
My deinition below that works for total score:
[![enter image description here][1]][1]
SET NEW.total_score = NEW.answer_01 + NEW.answer_02 + NEW.answer_03 + NEW.answer_04 + NEW.answer_05 + NEW.answer_06 + NEW.answer_07 + NEW.answer_08 + NEW.answer_09 + NEW.answer_10 + NEW.answer_11 + NEW.answer_12 + NEW.answer_13 + NEW.answer_14 + NEW.answer_15 + NEW.answer_16 + NEW.answer_17 + NEW.answer_18 + NEW.answer_19 + NEW.answer_20;
The mysql site - http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html
mysql> CREATE TRIGGER ins_transaction BEFORE INSERT ON account
-> FOR EACH ROW PRECEDES ins_sum
-> SET
-> #deposits = #deposits + IF(NEW.amount>0,NEW.amount,0),
-> #withdrawals = #withdrawals + IF(NEW.amount<0,-NEW.amount,0);
comma separating the columns seems to be the solution
So for your code it would be like...
SET NEW.total_score = NEW.answer_01 + ... + NEW.answer_20,
NEW.other_column = NEW.answer_01 + NEW.answer_02;

finding maximum data from multiple rows

Below is what I have
++++++++++++++++++++++++
+ id + field1 + field2 +
++++++++++++++++++++++++
+ 1 + 1 + +
+ 1 + 23 + +
+ 1 + + 1 +
+ 1 + + 33 +
+ 2 + 55 + +
+ 2 + + 2 +
+ 2 + + 23 +
++++++++++++++++++++++++
What I want is
++++++++++++++++++++++++
+ id + field1 + field2 +
++++++++++++++++++++++++
+ 1 + 23 + 33 +
+ 2 + 55 + 23 +
++++++++++++++++++++++++
I want to combine the rows (with greatest data) and show data for user in one row against multiple rows like I have in table.
Any idea how to do it?
Note : I don't have any row who have data for all fields. Only 1 data in one row and two or more rows per user.
I tried with
SELECT id, GROUP_CONCAT(MAX(field1)), GROUP_CONCAT(MAX(field2)) from myTable
GROUP BY id;
but its giving error as
Invalid use of group function:
data at sqlfiddle
This question is bit advanced to my earlier question, showing data in one row (from multiple rows)
SELECT id, MAX(field1), MAX(field2) FROM myTable GROUP BY id;
This simple query should do the trick.
SELECT id, MAX(field1), MAX(field2)
FROM myTable
GROUP BY id;
it groups all the rows with the same id and selects the maximum value within each group for each column

Totalling based on expression field

In reporting services, I have used
=IIf(Fields!Weekday.Value="Su"
or Fields!Weekday.Value="Sa"
or Len(Fields!HOLIDAY.Value)>0,
(Fields!GENERAL.Value
+ Fields!LAUNCH.Value
+ Fields!SHIFT.Value
+ Fields!OCESAWE.Value
+ Fields!OCESAWD.Value
+ Fields!WEPHWORK.Value
+ Fields!OCREMWE.Value
+ Fields!OCREMWD.Value) * 1.5,
(Fields!GENERAL.Value
+ Fields!LAUNCH.Value
+ Fields!SHIFT.Value
+ Fields!OCESAWE.Value
+ Fields!OCESAWD.Value
+ Fields!WEPHWORK.Value
+ Fields!OCREMWE.Value
+ Fields!OCREMWD.Value)
)
To get a columnn called "Total Weighted" and this column have several rows.
1. ID Total Weighted
2. 111 21
3. 121 49
How can I get the total of the "Total Weighted?
Create a calculated field in your dataset, and use the formula you provided as the value of that field. Now you can refer to that field elsewhere as if it came from your database.
So then you'd use an expression like =SUM(Fields!TotalWeighted.Value) in your tablix.

I need help finding the average number out of 60 columns, where the columns number does not equal 0

We have 2500 products on our site, ranked between 60 different categories. Our DB scheme is 61 columns, labled "product_id", and then the categories: "category_1", "category_2"... "category_60", and 2500 rows, one for each product. If a product is not ranked in a specific cateogry, that corresponding field is marked "0". If it is ranked, the field is an INT with whatever rank it is: "1" is 1st, "2" is second, etc.
Usually products are only ranked in 2-3 categories, so there are 57+ columns with a "0" in the field. My current query is:
mysql_query("SELECT AVG(category_1 + category_2 + category_3 + category_4 + category_5 + category_6 + category_7 + category_8 + category_9 + category_10 + category_11 + category_12 + category_13 + category_14 + category_15 + category_16 + category_17 + category_18 + category_19 + category_20 + category_21 + category_22 + category_23 + category_24 + category_25 + category_26 + category_27 + category_28 + category_29 + category_30 + category_31 + category_32 + category_33 + category_34 + category_35 + category_36 + category_37 + category_38 + category_39 + category_40 + category_41 + category_42 + category_43 + category_44 + category_45 + category_46 + category_47 + category_48 + category_49 + category_50 + category_51 + category_52 + category_53 + category_54 + category_55 + category_56 + category_57 + category_58 + category_59 + category_60) as 'cat_avg' FROM products.rankings WHERE product_id = '$product_id'");
With this, I'm just getting the sum of the columns, not the AVG. Maybe this has something to do with selecting rows instead of columns, I'm not sure. I tried SUM as well, instead of AVG, same thing.
I'm not really sure where to go from here. What i would like is the Average ranking across all columns for one product, where the column doesn't equal 0. So if a product_id 123 is ranked 7, 9 and 11, and then the other 57 columns are 0, the average returned would be 9 ((7+9+11)/3), not .45 ((7+9+11+0+0+0....+0))/60)
Note: I did not design this DB, I'm sure there is a better way to design it, but at this point it's too deeply integrated to change up quickly.
This may be a lot of stress on the query, but I don't know many other ways to do this, given the schema you have to work with.
One option is to sub-query the columns and union them, where the given columns are not 0:
SELECT AVG(
SELECT *
FROM (
SELECT category_1 AS category FROM table
UNION
SELECT category_2 AS category FROM table
UNION
...
) cats
WHERE category <> 0
)
FROM products.rankings
WHERE product_id = '$product_id'
It probably makes more sense to do this math within the page (assuming PHP given the query decorations) and on a per-row basis. Doing the above will put a lot of strain on the server depending the number of rows we're talking.
Restructured the whole DB... wasn't as bad as I though, just did a bunch of MySQL queries/updates that got me what I needed. Strained the server for a few hours, but it was well worth it in the end.