Multiple potential values for an IIF statement? - reporting-services

I am trying to write a report for student grades. One of the subjects has 3 teachers that swap classes a lot. I have a subreport in my report that pulls through target grades from a separate dataset. One of the parameters for the subreport is 'Teacher Initials'. As they swap students frequently, a lot of the time, the students have a new teacher to the one who set them their target grade and so it is not pulled through. Is there a way of having multiple values in an IIF statement for the parameter, such as:
IIF(Fields.SubjectName.Value = "Design & Technology"
, "ABC" OR "DEF" OR "GHI"
, Fields.TeacherInitials.Value
)
Is this possible or am I just doing some wishful thinking and need to find a way to integrate the targets into my initial SQL query?
Thanks,
Rob

I "think" you can do this using something like
IIF(Fields.SubjectName.Value = "Design & Technology"
, SPLIT("ABC,DEF,GHI", ",")
, Fields.TeacherInitials.Value
)
Your target parameter (the the sub/drilldown report) would need to be multivalue.
However, this approach seems unmaintainable as you would have to change the expressions if teachers changed.
A better way would be to not pass in the teacher at all (if that's possible) and/or have the teachers looked up in the subreport from a table or better still a view that list teachers and subjects.
If this does not help, post some sample data (as text) and the expected outcome and it will be easier to understand the problems you face.

Related

Is it possible to have a group by parameter in a SSRS Matrix report and have the columns rearranged depending on the group by chosen?

I haven't really worked with SSRS Matrix reports and I'm not sure if what I am trying to do is even possible.
The user can enter a begin and end year. They want the ability to group on either CBA, CRA or Client. The CBA and CRA choice would subtotal after each name, but the client would not. The columns to include would remain the same for each choice. However, they want whatever is grouped by to be moved to the front of the report. If you choose CBA, the columns relating to CBA should appear first. If you choose client, the columns relating to client should appear first.
Is any of this possible with a matrix report? If so, where do I start? Should any of this be done in the stored procedure or should it all be done in Visual Studio? I am using Visual Studio 2017. Below is a sample of what the output should look like.
Any help is greatly appreciated.
report sample
This is certainly possible. There are several ways to do this and you will have to choose how much of it is done in your dataset query/stored proc and how much is done via SSRS expressions.
There are a few things to think about no matter what route you decide on.
Your dataset query or stored proc must always return a dataset that has the same column names with the same datatypes and in the same order
Avoid hiding columns in the report designer as this does not work well
If the dataset returns lots of rows then you might want to do some of the work in the query
The SSRS Way:
If you wanted to do this entirely in the report designer, all the affected columns and groups would need to be set as expressions. For example, in a simplified version of your report, the second column expression would be something like.
=SWITCH(
Parameters!myParam.Value = "CBA", Fields!CBAName.Value,
Parameters!myParam.Value = "CRA", Fields!CRAName.Value,
Parameters!myParam.Value = "Client", Fields!ClientName.Value
)
The Columns header would also have to be a similar expression.
=SWITCH(
Parameters!myParam.Value = "CBA", "CBA Name",
Parameters!myParam.Value = "CRA", "CRA Name",
Parameters!myParam.Value = "Client", "Client Name"
)
The Row Group total (in grey on your example) would also have to be a similar expression.
You would have to repeat this for all affected columns.
Next
You would also need to change the RowGroups in a similar fashion. So you would add a row group and then the "Group On" and "Sort By" expressions to the same thing.
=SWITCH(
Parameters!myParam.Value = "CBA", Fields!CBAName.Value,
Parameters!myParam.Value = "CRA", Fields!CRAName.Value,
Parameters!myParam.Value = "Client", Fields!ClientName.Value
)
It's quite a long winded process but it's not actually that bad to do.
The SQL Method
The idea is basically the same, based on the parameter we pass in, we swap out the columns in the results but we alias them so they look the same in the SSRS dataset. We also have to provide the text for the column headers in the results so we don't have to work it out in the report designer.
Here's a very simple example.
SELECT
CASE #myParam
WHEN 'CBA' THEN CBAName
WHEN 'CRA' THEN CRAName
WHEN 'Client' THEN ClientName
END AS ColumnAValue
CASE #myParam
WHEN 'CBA' THEN 'CBA Name'
WHEN 'CRA' THEN 'CRA Name '
WHEN 'Client' THEN 'Client Name'
END AS ColumnACaption
, *
FROM myTable
Here we are swapping out the content of ColumnAValue and ColumnACaption. In the report designer, we would display ColumnAValue and set the Column Header expression to
=FIRST(Fields!ColumnAHeader.Value)
The Row Groups would both simply sort by ColumnAValue
This method means a lot less work in the report designer.
There are other options but these two methods I what I usually go for as they are the simplest. The SQL method is easier for other developers to understand because there is not much 'hidden' such at the row groups sorting and grouping properties.
At the end of the day it's down to you to decide what you feel comfortable with but hopefully this gives you enough to start.

Extracting words from a paragraph and then match with existing database by Ms Access

I am the beginner on the usage of MS Access.
I am going to build a program in the MS Access 2007 which can scanning some specific wordings listed in the data table from a paragraph.
For example, I want to know the occurrences of the transportation taken by the students.
(i) Therefore, I set the words "school" and "Bus" in my datatable [tableA] fields [trans].
(ii) Then, I input "I go to school by bus." in the [Input] boxes.
(iii) The result i want is that the sun of occurrences of both "school" and "Bus" can be showed in the another one textbox.
In the current situation, i just create a query [QueryA] from the [tableA] and directly use the count function in the query form. And then set the criteria as " Like [forms]![tableA]![Input] & "*" ".
However, it can just match the words in the [Input] with the final count result of the Query.
Ths a lot for providing any advice, including new direction.
I hope I understand what you're asking here, so I'll give it a stab with the information that you've provided. In your SQL window, try the following script: NOTE: You will need to change the WHERE clause to reflect your Input box(s)
SELECT Count(*) AS Expr1
FROM tableA
WHERE tableA.[trans] Like '%[Input]%;

Aggregate function in group header?

I have a really simple recordset by the name of qryUserFiles:
string: [UserID], [ftype]; Long: [fsize]
(records are file-information details of each file in each users' userfolder on the file-server)
I have created a report which lists the sum of [fsize] for each [UserID] by grouping on [UserID] and putting =Sum([fsize]) in a textbox in the header of the group. So far so good. So that shows me the total size of that user's user-share on the fileserver. (Helpful with respect to both convincing the users to clean up their stuff, and convincing the executives that we need to buy more storage!)
Now the headbanging part.
I want to add, in that same header, various textboxes containing the sum of the [fsize] for various values of [ftype]. So, for example, I'd want the sum of [fsize] for files where ftype="jpg" for each UserID. (And then another sum of [fsize] for files where ftype="mov" for each UserID, and so on for various 'problematic' file-types!)
I tried putting a
Dsum("fsize","qryUserFiles","ftype='jpg'")
in the group header, but, as expected, it is looking at the entirety of the 'qryUserFiles' recordset, and giving me the domain-total of size for jpg, not the this-user-total of size for jpg.
I considered trying to add something to the 'where' clause of the dsum function that would include 'this' user as criteria, but how would I refer to 'this' userID, with respect to the grouping-pointer?
Or is there a way easier way to do what I want without going nuts!? Would this be easier in another query? I feel like there's a simple, obvious answer just out of reach!
(I'm hoping to avoid brute-force VBA code to step through the table record by record, and calculate the stats with Dsum and add them to a new table. But if that's how to do this....)
I think - judging from what I read - you just need to let the report do its stuff. You can group on user and ftype - including the totals in the details and the totals in the Group Footer
You definitely should not use a DSum formula

SSRS: How to select two or more values from a long filtered multiple selection list with different search strings

Let's consider a multiple selection parameter on a report: Employee
This parameter has a lot of possible values. Initially nothing is shown on the list and there is a textfield search parameter associated, that updates the Employee selection list with top n matches for the searched string.
If the entered search query is John Doe we can imagine that now the selection list shows:
John Doe
...
Xavier John Doesson
Now I can select as many items as I want from this filtered list, but if I want to select both John Doe and Alicia Keys happens the following:
First when I enter the search string "John Doe" the selection list gets populated accordingly
I select John Doe - OK
I enter search string "Alicia Keys", the selection list gets populated also
Selection of John Doe is gone - I want to be able to select both Alicia and John at the same time, but I don't want to go through a thousands of names long selection list
Update:
Forgot to mention that we have an OLAP cube in the background with dimension 'Employee'. This dimension is used as the source of the parameter and the param dataset uses MDX to fetch the values, therefore the SQL solution cannot be applied here.
The current solution creates an custom set with MDX Filter and Head functions and then this set is used in the ROWS-part of the MDX query.
Here is how the set created:
SET setEmployees AS {
HEAD(
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch,1 >= 1 )
)
,100)
}
Basically the problem with this solution is that how do you add multiple search strings to the instr function
Is there a common solution to this kind of situation? Am I approaching the problem from wrong direction?
What you could do is make the search parameter more flexible, so you can handle input such as:
John OR Jane
If "OR" queries are more common than "AND" queries you could support it with queries such as:
John Jane
Note that this may throw people off, because the search features they're used to (such as Google search) typically tend interpret multiple words in the "AND" sense.
Anyhow, the tricky bit of course is the SQL behind the Employee data set. This should use the search parameter in a more flexible way. You haven't specified how that's currently working, but I imagine you may be using something like:
WHERE Employee.FullName LIKE '%' + #SearchParameter + '%'
You would need to extend that to support "OR" queries. There's a whole range of solutions for that, from quick 'n dirty handmade SQL (e.g. string split combined with WHERE...IN) to full-text querying. Choose a solution that's best for your situation.
If you have a fixed number of search terms than you can do something like the following.
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch1,1 >= 1) OR
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch2,1 >= 1)
)
Even if you can do that, I do not recommend it. You don't have the luxury to index Analysis Services like you do SQL. A better possible approach would be to query your data warehouse for the employees and return the appropriate keys, and then filter by those keys in your MDX statement.

