If I have data set as under
I can use
=Lookup("Gap", Fields!Name.Value, Fields!value.Value, "DataSet1")
to obtain the Gap value : 761
now I have the below data set
and I want to obtain the "GAP" value for X-Bucket.
How will the LOOKUP function be?
You got to use Multiple condition inside your lookup function.
=Lookup(Fields!Name.Value & "1-30-Bucket",Fields!Name.Value & Fields!Bucket.Value ,Fields!value.Value,"DataSet4")
Note: for my Testing I used 1-30-Bucket rather than X-Bucket so that I do not return 1st value, you can updated the expression as required.
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.
So I have a multiple value parameter than contains 3 options. >250K, <250K, >2M.
I also have a table that consists of multiple columns.
. Because the parameter is a multivalue, i am having difficulties filtering the dataset.
I need to filter the dataset by checking, (if > 250K is selected, filter the dataset accordingly), (if < 250K is selected, filter the dataset accordingly) and (if > 2M is selected, filter the dataset accordingly).
I was told to use a join and split on the parameter within the (>250K condition, then do a contains to see if it contains any of the parameter values) but I am not as advanced in my knowledge of coding to be able to do that.
Any Suggestion? Thanks in Advance
I previously tried the method below but then i came to realise that it wont work because the parameter is a multi value.
I know its been a while since you raised this, you were on the right track but all you should need to do is add a filter to the Tablix on the field you will be filtering, use the 'in' operator and in the Value type [#Yourparametername] the square brackets and case sensitivity are important. Also ensure the expression type is correct, in your case it looks like you are using Integer. The image should help.
If you want to use multi-parameters, In the dataset, you can read parameter value using JOIN.
Example:
If you want to read multiple values for #MyParamter in a dataset given in the following example:
Dataset Parameters
you need to use =JOIN(Parameters!myMultiParamter.Value,",") as an expression to read all selected values in CSV form.
Expression
Now the #ParameterValues param has all selected values as comma separated values and you can use them in your dataset code as per design requirements.
Note: It's not necessary to use a comma but u can use anything you want to separate values.
Your sql query where should look like
Where
(
(0 IN (#Parameter) AND ValueColumn<250000)
OR
(1 IN (#Parameter) AND ValueColumn>=250000)
OR
(2 IN (#Parameter) AND ValueColumn>=2000000)
)
One parameter
Two parameters
All parameters
Once you return the value you can also use charindex or patindex* and look for where the value in your where clause is a pattern where the index number is > 0 . For instance if the returned string from SSRS is '01,02,03' and then your where clause has something like this right(field, 2) which would result in value '03'. you change your where clause to be where patindex('%' + right(field, 2) + '%', #returnedstring) > 0 which will give you results. The keeps you from having to parse apart the #returnedstring parameter in your sql code.
I have the following query output from SQL:
Query and Report Formats
I have managed to restrain my data for the first columns but I don't know how to show the values as in the example in the last column named "Return"
The logic behind the completion of the "Return" column is the following:
After I group the data by the unique combination Section_ID x Route_ID:
If I have a return on the Section_ID the value of the "Return" column should be "Yes", else if there are not return it should be "No".
How can I achieve the report output as in the picture?
Thanks.
You can use a LookupSet() and Join() functions to get all returns by Section and Route combination in a string. Once you have all returns you can use the InStr() function to check if there is at least one return and return Yes in that case, otherwise return No.
So I've used the following expression:
=IIF(
InStr(Join(LookupSet(Fields!SectionID.Value & "-" & Fields!RouteID.Value,
Fields!SectionID.Value & "-" & Fields!RouteID.Value,
Fields!Return.Value,"DataSet25"),","),"Yes")>0,"Yes","No"
)
Based on the data returned by your query I've recreated your example, this is the result.
Note there are two rows for Section 4 and Route 26 combination, the expression returns Yes because one of the rows has a return.
Let me know if this helps.
How do I pass two dynamic values returned from one dataset as parameters to another dataset to return one row of a second dataset in a cell?
For each cell in a header row I need to determine A) Which column to get based off the meal period, and then B) take that value and pass it and another parameter to a query to get one of the columns (I'll take first) from the query.
I am already using cascading parameters, but I'm not sure if or how to use them in this scenario.
Example:
#SalesReceipt
#MealPeriod (A cascaded parameter. There should be one meal period per receipt)
Expression in an example cell:
=IIF(Parameters!#MealPeriod.value = "Lunch", Fields!Burger_Lunch_Type.value, Fields!Burger_Dinner_Type.value)
That returns either the lunch or dinner Type from a fact table, depending on meal period.
Given the Type and Item ID I need to get a value from another query or dataset and add that text to the cell expression. So the expression would look something like:
=IIF(Parameters!#MealPeriod.value = "Lunch", Fields!Burger_Lunch_Type.value, Fields!Burger_Dinner_Type.value) & " and " & (select top row from dataset given the correct type field and Item ID)
The cell should look like: Table1.Type and Table2.Breadtype AKA Bacon Burger and Whole Wheat.
Does that make sense?
I would use the dreaded Lookup function for this:
http://technet.microsoft.com/en-us/library/ee210531.aspx
I say dreaded because it is notoriously tricky to code and debug. I've even seen a case where a failed Lookup caused the entire row to disappear!
The Lookup target dataset itself should not use the parameters required for the Lookup - it's purpose is to return all the possible rows needed by the Lookup function.
If you need to use two columns as the key to your lookup, you can concatenate them e.g.
Fields!Burger_Lunch_Type.value & "|" & Fields!ItemID.value
Good luck!
I want to use columns in a function and the columns may differ from time to time. So I want to pass the columns into the function when calling the function, what datatype can be used in the function.
The following is the code that i want to put into the function and compute_page is the column name:
if dw_report.Object.compute_page[ll_first_row] <> dw_report.Object.compute_page[ll_last_row] then
Also, I want to do the same thing but this time is set the column value. I tried to use SetItem(), SetText(), SetValue(), but none of the function can achieve the expected result except using dwcontrol.Object.columnname[i] to set the value.
Thanks
Instead of using the .object notation to access the column, use the GetItemxxx(), eg:
if dw_report.getitemnumber(ll_first_row, "compute_page") <> dw_report.getitemnumber(ll_last_row, "compute_page") then
Just replace the "compute_page" litteral in the example by a string argument of your function.
Beware that the GetItemxx() call must match the actual column data type, so you need to check for the result of dw_report.describe(ls_your_column_name+".coltype") to call one of GetItemNumber(), GetItemString(), GetItemDecimal(), GetItemDate(), GetItemDatetime() or your application will crash.