I need an SSRS Lookup query to get results from Dataset 2 Column1 and if not found in Column1 lookup Column2.
Dataset1 - WONUMBER
Dataset2 - WONUMBER, Column1, Column2
You can just use an IIF() in your return argument of the LOOKUP function like this
=LOOKUP(Fields!WONUMBER.Value,
Fields!WONUMBER.Value,
IIF(Fields!Column1.Value=Nothing,Fields!Column2.Value,Fields!Column1.Value),
"DataSet2"
)
Related
I want to write a SSRS expression that will allow me to grab the value from Column B base on the max value from ColumnA.
For Example, I have the following values
ColumnA
ColumnB
1
Test
2
Tester
3
Testing
=FIRST(
iif(
Fields!ColumnA.Value= MAX(Fields!ColumnA.Value,"test"),
Fields!ColumnB.Value,0
),"test"
)
The reason I am doing this is because I am trying to combine to datasets in one table. Certain fields in the table just needs to select top N values from another dataset.
I think that easiest way is to add something like row_number into your sql query (row_number() over (order by ColumnA desc) rn and then you can have condition iif(fields!rn.value = 1, fields!ColumnB.value,0)
I have a dataset which brings in distinct values of a column 'A' of table 'B' and these form the select values for a parameter 'Param_A'. In addition to this I have a main dataset which brings in data from table 'B' and contains the column 'A' as 'Field_A'.I do not want to alter the main dataset and hence I am using a tablix filter to filter out the result set of the main dataset. The tablix filter is supposed to be performing the below functionality :
Expression:
Fields!Field_A.value in (Parameter!Param_A.value) or Fields!Field_A.value is NUll
Boolean Operator :
"="
Value:
True
But I am unable to use the operator 'in'. It gives me an error.Could you please help me out with this?
I used the 'inStr' Operator which eliminated the possibility of using 'in' operator:
iif(InStr(Join(Parameters!Project.Value,","),Fields!project_name.value)>0,
true,false)
This helped me!
I Have a very simple question regarding SSRS, I also tryied many ways but not getting correct value
:
Example:Say i have report and i have to add first three column into last column as
column1 Column2 Column3 Total
2 4 6 12
1 2 3 6
I tried to add this logic in my expression code as :
=Sum(Fields!Column1.Value, "DataSet1")+Sum(Fields!Column2.Value, "DataSet1")+Sum (Fields!Column3.Value, "DataSet1")
But this is not working and returning #ERROR in last column , can you please suggest the correct way to add the column values into one column.
Try Removing SUM() function because this is an aggregate function
Fields!Column1.Value + Fields!Column2.Value + Fields!Column3.Value
or just change your sql query to something like
select Column1, Column2, Column3, Column1 + Column2 + Column3 Total
from [your Table]
[where id = ???]
Can you use the combination of the textboxes instead of the sum of the fields?
ReportItems!textbox1.value+ReportItems!textbox2.value+ReportItems!textbox3.value
Using SSRS 2012 with SQL Server 2012. I have a result set in SQL Server 2012 which has the following fields as headers:
sumDeposits,
sumWithdrawals,
sumFees,
etc
This has been mapped to a Dataset in SSRS.
I would like a SSRS table or matrix where I can have the column header as column one and the data row (there is only one row in the result set) as column two in a table. Is this possible? Been struggling with it.
I should add that the way I am doing it now is to drag a Field from the Dataset onto the SSRS page, and then put a text box next to it. The number of fields is growing so I'd rather have a table.
It sounds like you want to unpivot the data from columns into rows. If that is the case, then you should be able to use the UNPIVOT function in SQL.
The basic structure of the query will be:
select col, value
from yourtable
unpivot
(
value
for col in (sumDeposits, sumWithdrawals, sumFees) -- your columns here
)unpiv;
If you have data that is not the same datatype, then you will have to convert the data for all columns to be the same type:
select col, value
from
(
select sumDeposits,
cast(sumWithdrawals as numeric(10, 2)) sumWithdrawals,
sumFees
from yourtable
) d
unpivot
(
value
for col in (sumDeposits, sumWithdrawals, sumFees)
) unpiv;
This type of query is exactly the same as using a UNION ALL with multiple calls to the same table:
select 'sumDeposits' col, sumDeposits as value
from yourtable
union all
select 'sumWithdrawals' col, sumWithdrawals as value
from yourtable
union all
select 'sumFees' col, sumFees as value
from yourtable
I want to pass variable number parameters to sql query. As an example:
select column1
from Table
where column2 in ( '0080','0010')
group by column1
having count(distinct column2) >= 2
In the where clause, 2 arguments 0080 and 0010 are used. But this number of arguments can vary based on the input from user. As an example it could be like this:
select column1
from Table
where column2 in ( '0080','0010', '0020', '0050', '0060')
group by column1
having count(distinct column2) >= 5
So, this number of arguments is not fixed and it will be passed by the user from an .xml file.
How can we pass a variable number of arguments to the query? As the number of arguments is not fixed and it can be changed from time to time, can we use an array or something similar?
I would suggest you try to load the arguments into a temporary table and use that in the where clause in a subquery. In particular if your argument list becomes very large, this is much more scalable.