Prevent "0" in CountDistinct in SSRS - reporting-services

I have the following expression:
=CountDistinct(IIf((Fields!txtGrade.Value = "*")
And (Fields!txtCurrentSubjectName.Value = "3D Design"),
Fields!intGradeTransposeValue.Value, Nothing))
There are 5 different txtGrade.Value in all - *, 1, 2, 3, 4 not every subject will have a grade. In the columns that have no values the expression is returning back a 0 - is there anyway I can just get it to show a blank cell with no number in it at all. This is what it currently outputs:

There are a couple of options you can use here. First, you could simply wrap the entire expression in an IIF that replaces the zeros with nothing.
=IIF(CountDistinct(IIf((Fields!txtGrade.Value = "*")
And (Fields!txtCurrentSubjectName.Value = "3D Design"),
Fields!intGradeTransposeValue.Value, Nothing)) = 0, "",
(CountDistinct(IIf((Fields!txtGrade.Value = "*")
And (Fields!txtCurrentSubjectName.Value = "3D Design"),
Fields!intGradeTransposeValue.Value, Nothing))))
The second option would be to set the text box properties to show zeros as a blank as shown in this image:

Related

SSRS - show field in expression based on where clause?

I have a data table that looks like the below. This shows the top 3 subcallcategories based on the amount of calls. The "order" column is a row number that shows which order the subcallcategory was in based on the calls.
I am trying to write some DAX in SSRS which displays the following
Anxiety was the most common counselling call, followed by Work Related
Stress and Bereavement
I have written the below code however it doesn't seem to be picking up the last 2 categories? Anyone have any ideas what I am doing wrong?
=IIf(Fields!Order.Value = "1" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") &
" was the most common counselling call, followed by " &
IIf(Fields!Order.Value = "2" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") &
" and " & IIf(Fields!Order.Value = "3" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "")
Below is my current output
As Alan mentioned, your expression is just looking at a single row of data.
You would need to put this expression in a table with Grouping by Category.
Then you would look for the ones in your ORDER and use that Sub Cat value. I use MAX and NULL to get matching values like
=MAX(IIf(Fields!Order.Value = 1, Fields!SubCallCategory.Value, NOTHING)) &
" was the most common " & Fields!Category.Value & " call, followed by " &
MAX(IIf(Fields!Order.Value = 2, Fields!SubCallCategory.Value, NOTHING)) &
" and " & MAX(IIf(Fields!Order.Value = 3, Fields!SubCallCategory.Value, NOTHING))
The MAX will get the SubCat value over NOTHING (SSRS for NULL) for the ones in the right ORDER.
This would give one line for Counselling and one for Legal.
You could also add the totals in with
MAX(IIf(Fields!Order.Value = 1, Fields!Calls.Value, 0))
I assume your ORDER field is an INTEGER and doesn't need the quotes.

IIf query decimal removal

Trying to attempt the following in MS Access.
Convert data in one field to an 18 digit number starting with 01 in another field.
There are also some conditions that have to be met:
the first dash should become double zeros
the second dash should be removed
the third and fourth dash should be a single zero
the decimal must also be replaced with a zero
My query works fine until the decimal is the 15th character in the data.
Here is the query:
SELECT MasterVacant.ParcelIdNumber,
"01" + Mid([ParcelIdNumber],1,2) + "00" + Mid([ParcelIdNumber],4,2) + Mid([ParcelIdNumber],7,1)
+ IIf(Mid([ParcelIDNumber],11,1) = "", "0"+Mid([ParcelIDNumber],9,2), Mid([ParcelIDNumber],9,3))
+ IIf(Mid([ParcelIDNumber],14,1) = ".", "0"+Mid([ParcelIDNumber],12,2), Mid([ParcelIDNumber],12,3))
+ Mid([ParcelIDNumber],15,3) AS ParcelNumber
FROM MasterVacant;
Here is a start and finish example...
'12-06-1-00-50.000-RR' should become '011200061000050000'
'12-06-3-07-09.000-RR' should become '011200063007009000'
'13-35-1-01-129.000-RR' should become '011300035100112900'
However, instead of getting `0113000351001129000' I get '013000351001129.00'.
The issue is how do I remove the decimal when the decimal is the 15th character like in the third set of example?
I receive the data as a single column. Some of it is below....
1. 13-35-1-07-29.000-RR
2. 13-35-1-01-112.000-RR (Removing the decimal when the data is like this is the issue)
3. 13-35-4-01-01.000-RR
4. 13-35-4-02-04.000-RR
5. 13-35-1-13-17.000-RR
The output for the above data should be
1. 011300351007029000
2. 011300351001112000
3. 011300354001001000
4. 011300354002004000
5. 011300351013017000
Use a custom function:
Public Function Make18(ByVal Value As String) As String
Const Head As String = "01"
Const Tail As String = "000"
Const Lead As String = "00"
Dim Parts As Variant
Dim Part As Integer
Dim Result As String
Parts = Split(Split(Value, ".")(0), "-")
For Part = LBound(Parts) To UBound(Parts)
Select Case Part
Case 0
Parts(Part) = Head & Parts(Part)
Case 1
Parts(Part) = Lead & Parts(Part)
Case 3, 4
Parts(Part) = Right(Lead & Parts(Part), 3)
End Select
Next
Result = Join(Parts, "") & Tail
Make18 = Result
End Function
and your query becomes:
SELECT
MasterVacant.ParcelIdNumber,
Make18([ParcelIdNumber]) AS ParcelNumber
FROM
MasterVacant;
I am assuming you meant the opposite where:
12-06-1-00-50.000-RR should become 011200061000050000
12-06-3-07-09.000-RR should become 011200063007009000
13-35-1-01-129.000-RR should become 0113000351001129.00
I would recommend the REPLACE() in MSACCESS to strip the dashes out. Once you have the dashes out you can MID()
Unfortunately your attempted code does something different with the 3rd row because 3 zeros are being put in when there should be only two in my opinion.
Try in a text box:
=Replace("13-35-1-01-129.000-RR","-","")
will return 1335101129.000RR
and see if that assists you in making your code.
Maybe go one step further and put it in a function.

Conditionally format certain cells of tablix

Using Visual Studio 2017 (SSDT), I have a tablix where I would like to use an expression to set the background color/fill. I would like the cells to fill gray where the:
2019 Metal is Silver and 2020 Metal is Bronze, or
2019 Metal is Gold and 2020 Metal is Bronze, or
2019 Metal is Gold and 2020 Metal is Silver.
Visually, like this:
The data set populating the tablix is:
(I added custom "Is Null" code to display zeros instead.)
I've been trying IIF statement logic but have been unable to get my desired results.
The design of the tablix is:
I'm trying to set the Fill BackgroundColor on the textbox here with an expression:
...using something like:
=IIF(
Fields!METAL_YEAR_2020.Value="Bronze" AND
(Fields!METAL_YEAR_2019.Value = "Silver" OR Fields!METAL_YEAR_2019.Value = "Gold")
, "Gray"
, "Transparent"
)
If I leave out the OR condition I can fill one intended cell, but I don't know how to account for the three cells.
So, this code below sets one cell but can I nest or SWITCH to set the three cells I want?
= IIF(
(
(Fields!METAL_YEAR_2019.Value = "Silver" and Fields!METAL_YEAR_2020.Value = "Bronze")
OR (Fields!METAL_YEAR_2019.Value = "Gold" and Fields!METAL_YEAR_2020.Value = "Bronze")
OR (Fields!METAL_YEAR_2019.Value = "Gold" and Fields!METAL_YEAR_2020.Value = "Silver")
)
, "Gray", "White")
since there is no data where you get the null values (not only the integer value is absent, but all values, you have to refer to the group value, which is in the textbox)
= iif(
(cstr(ReportItems!Metal_2019.Value) = "Silver" AND cstr(ReportItems!Metal_2020.Value) = "Bronze") OR
(cstr(ReportItems!Metal_2019.Value) = "Gold" AND (cstr(ReportItems!Metal_2020.Value) = "Silver" OR cstr(ReportItems!Metal_2020.Value) = "Bronze")),
"Gray","Transparent")
found at

ssrs show text different colour when field matches with another

I have a requirement to show different text color when one field matches with another three different fields.
I have written below expression,
=IIF(
Fields!OrderBlockLetter.Value = Fields!InstitutionBlockLetter.Value, "Green",
or Fields!OrderBlockLetter.Value = Fields!DegreeBlockLetter.Value, "Orange",
or Fields!OrderBlockLetter.Value = Fields!AwardBlockLetter.Value, "Blue", "No Color")
But its not working. When saving this code it gives error.
I am using SSRS report builder.
You can't use IIF with OR like that. IIF just returns a value if the expression is true and another if it's false. You can nest IIFs to get the desired results but using SWITCH is much simpler. Try this... (not tested but should be close enough)
=SWITCH
(
Fields!OrderBlockLetter.Value = Fields!InstitutionBlockLetter.Value, "Green",
Fields!OrderBlockLetter.Value = Fields!DegreeBlockLetter.Value, "Orange",
Fields!OrderBlockLetter.Value = Fields!AwardBlockLetter.Value, "Blue",
True, "Black"
)
As switch returns on the first true expression, if all the others fail, the final expression is always True so the "Black" will be returned.
EDIT: Actually, "No Color" is not a valid font. You either need to pick black (the default color), or white (to give the appreance of there not being text there)

SSRS customized pie chart color

I have a doubt here,
I need to show a pie-chart in SSRS, for the student results according to their status(Pass/Fail).......I have only 4 conditions Male-pass,Male-fail,Female-pass,Female-fail,I need to show these things with my own color,
for this am using the switch condition as
=Switch(
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Pass")), "Blue",
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Fail")), "HotPink",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Fail")), "Orange",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Pass")),"LimeGreen" )
but in the preview it shows only the default color set, not the customized one, can anyone fix this one...thanks in advance
Try using something like
=IIf((Fields!Gender.Value = "Male") and (Fields!Status.Value="Pass"),"Green",
IIf((Fields!Gender.Value = "Male") and(Fields!Status.Value="Fail"),"Red" ,
IIf((Fields!Gender.Value = "Female") and (Fields!Status.Value="Fail") ,"Blue",
(Fields!Gender.Value = "Female") and (Fields!Status.Value="Pass"),"Yellow","Orange"
,"#00000000"))))
You should be able to get it working using the Switch statement as well. The problem with your expression is that the logical "and" operator in SSRS is And, not ampersand. In SSRS, a single ampersand is used for concatenating strings. So your expression is concatenating the string representation of the two boolean results, resulting in strings like TrueFalse. This should actually giving an error on the Switch evaluation.
A correct Switch statement would be this:
=Switch(
Fields!Gender.Value = "Male" And Fields!Status.Value="Pass", "Blue",
Fields!Gender.Value = "Male" And Fields!Status.Value="Fail", "HotPink",
Fields!Gender.Value = "Female" And Fields!Status.Value="Fail", "Orange",
Fields!Gender.Value = "Female" And Fields!Status.Value="Pass","LimeGreen"
, True, "SomeOtherColor"
)
I've also added an "else" part to the switch in case some records are not covered by the other conditions. If you're 100% sure that won't happen, you can remove the line that starts with "True". But it shouldn't hurt to keep it either.
More info: Pie Chart Techniques (look for Custom Coloring chapter)