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

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.

Related

SSRS Data Returned but Not Showing in Tablix

SQL Server 2019
Report is being built in Visual Studio 2019, and is not yet deployed to SSRS.
Scenario - Report calls a stored procedure passing in 3 parameters (Rep ID, Year, Month) then displays the "first row" value from several columns of the data returned in a page header section, then displays the rest of the columns' data in a tablix.
Issue - it works fine when I request for all (wildcard % feeding into a LIKE statement) Reps for any given month/year combo. It breaks when I request for a specific Rep ID.
Here's what I've found:
it passes the correct Rep ID value in the query as viewed via Profiler,
the statement grabbed from Profiler works fine in SSMS directly
the number of rows returned via SSMS direct is 347, the number of rows returned as seen in Profiler is 355 (odd (to me), but not the driving concern at the moment as there's also a rowcount diff in the "all" query that is displaying fine; assuming some sort of overhead)
the "first row" values from the returned data are showing fine on the report preview screen
it's the rest of the columns' data that is not showing up in the tablix on the report preview screen when I select a specific Rep ID vs. using All
I also tried hard-coding the values within the stored procedure, and the same number of rows are returned, with the same result of "first row" values being used but the tablix not displaying the rest of the data
I do have a "no rows" message, but we know it's seeing the rows or it couldn't get the "first row" values so that's rather moot
What sorts of things do I need to look at to get this working?
Thanks in advance!
2020-10-21 EDIT: for what it's worth, I've now also tried
recreating the report without the top-level grouping (REP) since a single-Rep version does not need that level, no change
adding to the report (so, it's seeing the exact same data) a matrix vs. a tablix, matrix displays both the all-rep and single-rep data fine, I just can't make that give me the same format, arrangement, and sub-total lines, etc. as the tablix (not surprising since they're different beasts) though I'm trying my best there in case I can't get the tablix to behave
profiler-ssms-reportpreview-image
I found the issue. It was hiding the grid on 1 Rep row instead of hiding it at 0 rows as expected.
<Visibility>
<Hidden>=RunningValue(Fields!dataRepName.Value, CountDistinct, Nothing) = 1</Hidden>
</Visibility>

SSRS standalone formulas

I have been working on this for days without being able to solve yet. It's probably simple if you know what you're doing. I'm simply trying to make a standalone formula that is not in a tablix or anything, it's just in a textbox.
Here is an example of my Dataset called Dataset1:
What I am trying to get is a sum of the Actual Cost when the Category is Labor from Dataset1. My current expression is:
=Sum(iif(Fields!Category.Value="Labor", Fields!ActualCost.Value, 0), "Dataset1")
I refer to Dataset1 as my scope because otherwise, I get an error about using an aggregate expression without a scope.
The report runs but shows #Error in the textbox that has my expression in it. When I replace Fields!ActualCost.Value with a 1, I get the answer, 5, which is the correct number of rows with Labor as the Category. But it won't let me sum the numbers in the ActualCost column where Category is Labor.
Any ideas as to what I'm doing wrong? I feel like it's something to do with aggregating, but I'm not sure. Thanks!
It may have to do with the datatype of fields!ActualCost.Value. If that field is a decimal (regardless of how you have it formatted), try using cdec(0) instead of just 0 in your expression.

SSRS: Getting Value From A Particular Textbox

I am using Visual Studio 2012 for SSRS purposes.
Currently, in my SSRS report, I have the following setup in my tablix/matrix:
Basically, I have row groups of Date and Mailbox and my first column is Starting which is number of records when starting of a particular date.
When I initially preview the report, this is what shows up:
Right now, in my total box, I have it as sum(starting) which is wrong and doesn't make sense. I basically want the First(Sum(Starting)) but I know SSRS is currently not allowing me to do that.
And I can't do First(Starting) because when I do my drilldown, it looks like this (I blurred out particular mailboxes):
So basically if I did First(Starting), it would pull in 25, instead of 339, because that's technically the first value.
How do I write an expression for the total line in Starting where I can get the first value that shows up underneath the Starting column where it is Sum(Starting) which in this case would be 339.
Basically just had to write a different dataset to be just the value I needed then wrote an expression to grab that specific value from the dataset.

SSRS: Get values from a particular row of DataSet?

My dataset currently has 12 rows of data. Each representing data for a month. I would like to have variance of a column between to rows, the rows being last & last but one i.e., latest month and previous month's data.
It could have been simple if I were to work on tablix but thats not the case. I want those values for a textbox.
Any ideas on it anyone?
I hope you are using SSRS 2008R2:
R2 introduced the Lookup function that is perfect for this scenario.
=Lookup( Fields!ProductUID.Value ,Fields!ProductID.Value,Fields!Price.Value,"PriceDataSet")
The Lookup function above will evaluate the first parameter ("Fields!ProductUID.Value") in the current dataset, then look for a matching value in the field specified in the second parameter ("Fields!ProductID.Value") in the dataset specified in the fourth parameter. The value of the third parameter is then evaluated in that row of the dataset and returned.
A little convoluted, but very helpful.
In your case, you can use this in a textbox with a calculated a static number:
=Lookup(
Month(DateAdd(DateInterval.Month, -1, GetDate())),
Fields!MonthID.Value,
Fields!Name.Value,
"DataSet1")
This should calculate a number for last month, then look for a match in DataSet1.
In this example I have a tablix with Statecode and name as below
enter image description here
Suppose you want to display the name of state of CA, write an expression as -
=Lookup(
"CA" ,
Fields!StateCode.Value,
Fields!StateName.Value,
"ReportData"
)
This will return 'California' in the text box
I ran across this post while trying to solve a similar problem but with columns of double data type. Not sure why but SSRS did not want to return my first row using LOOKUP in combination with ROW_NUMBER in SQL(If someone can solve that all the better). I ended up using a SUM(IIF) instead. Hopefully, this is useful for someone else.
=Sum(IIF(Fields!RowNum.Value=1,CDBL(Fields!MyNumericColumn.Value),CDBL(0)))
Note: If SSRS complains about data types, just cast both parts of the IIF to the desired data type.

SSRS 2005 Matrix Reports - Editing Total

This seems as though it should be simple, but appears not to be.
In SSRS 2005 I've written a matrix report and added some fields, one of which has the formula: If (x / y >= n, 1, 0). I've called this field 'Accuracy'. The report aggregates this field across a number of individuals and then for a number of days.
Ideally I want a subtotal that gives a sum of the 'Accuracy' figures (so we can say we had n people who were accurate today). However, the subtotal calculates the formula for the totals of x and y. Subtotals is only ever going to be 1 or 0.
Any ideas as to how I can get a Count of Accuracy displayed on the matrix report? I've tried creating various fields along the lines of Sum(accuracy) and Count(accuracy) - these return an error when the report is run.
Thanks!
maybe report behaves 0 and 1 as a boolean value. you can make a dll that do this work for you and reference to your report and use the methods that exist for this work in dll.
Try using the running value. You could put the expression inside it or inside the report code block and just call it.
=RunningValue(what to count, sum, scope)
=RunningValue(Fields!Cost.Value, Sum, Nothing)
More info here:
http://msdn.microsoft.com/en-us/library/ms159136.aspx
Hope it helps.