Customize SSRS report on the fly - sql-server-2005

We have a requirement to represent the data on SSRS report in a simple manner.
i.e. the sql query for this report will look like this.
Select col1, col2,....col8 from Table where Date between date1 and date2.
So the user will run this report by selecting it from the web application with some parameters (eg: date1 and date2)
But the critical thing which i am facing here is that on the interface user has the option to select the order of the columns to position as shown in the image below.
In the image you will see the customized format has col1,col4,col8,col6,col5,col3,col7,col2.
Please help me how to create an RDL file to organize this kind of requirement. Thank you in advance in understand the correct requirement and producing the result as requested.

Set the expression for the columns to choose among the different fields depending on the selected parameter. For example, the expression for the value of the second cell might be similar to
=IIF(Parameters!MyColumnParameter.Value = "Choice1", Fields!Col2.Value, Fields!Col4.Value)
(Above code not tested, but hopefully close enough to give you the idea.)

Related

SQL ORDER BY behaving strangely in MS Access 2010 report

I have done my research on this in Stack Overflow and am aware of offered solutions whereby the advice is that MSAccess reports override queries and the sort order is usually set in the report properties, or by VBA OnLoad, or something similar. I have noticed something weird in my MS Access reports however, and that is that on one report I have created with the following query the report displays everything in perfect order:
SELECT Format([DateOfEnquiry],"yyyy") AS [Year], Count(T_Enquiry.DateOfEnquiry) AS
NumOfEnquiries, T_Enquiry.YearLevel
FROM T_Enquiry
GROUP BY Format([DateOfEnquiry],"yyyy"), T_Enquiry.YearLevel, IIf([YearLevel] Is
Null,0,Val([YearLevel]))
ORDER BY Format([DateOfEnquiry],"yyyy"), IIf([YearLevel] Is Null,0,Val([YearLevel]));
Here I'm particularly concerned with the ordering/sorting of the [YearLevel] field. [YearLevel] is a text lookup field because it not only contains the integers 1-12 but also has the letters 'K' and 'P' in the lookup field. When running the above query it returns the correct order - that is from 'K' then 'P', then from 1-12. I've used this query as the record source for my report and the report lists all items just as the datasheet does when running the query itself. Perfect!
Now take a look at the following query that I use as a record source for another report:
SELECT Format([DateOfEnquiry],"yyyy") AS [Year], Count(T_Enquiry.Outcome) AS
NumOfEnrolments, T_Enquiry.YearLevel
FROM T_Enquiry
WHERE (((T_Enquiry.Outcome)="Enrolled"))
GROUP BY Format([DateOfEnquiry],"yyyy"), T_Enquiry.YearLevel, IIf([YearLevel] Is
Null,0,Val([YearLevel]))
ORDER BY Format([DateOfEnquiry],"yyyy"), IIf([YearLevel] Is Null,0,Val([YearLevel]));
When this query is run, the datasheet is in perfect [YearLevel] order. However the report view is not. The report view puts [YearLevel] 10 first, then 12, then 2. The only difference (apart from the respective fields) between both SQL queries is the WHERE statement in the second query above. Should this make a difference in report view? I don't see how.
Can anybody please suggest a work around? Or point out what I might be missing in the report properties, VBA code, SQL queries...or maybe there might even be a macro that can sort [YearLevel] more easily in the proper order? I look forward to any advice.
Cheers.
New Information
I have done some more testing and determined that in my report design view I have a text box called Txt_TotalEnrol in the report footer which contains the following calculation:
=Sum([NumOfEnrolments])
This is in addition to some other totals. It seems it is this textbox that causes the order of [YearLevel] to be out. I deleted Txt_TotalEnrol and the ordering of [YearLevel] went back to my desired order.
Why does this operation effect the order of [YearLevel] on the report? Any suggestions very much appreciated.
As #parakmiakos said, check first that there is no other constraint in the OrderBy property of the report that may be overriding your bound query.
If your report is shown in a form, also check that the form doesn't have its own RowSource and OrderBy properties set to something that would explain the behaviour.
I would also not use Year as a field name since it's a reserved word and it may cause strange issues that can be hard to debug.
You could also try to wrap your query into another query (I've made small changes):
SELECT P.TheYear,
P.NumOfEnquiries,
P.YearLevel
FROM (SELECT Format([DateOfEnquiry], "yyyy") AS TheYear,
COUNT(T_Enquiry.DateOfEnquiry) AS NumOfEnquiries,
T_Enquiry.YearLevel,
Val(Nz(YearLevel)) AS YearLevelAsNumber
FROM T_Enquiry
GROUP BY Format([DateOfEnquiry], "yyyy"),
T_Enquiry.YearLevel,
IIf([YearLevel] IS NULL, 0, Val([YearLevel]))) AS P
ORDER BY P.TheYear,
YearLevelAsNumber
EDIT: I had forgotten that reports have a really un-intuitive way of settings sortting and grouping rules.
In Design mode, you need to right-click on an empty part of the report an select Sorting and Grouping:
Then a panel will appear that should let you setup your sorting rules:
Problem solved!
I created a simple query to list all the "Enrolled" [Outcomes]:
SELECT Outcomes
FROM T_Enquiry
WHERE T_Enquiry.Outcomes="Enrolled";
and then inserted the following into the Data Property of the Txt_TotalEnrol textbox in the report:
=DCount("Outcome","qry_TotalOutcomeEnrolled")
This had the desired effect of providing a total number and not re-ordering [YearLevel].
I was using ORDER BY over fields with text and the results were not as expected, so I had tried a GROUP BY but it ended up truncating my text fields at 255 characters. What ended up working for me was still using ORDER BY but for the text fields, using a LEFT statement.
So, instead of:
SELECT text1, text2, text3
FROM table1
ORDER BY text1, text2, text3
I instead put:
SELECT LEFT(text1,50000),LEFT(text2,50000),LEFT(text3,50000)
FROM table1
ORDER BY LEFT(text1,50000),LEFT(text2,50000),LEFT(text3,50000)
It's ridiculous, but it worked for this instance.

Display row with condition in Pentaho Report Designer

Assume I have one data set with following fields:
Name, Amount, Time, etc
How can I display only those records with Amount > 100, for example?
Since I need this data set for other report, I can't filter these records when I prepare data set.
I searched around, but couldn't find any answer. I will really appreciate if anyone can help.
By the way, I used Pentaho Report Designer 3.9.
Thanks a lot.
Yes, you can.
You have to find your Details Band - not Details Body -, within your Report Structure, and set up the Style Attribute visible the expression:
=if([Amount]>100;true();false())
Besides, if you want your summaries to consider only the shown data, you can also add an Open Formula function field, that would say:
=if([Amount]>100;[Amount];0)
And you'd summarize it at the end of the report.
Here's the link with the full example built to your situation.

VB.NET Active Reports

I have a VB active report which has many different attributes. The report contains attributes area, balance, id and status and is currently grouped my area. What I need to do now is remove all lines from the report where the balance is equal to 0 and the status equal to deactive. The information for the active report is from my database. Thus I think the best way would be to only select records where the balance is not 0 and status not equal to deactive. Is there a way I can query my database and have the active report be based off the query results? Is there an easy way to do this? Thanks for any help.
Yes, the best way to do this is to change the query so that only the minimum records you need are actually coming into the report. The Modify Data Sources at Run Time topic from the documentation shows how to modify that SQL statement in the code dynamically at runtime.
If you can hard-code the SQL query for the report you should probably just modify the SQL at design time inside the designer. This Bind Reports to a Data Source topic shows you how to do that.
You can also programatically control the visibility of fields/textboxes based on the data using the Format event of the section containing those controls (most likely Detail_Format), but it sounds to me like modifying the SQL query is your best bet.

Dynamic SSRS report

I had a problem in creating the Dynamic report in SSRS. My problem is:
In a table I have stored SQL scripts with the column SQLScripts. If you execute these SQL scripts you get different number of columns for each script.
My problem is, I have one report with buttons of these scripts, for example test1, test2...like that. If you press test1 button this should take the test one SQL script and should display the report with appropiate columns in that sqlscripts.
I can't create individual reports for each test report, they are plenty. Are there any options for me to solve this problem...
The only way I've been able to get this to work sofar is:
Each report has 2 datasets.
ReportData
DataHeaders
The "DataHeaders" need to have the proper name of the datafields in "ReportData". Be careful since SSRS replaces blanks and special characters with "_"
Now, create a table (or matrix) and drag the DataHeaders as the Columns of your report. (This should be a grouped column). If you run it at this point, you'll see all your columns without any data. Now comes the magic:
Create another report that takes a "DataField" parameter. Create another table or matrix within this report and set it's dataset property to be "ReportData". In the DATA cell for the table, set it to the expression =Fields(Parameters!DataField.Value).Value
Now go back to your first report. Right click and insert a subreport. Right click on the subreport and select "Subreport Properties". Under general, select the second report you created to be used as the subreport. Under parameters, select the DataField parameter and set its value to something like =Fields!DataField.Value
In my case I did some formatting in this expression to fix the above mentioned issue with spaces and special characters, since my stored procedure was initially used in ASP.NET and this was just a proof of concept.
Also in my experience the performance isn't great. In fact it was kinda slow, though I haven't had a chance to switch it to use a shared dataset, which I suspect would help a bit. Please let me know if you find a better solution.
I have not found a way to do this completely dynamically. Here is a similar question with some possible solutions:
How do i represent an unknown number of columns in SSRS?
You basically need to create a 'master dataset' from the other Datasets that are based on your multitude of SQL scripts first.The master dataset should contain the data to be presented in it's most simplistic form, i.e. in a simple list format.
Finally, go to the toolbar in SSRS and drag a 'Matrix' into the report. A Matrix table acts similar to a pivot table in Excel or a CrossTab query in Access that will display whatever's in the Dataset.

SSRS Report , Dynamic selection of fields

I want to create a report where my report's fields should change according to my input parameter values.
For example, if I select 2 months, there should be 2 fields in result, having month wise calculation. If I select 3 weeks, there should be 3 fields each for each weeks calculation instead of the 2 months field.
How do I achieve this?
I'm still a beginner at SSRS, but I've heard of a few ways to handle this:
To a certain extent, you're really talking about separate queries, depending on the parameters. So, use a dynamic query (build the query up as a string expression). The simplest way I saw was to use IIF in the expression to choose one or the other stored procedure based on the parameter values.
To the extent that it's pretty much the same query, but you want different columns visible, then you can tie the visibility of the columns to an expression based on the parameter values.
If too much of the structure of the report differs based on the parameters, then you can use multiple reports. Have one front-end report that calls on one of the other reports based on the parameter values, passing the parameter values to the other report.
I hope that helps. If you've already figured out a solution, then please tell me!