Hello please can anyone assist
I have 2 datasets, one of them is filtered to bring back a set of numbers.
I have another dataset using the same data source which is filtered to bring back a different set of numbers.
I want to look up from one dataset to the other to have both sets of figures in the same matrix.
The Matrix is setup to have a name in a row, and month date in the colum.
I want to therefore look up the name from the 2nd dataset as well as the month number and return the value into the above.
Is there anyway to lookup against 2 conditions and return the value ?
Thanks !
Yes - you can combine the fields into one using a separator between the fields.
=Lookup(Fields!MonthNum.Value & "|" & Fields!aName.Value,
Fields!MonthNum.Value & "|" & Fields!aName.Value,
Fields!Number.Value, "Product")
The separator is used to keep values from the first field affecting values from the second.
Update:
For your issue when there is no month, you can try excluding them:
=IIF(ISNOTHING(Fields!MonthNum.Value), NOTHING,
Lookup(Fields!MonthNum.Value & "|" & Fields!aName.Value,
Fields!MonthNum.Value & "|" & Fields!aName.Value,
Fields!Number.Value, "Product") )
If MonthNum is NULL, it will return NULL (Nothing in SSRS).
Related
I am in report builder and I have my primary dataset that is from a SQL database, I also then created a second dataset (enter data). I need to compare 2 fields from each dataset to retrieve the correct value from the 2nd dataset and populate a column on my report. I have tried the IIF statements and Lookup statements but I keep getting the error "report item expressions can only refer to fields within the current dataset".
I have a attached a screenshot of what I am trying to do....
The IIF statement I tried to use.. If Acctnum and prodid = each other return IncodeNumber
=IIF((Fields!AcctNum.Value=Fields!AcctNum.Value, "IncodeAccount") AND
(Fields!ProdId.Value =Fields!ProdId.Value, "IncodeAccount")),(Fields!IncodeNumber.Value, "IncodeAccount"),"True")
See code in my problem.
You need to use LOOKUP(). The problem with LOOKUP() is that is can only compare a single value from each dataset. However, we can easily get around this issue by concatenating the two values you need to compare.
Note: This assumes the expression will be in a tablix that is bound to your first dataset and that IncodeAccount is your second dataset - the values you want to lookup. If this is not the case just adjust the expression accordingly
So for you, you probably need to do something like this..
=LOOKUP(
Fields!AcctNum.Value & "||" & Fields!ProdId.Value,
Fields!AcctNum.Value & "||" & Fields!ProdId.Value,
Fields!IncodeNumber.Value,
"IncodeAccount"
)
I've used two pipe symbols to join the values to avoid incorrect matches being found. e.g. Account 123 and product ID 4567 would incorrectly match to Account 1234 and product ID 567 as they would both be 1234567 when joined. By using the || the match would be 123||4567 and 1234||567 respectively.
You may need to convert the values to string using CStr()
Alternative approach
If you are going to do this 'join' multiple times in the same dataset then you could add a calculated column to the dataset that concatenates the two columns. Then you can use this single field in the lookup which will make things a little simpler.
Or, you could do this concatenation in a database view which would make things even easier.
new to SSRS report design. Although, I've used CASE statement before but not sure how to utilize in a condition where SSRS report needs to two parameters ( parameter symbol (>,<,=,%) and parameter date ) pull data from a dataset.
I'm wondering if CASE statement can be used to achieve this need?
Or any other suggestion that would work for this condition, will be greatly appreciated.
PS: I've not come across such example so far
I'm assuming that you want to parameterise the actual operator so the user can for example, choose < 1000 or > 50 etc...
If that's correct then you can do this as follows.
Assume we have two parameters
pOperator which has values of ">", "<" and "=" (note for the = option you will need to specify this as an expression ="=" or SSRS will think you have a blank expression.
pMyValue which will allow the users to type a number in
What you need to do is change the dataset query to be an expression, so something like this.
="SELECT Employee, Salary FROM myTable
WHERE Salary " & Parameters!pOperator.Value & " " & Parameters!pMyValue.Value
If you had used > and 30000 as your parameter values then this would return
SELECT Employee, Salary FROM myTable
WHERE Salary > 1000
You could also have a single parameter where the user can type the whole ">=15000" and then just replace the two parameters above with a single one.
Hi Team,
I have a SSRS report like this, the users would like to see the data like the picture below. For Column 2 if the value is N/A the values of column 3 would be in list and separated by comma. and the multiple lines will be converted to only one line where N/A is there.
First you will want to create row groups for two of your columns. I have assumed they're called Shipment and Description. Then you can use Join and LookupSet to do the CSV aggregation. Similar to the answer here.
Something like this:
=Join(LookupSet(Fields!Shipment.Value & "-" & Fields!Description.Value,
Fields!Shipment.Value & "-" & Fields!Description.Value,
Fields!PartNumber.Value, "YourDataset"), ",")
I want to build a SSRS report that has column as week numbers - 8 weeks for 8 columns starting with current. This report is run every week and current week number is set then. So both column names and their values should change .Is it possible to build something like this in SSRS?
I tried doing this with a dynamic SQL based stored proc in dataset. However for every run I don't even see the columns values updating dynamically
Here's an example :
Also I am trying to avoid these week numbers as row values and then using matrices
My stored proc looks something like this
declare #n tinyint = datepart(wk, getdate())
declare #n1 tinyint = (#n+1), #n2 tinyint =(#n+2), #n3 tinyint =(#n+3), #n4 tinyint =(#n+4), #n5 tinyint =(#n+5), #n6 tinyint =(#n+6)
exec ('Select b.sku, b.['+#n+'], b.['+#n1+'], b.['+#n2+'], b.['+#n3+'], b.['+#n4+'], b.['+#n5+']...
Will appreciate any help in this direction.. many thanks!
When working with SSRS it's generally best to avoid dynamic SQL and pivoting the data in the SQL. Use the SQL to get the raw data you need and then let SSRS do the pivoting and aggregation. This way you take advantage of what they each do best. I know you said you want to avoid matrices, but it is the best way to make the report dynamic.
So you should either return all the data in one dataset and use filters on your matrices OR write two queries and have each one populate a matrix. BTW a matrix is just a table with a column group added, so don't be intimidated by them.
There are 2 ways to do this with a standard tablix.
Calculate the column headers as expressions using concatenation of Wk and some date math to find the correct week number and return the same sort of thing from your query (e.g. columns are current_week, week_minus_1, week_minus_2...)
Return the column headers as additional columns in your query that are the same value for every row (e.g. ColHeader0, ColHeader1...). Your data columns would still be relative weeks (e.g. ValueWeek0, ValueWeek1...). In your report the column header would have an expression like =First(Fields!ColHeader0.Value). This is a more flexible approach since it lets you pick 8 historical weeks instead of only the last 8 weeks if you add a parameter.
EDIT - Clarifications
The reason that you get the blank column Wk48 is approximately that you have created your report looking for that column that won't be there the next time. SSRS looks for exact columns. You should you use relative column names for either of the options I have specified:
exec ('Select b.sku, b.['+#n+'] as Wk0, b.['+#n1+'] as Wk1, b.['+#n2+'] as Wk2, b.['+#n3+'] as Wk3, b.['+#n4+'] as Wk4, b.['+#n5+'] as Wk5...
This will allow you to populate the aliased Wk0 column with the appropriate current week data and still make sure that it can be consistently referenced as the base week by SSRS.
To change the column headers you can:
Independently calculate the week numbers in SSRS in the column header expressions: ="Wk" + CStr(<correct week calculation>).
Return the column headers in the result set and access them in the column header expression:
exec ('Select b.sku, b.['+#n+'] as Wk0, b.['+#n1+'] as Wk1, b.['+#n2+'] as Wk2, b.['+#n3+'] as Wk3, b.['+#n4+'] as Wk4, b.['+#n5+'] as Wk5..., ''Wk'''+#n+' as ColHeader0, ''Wk'''+#n1+' as ColHeader1...
and reference the returned column headers from the SSRS column header expression as =First(Fields!ColHeader0.Value).
Here's a solution that worked for me:
Create parameters (say CurrWk, CurrWk1) ,set as hidden and store 'Default value' and 'Available value' equals to current week number (datepart(wk, now()) and any subsequent week by doing a +1, +2, +3.. etc.
Write a query expression . Click onto fx beside dataset query space and write the select query for your program embedding parameter values in the expression window. For eg ="Select SKU, [" & Parameter!CurrWk.Value & "] as Wk1,
[" & Parameter!CurrWk.Value & "] as Wk1 from Sales_Table"
Before passing this query as a 'command text expression' please ensure this query is working in sql ssms.
Save the expression. Now find 'Fields' tab on the left hand side panel.You need to map the fields manually from the query here. If this is not done, there is a very high chance you seean empty field list and wont be able to access them at all. This may be because ssrs do not store query metadata directly from expressions.
You can avoid part of the issue by having atleast the static fields , for example here SKU listed in the 'Fields' list by first running a sql query with static field(select SKU from Sales_Table ). You can then go back to update dataset- change query to expression and embed the parameterized field names.
Map field names. In this example I chose 'Query Type' fields and set Field names as SKU, CurrentWeek, NextWeek and mapped to source SKU, Wk and Wk1 respectively.
Click on 'Refresh Fields' at the bottom. Now you have a dataset with the complete field list. Use these in charts, tables . Run it every week and note the numbers changing as expected.
In case you are using this dataset in a table, make sure you set headers with Labels of Parameters (for eg here I did =Parameters!CurrWk.Label for col with current week data)
That's it!
It is basically the same question I had in this thread:
Adding values to a Report when there is no Data in query SSRS
The only difference now is that I want to extend the same functionality to different Datasets.
Imagine this:
I have two Datasets. Dataset1, Dataset2.
Both have the same primary key, in this case:
Sales Rep
Category
Now in Dataset1 I have the following Data:
The idea in that thread was to put "0" Each time a Sales Representative Did not have all the categories, if you see for example Sales Rep on DataSet1, does not have G1,G2 Category so In those cases they have to put 0.
Thanks by the answer of the community this can be achieved by adding a Calculated Field on DataSet1:
=Fields!SalesRep.Value & "-" & Fields!Category.Value
So that will give you for example 11-G1 for the 1st Row. and the expression for each Row (For each category) will be:
=iif(IsNothing(lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7")),0,
lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7"))
As you can see, the ReportItems!Textbox62.Value saves the value of the Category so If 11-G1 is nothing (dont exist) put "0".
The idea here is to do the same thing with DataSet2.
The tricky part is that we have to ask if 11-G1 equals 14-G1 because in DataSet2 the SalesRep does not exist for all the categories it must put "0". Both are grouped as SalesRep.