SSRS 2008 Dynamic Columns in a Matrix Report? - sql-server

I have SQL 2008 (not R2). I would like to have a matrix report where user can select one of the SQL resultset columns to be the matrix column group..
For example
A B Value
a1 b1 10
a2 b2 20
a3 b2 30
So the possible matrices could be (user selects from dropdown with A, B).
By A
a1 a2 a3
Value 10 20 30
By B
b1 b2
Value 10 50

This question should solve your problem. It is a way to use a parameter to refer to a field in your dataset.

i havne't actually done anything like this before, but i have a theory that you can modify the expression on the group to have an iif statement to change which field is grouped on
so, for the column group, change the expression for the gorup to something like =iif(ParameterValue=1,Field1,Field2)

Related

Excel index and match with multiple conditions with multiple results

I am trying to perform an index and match formula in Excel with a two large datasets which will return multiple unique results.
I have illustrated a simplified version of the data below. The two match conditions are A1 in table 2 = A:A in Table 1 and B2 in table 2 = B:B in table 1. This will result in multiple results and I want a formula I can drag from cells C3 across to D4 in table 2 to show the results of this index and match.
Table 1
First Name
Second Name
Food allergy code
Bob
Johnson
03
Bob
Johnson
04
Table 2
First Name
Second Name
Food allergy code 1
Food allergy code 2
Bob
Johnson
03
04
I have used the formula below which returns the first match, but when I drag this from cell C2 to D2 it returns the same value. I'm not sure how to rewrite this formula so that it provides each unique Food allergy code given both match conditions are met.
=TRANSPOSE(INDEX(Table1!C:C,MATCH(1,(Table1!A:A=A2)*(Table1!B:B=B2),0)))
Any help would be appreciated.
You could use the following, but it is computationally rather inefficient, so if you want to drag this formula over many cells, you should leave a comment to find a computationally more efficient solution.
=TRANSPOSE(FILTER(D:D,(B:B=G4)*(C:C=H4)))
which looks like this in an example:

excel sumif multiple columns data

My data is:
I need to calculate a sum of the "col1" and "col2" where "name" is "a": 1+2+5+6 = 14.
Now I am using:
=SUMIF(A:A,"a",B:B)+SUMIF(A:A,"a",C:C)
Is there any better way (eg with arrays)?
Try this, for the sum of values where name is a,
Formula in cell B6 --> Applicable To All Excel Users
=SUMPRODUCT(($A$2:$A$4=$A6)*($B$2:$C$4))
Formula in cell C6 --> Applicable To Only O365 & Excel 2021 Users
=SUM(FILTER($B$2:$C$4,A6=$A$2:$A$4))

how to use the Pivoted Column values in Matrix use in another Tablix and write expressions on top of it

I have one set of data with fields
StudentId, Name , Address in one dataset and being used in one Tablix.
also another set of data: StudentID Subject Marks in another Dataset and using Matrix to Pivot in the Report.
I am able to fetch the Report in this way
StudentID Name Address MAths Physcis Chemistry Median
1 Mike NJ 85 70 90 2
2 David CA 81 85 90 1
I was calculating Median by counting number of Subject Marks greater than 80.
Now how do I use the value of Median in Tablix instead of in Matrix.
Below should be the expected output format
StudentID Median Name Address MAths Physcis Chemistry
1 2 Mike NJ 85 70 90
2 3 David CA 81 85 90
Note: I am using Matrix to Pivot Subject Column in SSRS Report. I am using Pivot operation in SSRS instead of performing in SP because I get 40 columns after Pivoting in SP and need to physically map 40 columns. Here in example I have only given 3 columns(Maths, Physcis and Chemistry).
Also please do let me know if expected output format is at least possible.
Is there any way that I will be able to Pivot Subject Columns inside the Tablix itself instead of using the another Matrix??
Thank you.
There are two ways to typically go about an aggregation like this. If you stick with the two existing datasets, you'll have to use the Lookup or LookupSet functions to get data from the other dataset. For example, if your table/matrix is using the second dataset as it's source, you would Lookup the Name of each student. Keep in mind that this is not efficient for large reports.
The other approach, which I would recommend, is to join these two datasets in SQL and use that as the data source for the report. This is more efficient and makes the report simpler to maintain.
It's good that you are letting the report do the pivoting for you, it works much better that way.

