SSRS: Filter 1 field based on 2 possible values in another field - reporting-services

I don't if I'm being a knucklehead, but I've searched considerably and tried several options: can't make it happen. Here is the issue.
I have the following Data Query:
First of all, sorry it's French. Secondly, as you see, the fields are "File number", the "Year" and the "Number of distinct patients".
Wanted result: I want to filter for Case numbers who appear both at 2015 and 2016.
As you see, certain patients showed up several years in a row. However, I want to find out how many showed up in 2015 AND 2016 only (not 2014, etc.) (so a total of 2 visits for the 2 years combined). So solely filtering in my Data Query on 2015 and 2016, doesn't do the job, since it fails to exclude the patients that only showed up once. Furthermore, filtering on 2015 and 2016, and then Count(Fields!File_number.Value)=2 wouldn't work since it fails to exclude the patients that might have been here in 2014.
I have tried several Boolean expressions, but as soon as I include 2 years in my filter, it blanks my tablix out. (Understandibly cause I tell it that Fields!Year.Value must be equal to 2015 and 2016 simultaneously).
So I tried bypassing it by telling it that and did the following:
Expression:
=IIF(Lookup(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset")=2015 AND Lookup(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset")=2016, True, False)
It works for 1 year only: as soon as I add 2015 either by and "AND" or by adding an additionnal filter, mytable goes blank.
Any suggestions? Thanks!

