Reporting Services - Find value in a group - reporting-services

I have a column with three possible values:
-1, 0 and any value greater than 0.
In each group, I must verify if ALL values are equal to -1 and if present ALMOST 0 value.
Is it possible?
I tried to solve it in this way:
=IIf(CountDistinct(Fields!Flag_09.Value,"Group1") = CountRows("Group1")
And First(Fields!Flag_09.Value = "-1"), "-",
[ ???? ])
Thanks

As far as I can tell, you want to see if all the detail rows in a group are -1 and then do something. Fortunately your data allows a very simple solution:
=IIF(CountRows("Group1") = 0 - SUM(Fields!MyField.Value), "-", "They aren't all -1")
That is, if the number of rows is equal to the negative of the sum of this field, then all the fields have -1 in them.

Related

LAST WHERE clause in SSRS expression

For the visibility of some fields, i want to check if a field has a specific value.
Right now i'm using this visibility expression:
=IIF (Sum(IIF(Fields!TagName.Value = "Option1" , Fields!Val.Value, 0), "ParamDataset") > 0, true, false)
If option1 is 1, the field is shown, if its 0 then its hidden.
Its working, but the solution is bad.
It checks all the entrys of Option1, and if it were at one time 1, the field is shown, even if the last entry is 0. Also it differentiates only between 0 and 1.
I'm searching for a expression which checks only the last entry of "Option1", and if possible also if the value is a specific value, not only 0 or 1. For example if its 23 or whatever.
PS: i cannot use tablix and the corresponding filters, because the process data is in a different dataset than the configuration data.
I don't think this is possible in an SSRS expression. I thought of using LAST but you want the LAST where OPTION = 1.
You might be able to make it work if you could sort the data so that Option1 is the last sorted followed by your current sorting:
ORDER BY CASE WHEN TagName = 'Option1' THEN 1 ELSE 2 END, <CURRENT SORT CRITERIA>
Now since your Option 1 TagName is last and you want the last of the Option1, you could use LAST:
=IIF(LAST(Fields!Val.Value, "ParamDataset") > 0, true, false)
It would work better if you could add a ROW_NUMBER to the ParamDataset:
,ROW_NUMBER()OVER(PARTITION BY TagName ORDER BY SOME_FIELD DESC) ROW_NUM
Then you could check for Tag Name = Option1 and ROW_NUM = 1:
=IIF(SUM(IIF(Fields!TagName.Value = "Option1" AND ROW_NUM = 1, Fields!Val.Value, 0), "ParamDataset") > 0, true, false)

Using like operator in SSRS Expression

I have a tablix with following results.
SSRS Result
Since i am learning SSRS. i wonder how to Sum line total with respect to product name. Since product name has duplicate values but it has only M and Xl difference. If i use row group it won't total like i expected since it has M and Xl difference. I wonder how to write an expression for the total.
The desired result set
May 31 2011 S043659 Long-Sleeve Logo jerse M 3 $86.52
Long-Sleeve Logo jersey XL 1 $28.84
Total $115.36
mountain bike socks M 6 $34.20
i used this expression but giving me an error.
`IIF((Fields!Product.value = Previous(Fields!Product.value),Sum(Fields!linetotal.value))`
There's actually a few things wrong with your expression.
The IIF doesn't have a 3rd argument for the ELSE value. In this case, you'd want to use 0. So the expression would be IIF the fields match then LineTotal Else 0.
You want to have the SUM on the outside of the IIF, otherwise it will only SUM one row.
The matching without the size is trickier. I have it trim off the last 4 characters to exclude the size for a match - it may not work depending on your other Product names.
=SUM(IIF(LEFT(Fields!Product.value, LEN(Fields!Product.value) - 4) = LEFT(Previous(Fields!Product.value), LEN(Fields!Product.value) - 4), Fields!linetotal.value, 0))
The expression reads the SUM of (IF the Product matches the Previous Product then the Line Total else 0).
All this being said, it would actually be easy to crate a parent group and GROUP BY on the parent product. Unfortunately, your data uses a comma to separate one type (jersey) by size but a space in another (socks) so I don't see how to do it. If they all had a comma, I would create a Calculated Field on the dataset to use the product-line up to the comma.
=LEFT(Fields!Product.value, INSTR(Fields!Product.value, ",") - 1)
IF your Product line is either a comma or space to separate, you might be able to use this for your Calculated Field:
=LEFT(Fields!Product.value,
IIF(INSTR(Fields!Product.value, ",") > 0,
INSTR(Fields!Product.value, ",") - 1,
InStrRev(Fields!Product.value, " ") - 1) )

