I have multiple tables with some rows and columns in sql.
Columns are like (Key, column1,column2,column3), I did unpivot tables in sql.
And got dataset in ssrs like : TableName, Key,ColumnName,ColumnValue.
I've created multiple matrixes like below structure for each table by setting filter = "TableName":
----------------------
Key | [ColumnName]
----------------------
[Key] | [ColumnValue]
------------------------
Question: How I can do sort (order by) based on column in SSRS matrix. I have as I said multiple matrixes. 1st matrix I want to sort by Column1, 2nd matrix by Column2, 3rd Matrix by Column2 and Column3 Where I need mention to sort by certain column name?
So far I've tried to sort my first Matrix.. tried it with "Row Group Properties ----> Sorting ---> Expression : SUM(IIF(ColumnName="Column1",ColumnValue,0)), but it didn't work. Also I've tried COUNT instead of SUM. No luck so far.
I solve it by this...
So if we want to get like "Order by Column1" then after unpivot Put your dataset in the matrixes. Go the the matrix which you want to Sort by specific column (in my case column1) Row group properties---->Sorting----> Add---> Expression:
MAX(
IIF(Fields!ColumnName.Value="Column1",Fields!ColumnValue.Value,Nothing)
)
and if you want to ad also Column2 to this matrix to sort, just after set 1st expression hit "Ok" and in the same window click --->add---> expression----> same query but with your column name (ex. Column2).
Hope this will help to some one.
Related
I got a sum Table 1 from a dataset, grouped by a parent Group 1 and a child group 2.For C, it sums values for different Sites.
The table I really want is to merge the SumValue under one column and re-name the group, e.g., C1 & C2 instead of Site-C1 & Site-C2.
I have tried to rename the Group 2 from Site_C1 and Site_C2 to C1 and C2, but it still splits to different columns:
Thank you for your help in advance.
It is similar to a question you posted before. As I said in that moment you can use an expression to conditionally set the grouping settings in your matrix. Add a matrix and add the Group 1 to Column Groups
In the Group properties / Group on put this expression:
=IIF(
Fields!Group.Value="C",
RIGHT(Fields!Subgroup2.Value,2),
Fields!Group.Value
)
Note Subgroup2 is Group 2 in your case.
Put the same expression on the header (the selected cell in the screenshot). It will preview the following matrix:
Let me know if this helps.
I would add one ore more calculated field to the dataset. There you can add the values of the relevant columns like this:
=IIF(IsNothing(Fields!C10.Value), 0,Fields!C10.Value)
+ IIF(IsNothing(Fields!C11.Value), 0,Fields!C11.Value)
+ IIF(IsNothing(Fields!C11.Value), 0,Fields!C12.Value)
In your table, don't bind a column to C10, C11.. but bind it to the calculated field.
I need to get the total transaction in the table and our formula involves a count distinct that's why I used derived column and aggregate transformation.
Now that I have the result, I want to add the output of aggregate transformation with another table. I tried union all, but it adds the output in the last entry.
Example:
Table1
businessdate,storekey,itemkey,vf,trasnumber
1000,200,200,N,1234
1000,200,123,N,1235
1000,200,124,N,1235
1000,200,200,N,1236
1000,200,200,T,1236
AggregateTable
formula: (count distinct transnumber than have vf=n) subtract it with (count distinct transnumber that have vf=t)
result
4
I want the combined table to look like this:
Table2
businessdate,storekey,itemkey,vf,trasnumber,result
1000,200,200,N,1234,4
1000,200,123,N,1235,4
1000,200,124,N,1235,4
1000,200,200,N,1236,4
1000,200,200,T,1236,4
Would like to ask help on how I can add the result of aggregate transformation at the end of each row in table 1.
Thank you very much.
I would add a "Dummy Merge Key" e.g. an integer with a fixed value of 1 to both data flow paths (from Table1 and from AggregateTable).
Then you can use a Merge Join transformation to connect the 2 paths (joined on the "Dummy Merge Key", and add the "result" column.
Add an OLE DB Command transformation after the aggregate. This would contain SQL similar to this update table1 set result = ? where businessdate = ? and storekey = ? You can then tie the "?" parameters to the output from the Aggregate transformation (I'm assuming here that businessdate and storekey are the keys that you've aggregated on)
How do I calculate the formula Sum([PRODUCT_VAL] ) for Distinct( [ID]) in SSRS?
[PRODUCT_VAL] and [ID] are two columns in the dataset.
I think I need to iterate through rows of a DataSet in custom reports code, to find Distinct [ID] and make SUM for those values [PRODUCT_VAL], but is it possible?
Or is there a better solution?
It sounds like you are trying to do a sum where the ID is a certain value, similar to the SUMIF function in Excel? Two ways you can achieve this (let's say 1 is the value of ID that you want to select on):
SSRS Expression
=SUM(IIF(Fields!ID.Value = 1, Fields!PRODUCT_VAL.Value, 0.00))
SQL in your dataset
SELECT ID, PRODUCT_VAL, CASE WHEN ID = 1 THEN PRODUCT_VAL END AS ProductValForID1
FROM MyTable
and then sum on the ProductValForID1 field.
I have a column name 'APPs % of total' and it requires two different data sets to be populated .This doesn't seem to work. Any tips will be appreciated. Thanks
=(Fields!AppQty.Value/Fields!AppQty.Value,"second dataset")
The problem is: how does SSRS know which row to pull from the second dataset to get the field? So you have to use aggregation or lookups:
Method 1: Simply aggregate at the current level
There's usually no need for a secondary dataset just for your sums. You can aggregate at the group level within the current dataset by using the following formula:
=Fields!AppQty.Value / SUM(Fields!AppQty.Value, "table1_Group1")
where table1_Group1 is the group where the data is summarised.
Method 2: Aggregate the entire dataset
Aggregate at the dataset level for the either the current dataset or a secondary one:
=Fields!AppQty.Value / SUM(Fields!AppQty.Value, "SomeDataset")
Method 3: Lookup the value from another dataset
You'll need a dataset that sums the values at a group level. You usually achieve this result using method 1 and grouping, but here for completeness. So, let's say you are grouping by DepartmentId, you would have a dataset that aggregates like so:
SELECT DepartmentId, SUM(AppQty) AS AppQty
FROM MyTable
GROUP BY DepartmentId
Then lookup the appropriate value for the department from the current row (in the current table's dataset):
=Fields!AppQty.Value / Lookup(Fields!DepartmentId.Value, Fields!DepartmentId.Value, Fields!AppQty.Value, "SummaryDataset")
So the Lookup matches the DepartmentId from this dataset with the DepartmentId in the SummaryDataset and returns the AppQty value.
I'm trying to create an ssrs report. Here's the data i have:
original data
I need to grouping and numbering based on specific column but ignoring the Entire entry row, the final result should be like this.
result
What's the grouping should be on case like this so i can put the number just like in my screenshot ?
Insert a matrix , row groups for Warehouse, Column1, Column 2
and for column groups use Amount, insert amount field with aggregate function of sum.
to add in the No. row, you will need to insert a empty column between column1 and column2 and insert an expression similar to:
=RunningValue(Fields!Test_case.Value, CountDistinct,"Tablix3" )
Whereby Fields!Test_case.Value is equivelant to Column1 and Tablix3 is equivelant to your matrix.
Example of design and report outcome, just need to correct expression for the No. column: