COUNTIF in Tableau? - function

I have a simple COUNTIF task in Excel that is proving rather difficult to replicate in Tableau...
This is the data:
ID Metric Scope DynamicCalc
1 A1 TRUE X
1 B1 FALSE X
2 B1 TRUE X
2 A1 FALSE X
2 C1 FALSE X
The column 'DynamicCalc' should have the following values when Metric=A1 is selected: TRUE,TRUE,FALSE,FALSE,FALSE but if say B1 is selected it would be FALSE,FALSE,TRUE,TRUE,TRUE... so basically I want to assign a value of TRUE to the DynamicColumn if there is at least one TRUE in the Scope column to all rows for that ID.

The LOD Expression can be used to retrieve your desired result
try using a calculated field like below :
{FIXED [ID],[Metric]:MAX(if [Scope]='TRUE' then 'True' else 'False' end)}
When the Selection is B1 :

I know this is late, but as SO community (bot) has made it active again, I propose a slightly different approach. The selection should be through parameter.
After making parameter on Metric field, create a calculated field say Dynamic calc like this
{FIXED ID : MAX({FIXED ID, [Metric]: MAX(If [Metric] = [Metric Parameter] THEN [Scope] END)})}
Add this field and your desired view is complete. See GIF below

Related

How to display 1.0% as 1% in SSRS expression

I am calculating percentage and formatting the value as "0.0". That give me values like 3.7%, 4.1% etc. But when it's 1.0% I want to show as 1% only, how to remove decimal when the there is a whole value?
Thank you.
I am assuming your database values are in decimal format so that 0.01 represents 1%.
If this is not the case, let me know and I will modify the answer.
I created some test data with
SELECT 0.09 as pc
UNION SELECT 0.091
UNION SELECT 0.099
UNION SELECT 0.01
UNION SELECT 0.011
UNION SELECT 0.012
UNION SELECT 0.019
UNION SELECT 0.020
UNION SELECT 0.021
I then added a table to show the raw value plus various other formats.
Finally I added a 4th column that formats the value based on if it is a 'whole percent' or not.
I set the Format property of the textbox to the following expression.
=IIF(
Fields!pc.Value * 100 = CINT(Fields!pc.Value*100)
, "p0"
, "p1"
)
This basically checks if the value when multiplied by 100 is an integer, if it is then we apply p0 as the format code, if not we apply p1 as the format code.
The end result is as follows.
Note: We have only changed the format property of the textbox, not the value expression.
As you can see in the design below, each column's value expression is identical ([pc]), it is only the format property of each textbox that is different. To show the properties panel click on the textbox and then hit F4 in Visual Studio. If you are using Report Builder then I'm not sure if F4 works, but there is a menu option to show the properties panel somewhere.
Finally, you will obviously need to replace the field pc from my example with the actual field name in your report.
How about you wrap an iff statement around your formating?
Something along the lines of
=iif(round(Fields!num.Value) = Fields!num.Value,format(Fields!num.Value,"0%"),format(Fields!num.Value,"0.00%"))
This evaluates the output and if it is 1.0% then it makes it 1% else formats the rest of the value as required

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))

SSRS: How to add an condition in the expression while counting rows?

I need help with writing a conditional expression for counting specific rows of the dataset using which I determine to make a textbox visbile
DataSet_Example
Name value Level
ABC 12345 PG1
DEF 45677 PG2
FEG 98098 PG1
I want to count the rows based on the level. Something Like the one below
iff(CountRows("DataSet_Example").Level == PG1 < 1)
How do I do it in SSRS expressions?
You need insert a row group for "Level" and then set your visibility expression for each row to the following:
=IIF(CountRows("Level") > 1 , condition if true, condition if false )

SSRS - Group set of rows based on calculated value from the row's data

I want to group ( display ) a set of row(s) based on a calculation on one of row's column data.
Lets say I have 3 columns in my tablix.
1. Description
2. Amount
3. Debit/Credit
based on the D/C value I would like to sum up the amount ( for debit its -ve and credit is +ve) until the total gets to zero and then group those rows into a different color or a line space between other set of rows.
Example output:
Description Amount D/C
xyz 10 D
sss 10 C
abc 15 D
vvv 5 C
ccc 5 C
abc 5 C
Thanks
Karthik
I've recreated your scenario using the dataset you have provided in the question.
I am using the Amount cell background-color property to group the sums.
This is the tablix I've created. The selected Cell background-property is set to a expression (see below):
In Report menu, Report Properties... / Code tab put this function in the text area.
Dim prevColor As String = "Red"
Dim accumulator As Double = 0
Public Function GetSumColor(ByVal value as Double) as String
Dim color As String
accumulator = accumulator + value
color = prevColor
If accumulator = 0 Then
If prevColor = "Red" Then
prevColor = "Yellow"
Else
prevColor = "Red"
End If
End If
Return color
End Function
This function will change the cell background color between Red or Yellow based on sums equals to zero (you can use the whatever color you want).
In the Amount cell background-color property use this expression:
=Code.GetSumColor(
IIF(Fields!D_C.Value="C",-Fields!Amount.Value,Fields!Amount.Value)
)
It will produce the following result:
Let me know if this helps you.

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.