Yeah, this isn't an easy thing to solve, you aren't being a knucklehead :) You are correct about the double boolean expressions in the query and the two combined lookups won't work either. In the case of a lookup, LOOKUP returns the first match in a dataset, so every time, both of those looksups are going to return the first value.
There is another function called LookupSet which does return ALL matches from a query though. It should be possible to create an ugly expression around this function to test specifically whether the string 2015 and 2016 both appear in the results with something like:
=Join(LookupSet(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset"),",")
and then substring searching for both "2015" and "2016" (I'll let you fiddle with that part)

Related

SSRS - I want to filter on data used in an Average

Sorry - I'm quite new to SSRS and floundering about.
I want to average some values over 3 years worth of data but I don't want to include 2020 in my average.
so currently the Value is [Avg(L3VAValueAdded)] - which works for all years - but includes 2020 but I need to be something like [Avg(L3VAValueAdded) where year <> 2020] or something like that?
If you look at the actual expression that you currently have it will probably look something like this...
=AVG(Fields!L3VAValueAdded.Value)
An interesting feature of the AVG() function is that it does not include NULL values so we can use this to our advantage.
Change your expression to
=AVG(IIF(Fields!myYearField.Value) = 2020, Nothing, Fields!L3VAValueAdded.Value))
Obviously swap out the myYearField name for the correct field containing your year. This assume the "year" field is numeric, if it is a string then put 2020 in quotes.

Access 2013 Count

I am working on a report in Access 2013 I need to seperate the first 20 records in a column that contain a value and assign a name to them. Such as at 1-20 I need it to insert Lot 1 at 21-40 need to assign Lot 2 etc... The report needs to be separated by lots of 20. I can also just insert a line when it reaches sets of 20 without a name if that makes it easier. Just need something to show a break at sets of 20.
Example: As you can see the report is separated by welder stencil. When the count in the VT column reaches 20 I need to enter a line or some type of divider to separate data. What our client is asking for is we separate the VT in sets of 20. I don't know whats the easiest way to accomplish this. I have researched it but haven't found anything.
Example Report with Divisions
Update the report's RecordSource query by adding "Lot" values for each row. There are multiple ways of doing this, but the easiest will be if your records already have a sequential, continuous numerical key. If they do not have such a key, you can research generating such sequential numbers for your query, but it is beyond the scope of this question and no details about the actual data schema were supplied in the question.
Let's imagine that you have such a key column [Seq]. You use the modulo (mod) and/or integer division operators (\ - backslash) to determine values that are exactly divisible by 20, e.g. ([Seq] - 1) mod 20 == 0.
Generate a lot value for each row. An example SQL snippet: SELECT ("Lot " & (([Seq] - 1) \ 20)) As LotNumber ...
Utilize Access report sorting and grouping features --grouping on the new Lot field-- to print a line and/or label at the start of each group. You can also have the report start a new page at the beginning or end of such a group.
The details about grouping can be found elsewhere in tutorials and Access documentation and are beyond the scope of this question.

Searching ALL ROWS in a Group using IIF Expression

I am working on a report that displays patient names (as groups with drilldowns) and several fields related to their visits. I have created a column in the report to display whether or not a specific value appears in the 'LocationID' column. The expression I used is
=IIF(Fields!LocationID.Value="WELL","Y","N")
I thought this was working great, it displays Y or N next to each name to let me know if 'WELL' was in their 'LocationID'. I checked several to ensure that this was going to work and discovered that there was a LocationID code of 'WHS' and since I have the rows ordered by Name and LocationID if there was a WHS visit it shows up at the top of the group and my expression is only seeing this top item. How can this expression be written differently so that it searches the entire result of each group? Depending on the date range a patient may have one visit or they may have ten. I need to check all visits that are returned. Perhaps there is a better method. Thanks in advance.
I agree with jimmy8ball that the easiest way to solve most issues like this is to push some logic back into the SQL layer.
However, if you really want to do this via SSRS functionality, then you could implement a substring search against a lookupset. Assuming you have a patient id in your dataset that is unique for each patient (I hope your group isn't on the name) then...
=Iif(InStr(Join(Lookupset(Fields!patientid.Value, Fields!patientid.Value, Fields!LocationsID.Value, "dataset"), ","), "WELL") > 0, "Y", "N")
Which says, "Search through the dataset for all rows related to my patientid, join every location into a comma deliminated string, search the string for the text "WELL" and return "Y" if it's found.
Obviously if you have locations in your dataset like "WELLY", these will become false positives and you'll have to implement some more nested logic. Try appending a value (perhaps !) to the lookupset return field so that you can search for "WELL!" or some other terminator character.

SSRS - Expression with Lookup in child group causes repeating label values

I created a matrix with two column groups (year and quarter).
The expression for the quarter label (the expression under [year]) is:
"Q " & CStr(Fields!quarter.Value)
So in the report I get Q1, Q2, Q3 and Q4 as quarter labels.
We have a international team so I need the others labels to be in german or in english, depending on the user. So I created a dataset with all translations which is filled from a translation table in the database. To get the correct translation for the label I use the LOOKUP() function.
When I use LOOKUP() to get the correct translation for the "amount Rest" textbox (located in the year group) it works fine:
=LOOKUP(11, Fields!ID.Value, Fields!description.Value, "ds_Labels")
The result:
But when I try to use LOOKUP() to get the translation for the "amount" textbox, which is located in the quarter group, the correct translation appears but the year label also starts with 2014 instead of 2008 and the quarter and year labels repeat:
=LOOKUP(17, Fields!ID.Value, Fields!description.Value, "ds_Labels")
The result:
I've no idea what kind of bug this is and how I can get rid of it. Maybe someone can help me :)
UPDATE
Like I mentioned in the comments, the LOOKUP() function works in the first three columns of the quarter group. The report goes crazy if I try to use LOOKUP() in the fourth textbox of the quarter group (see the second last screenshot). But I still don't understand why...
UPDATE 2
When I deploy the report on a SSRS 2008R2 the report works completely fine. But I need it to run on SSRS 2012. Maybe it is a SSRS2012 bug?
Have you made sure that only one record is being returned when you look up the record(s) associated with id 17? The function is designed to be used for 1 -to- 1 relationships
I believe it's a bug. Running Lookup() / LookupSet() queries against the same dataset that is being currently rendered in a tablix causes duplicates.
The only workaround I found is to pass a copy of the dataset and run Lookup() queries against that copy. This way everything works fine.

Need Savings totals by month to pull data correctly and display in Chart

My data and this SSRS chart have a ton of problems, I'll try to keep my question(s) succinct.
First, as you can see by this chart and this screenshot of my data (just showing date and April Savings), my expression/chart is not summing all of the savings within a month, which is my goal.
It appears to be picking one amount within the correct month and using it. I set up a tool tip for April so I could see what number it's pulling (since clearly the chart columns are not representing the data whatsoever - another issue).
You'll see in the SQL data screenshot that it does indeed pull $1,230 from the April 2013 Savings. How can I get this to Sum within the month AND still do a running value from the beginning of time data began to current, this often will include multiple years.
Here's my Chart Data (note that my Team Goal works perfectly, and is even charted correctly - but if anyone knows how to force that line to go from end to end on my chart, feel free to let me know.) :
To summarize, how can I sum each month's data, while still do a running value across the months AND years?
Here's my Expression for Implementable Savings:
=RunningValue(Sum(Fields!ImplementableSavings.Value), Sum, nothing)
(obviously if I can get one working, I can get both)
My Expression for ImplementedSavingsMonth:
=MonthName(Month(Fields!ImplementedSavingsDate.Value))
My Expression for ImplementedSavingsYear:
=Year(Fields!ImplementedSavingsDate.Value)
Let me know if there's anything else I can provide.
Quick sidebar question: WHY does my chart column collect one piece of data. IE: see the tool tip $1,230 for April 2013), but the chart column displays that the number is around $1.7M? And in this scenario, both of my blue and yellow columns are displaying the same number, so why does blue always appear to be a higher number? I will ask this as a 2nd question if it's inappropriate for me to ask here.
I would use this Expression for Implementable Savings:
= RunningValue ( Fields!ImplementableSavings.Value, Sum, "Chart1")
.. assuming your Chart's name is Chart1.