How to simulate a Group Header in an Access Continuous Form?

I have a form (not a report) in Access displayed in Continuous View that has alot of repeat data. i.e. it looks like:
State Names
FL Abe
FL Bart
FL Charlie
GA Deleanor
GA Mary
This needs to be interactive (there's some command buttons on each row as well as in the form header), but there's alot of repetitive data. Is there a way to add a group header by state? i.e. make it look like:
State Names
FL
Abe
Bart
Charlie
GA
Deleanor
Mary
I found a number of problems with the solutions posted. Most obviously there are issues (as noted) if there are duplicate entries. But I found there was a deeper issue which is that you can't do this and still sort the data on yet another field (suppose you wanted to sort by the date by which each name was first registered in each state, and yet NOT rank them that way).
A better solution is found in the Using Code section of the Microsoft KB:
http://support.microsoft.com/kb/q101081
The code from that section retrieves the actual data from the Previous field, in whatever sort order you define.
Computationally this can be a bit intense, so it works only for small datasets, but I achieved good results by first testing the function:
=PrevRecVal([Forms]![myForm],"ID",[ID],"Names")=[Names])
then putting it inside the IIF function:
=IIf(PrevRecVal([Forms]![myForm],"ID",[ID],"Names")=[Names],"",[FullName])
Have you looked at subdatasheets? If you have a state table (or just query your existing data for the unique states), you could use that in a non-editable parent datasheet, and then the subdatasheet would display the people data, and you could make it editable.
I'd implement this with datasheet forms, not with the actual table or query datasheets. This gives you a lot more control over the subdatasheet linking and formatting, as well as making interacting with the datasheet events easier (it can be done with a table or query datasheet, but only through Screen.ActiveDatasheet.
The closest I can get is to add a field to your form's record source which numbers each row within a group. Then you could add a text box in the detail section of your form with this expression as its control source.
=IIf(rank = 1, [State], ""]
The text box would display the first occurrence of each state, and a zero length string otherwise.
I tested with this query for the record source.
SELECT
m1.state,
m1.names,
(
SELECT Count(names)
FROM MyTable AS m2
WHERE
m2.state=m1.state
AND m2.names<=m1.names
) AS rank
FROM MyTable AS m1
ORDER BY m1.state, m1.names;
And it worked, but is not editable. If you need to be able to edit, try a query which uses DCount to generate the rank.
SELECT
m1.state,
m1.names,
DCount("names", "MyTable",
"state ='" & state & "' AND " & "names <= '" & names & "'") AS rank
FROM MyTable AS m1
ORDER BY m1.state, m1.names;
Both those queries give this result set with your sample data:
state names rank
FL Abe 1
FL Bart 2
FL Charlie 3
GA Deleanor 1
GA Mary 2
Note, I assumed unique combinations of state and name.