Transpose every other row in a google sheet

I've been given a badly formatted sheet where there are thousands of records with X and corresponding Y value in the following row rather than the same row and next column.
Is there a function that will allow me to copy altering rows?
So...
A2 goes into B2 and A3 goes into C2
A4 goes into B3 and A5 goes into C3
etc
A sample sheet is in https://docs.google.com/spreadsheets/d/1fB2rpVdJiTmp96sjGZiIYvKxEL9DLiK7W7QU8-4AN3A/edit?usp=sharing
I'd prefer a Google Sheet solution but excel is fine as well.
delete everything in B2:C range and try:
={FILTER(A2:A, A2:A<>"", MOD(ROW(A2:A), 2)=0),
FILTER(A2:A, A2:A<>"", MOD(ROW(A2:A)+1, 2)=0)}

SQL tables design one table or two tables

I have a table with about 20 columns. It works well, its related to other table many to many, but it works fine and design is good so far.
Now I need to store another type of data, which has almost same columns, it has 15 columns that are basically same, but 5 columns are completelly different
between this 2 types. So how do I do it
1. do I store it in one table (by adding new Columns in first table -> this way some 5 columns would be null depending which type of data we save), or
2. split it to 2 tables and than each table has same columns repeated in other table
3. some other way ?
COLUMNS CASE 1 - STORE IN ONE SAME TABLE
ID INTEGER
Description NVARCHAR(max)
Value FLOAT
ValueEUR FLOAT
ValueUSD FLOAT
YearOfBuilt SMALLINT
New BIT
Requirements NVARCHAR(max)
FIELD A1
FIELD A2
FIELD A3
FIELD A4
FIELD A5
FK_TypeID INT
do I add 5 new fields for other document type to above table:
FIELD B1 FLOAT
FIELD B2 FLOAT
FIELD B3 FLOAT
FIELD B4 FLOAT
FIELD B5 FLOAT
In this case if I save data for type 1
saved field value would be null for columns FIELD B1, ... FIELD B5.
Well, it would work, but than some fields would be empty, depending on type.
or do I make table design as in case 2 below
COLUMNS CASE 2 - STORE IN TWO TABLES
TABLE 1
ID INTEGER
Description NVARCHAR(max)
Value FLOAT
ValueEUR FLOAT
ValueUSD FLOAT
YearOfBuilt SMALLINT
New BIT
Requirements NVARCHAR(max)
FIELD A1
FIELD A2
FIELD A3
FIELD A4
FIELD A5
FK_TypeID INT
TABLE 2 - Repeating same columns but excluding columns not needed for this table
ID INTEGER
Description NVARCHAR(max)
Value FLOAT
ValueEUR FLOAT
ValueUSD FLOAT
YearOfBuilt SMALLINT
New BIT
Requirements NVARCHAR(max)
FIELD B1 FLOAT
FIELD B2 FLOAT
FIELD B3 FLOAT
FIELD B4 FLOAT
FIELD B5 FLOAT
FK_TypeID INT
Now in this case 2, I would repeat same columns but exclude columns not needed. This means same columns names, however data are stored to save space (no null values).
Which approach would be better?
Or is there another way to do it? I am not beginner in database design.
Generally we split into two tables - this is called Database Normalisation: https://en.wikipedia.org/wiki/Database_normalization
Especially so if the same-columns are related in some way eg if they are contact details for two different kinds of people (eg customers vs employees) then you can name the new table after that (eg the new database would be called contact_details or something).
Basically: you're not saving anything (not space or optimising performance or anything) by storing it all in the same table. All you're doing is making the data more confusing for yourself or other developers to understand in the future.
Also, think of future queries you create - every one of them will have to filter out the data that's not relevant - which makes every single query more complex. Better to store different things in different tables and make it easier to understand-at-a-glance what's going on in your database+code

Resources