How to read a sql expression

I am very new to sql and trying to understand a simple aggregate expression.
sum(if(i.action = 'clean_delete', 1, 0)) as uninstalls,
What exactly the above expression mean or will do. I am having a hint it means if action = clean_delete assign it as 1 , else 0 .. but why sum ?
Sorry for being dumb at this point
This sums up how many times the condition is true.
In other words how many actions are clean_delete.
if(i.action = 'clean_delete', 1, 0)
returns 1 if the condition is true and 0 otherwise. In MySQL you could even reduce that to
sum(i.action = 'clean_delete') as uninstalls
If the action has the text 'clean_delete', 1 is returned; else 0.
So, this is summing up the cases where action is 'clean_delete' and using the alias uninstalls.

How to not COUNT a value in SSRS matrix when value is NULL

I cannot make the my expression NOT count a NULL value in my SSRS matrix.
In my SSRS matrix, I have 2 columns one for AppraisalCompany and a count under the SubmittedDate column. In my report this what is happening:
Per Derrick's suggestion here is the change I made in the ColumnGroup properties for the SubmittedDate:
Here is my expression change in the ColumnGroup properties:
Unfortunately I got this error:
I'm suspicious of your Dataset, I'm not entirely sure how you're getting a null value to return 1 in the COUNT. I have been unable to reproduce your results.
Dataset Query
SELECT 'Drive In' AS AppraisalCompany, NULL AS SubmittedDate
UNION
SELECT 'Photo App - English', 'Dec-18'
Next I created a Row Group on AppraisalCompany and a Column Group on SubmittedDate.
I filtered the column group to remove the null grouping, using the expression =IsNothing(Fields!SubmittedDate.Value), operator <>, and Value true.
In the textbox in the matrix I used [Count(SubmittedDate)].
OUTUT
Appraisal Company | Dec-18
-------------------------------
Drive In | 0
Photo App - English | 1
By a Decimal (Number) datatype Nothing and 0 are the same. You can test this.
Put a tablix into your report with year from 2017 to 2019. Then put the year in a column of the tablix as a number format, then write the following expression in the detail textbox:
=CDec(IIF(CDec(Fields!Year.Value) = 2017, 0, Nothing))
After executing your report you will notice that every value in the year column is 0.
The same goes for the check. Both of these expressions will always return Yes. I basically check for 0 and the second one for for Nothing:
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = 0, "Yes", "No")
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = Nothing, "Yes", "No")
But remember your textbox/column has the be a number format.
So if you want to return Nothing and you display it in a number format textbox, it will show you a 0.
With this in mind it will make sense that a Count() returns the value 1 for 0 AND Nothing. So basically this will do the trick:
'Cont
=Sum(IIF(Fields!YourValue.Value = Nothing, 0, 1))

Report and Graphic in access 2007 - calculating values on queries

Picture a table with fields (Id, Valid, Value)
Valid = boolean
Value = number from 0 to 100
What I want is a report that counts the number of records where (valid = 0), and then gives me the total number of cases where (value < 70) and the number of cases where (value >= 70).
The problem is that the "value" field could be empty on some of the records and I only want the records where the value field is not empty.
I know that the second value (value>=70) is going to be calculated, but the problem is that I can't simply do (total number of records - number of records where value < 70), because there's the problem with the records where "value" is null...
And then I want to create graphic with these values, to see the percentage of records below and above 70.
"The problem is that the "value" field could be empty on some of the records and I only want the records where the value field is not empty."
Use a WHERE clause to exclude rows whose "value" field is Null.
Here is sample data for tblMetraton.
Id Valid Valu
1 -1 2
2 0 4
3 -1 6
4 0
5 0 90
I used Valu for the field name because Value is a reserved word.
You can use the Count() function in a query and take advantage of the fact it only counts non-Null values. So use Count() with an IIf() expression which returns a non-Null value (I used 1) for the condition you want to match and Null otherwise.
SELECT
Count(IIf(Valid=0,1,Null)) AS valid_false,
Count(IIf(Valu<70,1,Null)) AS below_70,
Count(IIf([Valu]>=70,1,Null)) AS at_least70
FROM tblMetraton AS m
WHERE (((m.[Valu]) Is Not Null));
Based on my sample data in tblMetraton, that query gives me this result set.
valid_false below_70 at_least70
2 3 1
If my sample data does not address the variability you're dealing with, and/or if my query results don't match your requirements, please show us you own sample data and the results you want based on that sample.