How can I check if an integers value is 0 or because it is null,it is taking its value as 0 - ios

I have an integer(int a) whose value can be ranged between -30 to +30.so if the user selects a value from the range provided,(int a) value should change accordingly.but then sometimes,when the user does not select anything from the provided range and skips the option,(int a)is been set to null and automatically assigning the value by itself as 0.how can I differentiate this and and the user himself choosing 0 as the value of (int a) as it is also included in the provided range.

You could try setting the initial value of the integer into something that is clearly outside the range (-999, for example). So that when you re-check the integer, if the value is out of the range's bounds then you know the value has never been set.
Alternatively you could encapsulate the value in an object instead of using the primitive, i.e you could use NSNumber.

Related

Calculate count of rows with a dimension value Tableau

I want to create a Calculated field to display a Number when the Column/Dimension Outcome_Code == Death.
EX: Out of 1000 rows if 400 rows has Outcome_Code == Death, then I just want to to display a big Number 400.
If I give COUNT(Outcome_Code == 'Death'), it is just just counting total number of rows in the table and showing 1000.
How to create a Calculated field in this case, I don't want a table of value counts, I Just want to display the number, so want a calculated field.
SUM(INT([Outcome_Code] = "Death"))
The innermost expression is a boolean valued expression. The function INT() is a type conversion function that converts boolean values into integers -- evaluating to 1 if the boolean value is True and 0 if it is False. You can leave off the SUM in the calculated field and apply that on the shelf instead if you prefer.
It's worth the effort to realize that boolean expressions are first-class expressions, and can be treated just as naturally as numeric expressions. Other similar expressions are:
MAX([Outcome_Code] = "Death")
which evaluates to True if ANY data records have "Death" for an [Outcome_Code]
and
MIN([Outcome_Code] = "Death")
which evaluates to True if ALL data records have "Death" for an [Outcome_Code]
The last two take advantage of the fact that Tableau treats True as greater than False -- from which you can derive the meaning of MIN and MAX applied to boolean expressions

check if all values returned in filter are equal (google sheets)

I have a row with the following values in each cell from A1 until F1
A,A,A,A,A,A
Then in row 2 I have
A,B,A,A,A,A
Since some columns are empty (no value) I filter the row to get only cells with value:
=filter(A1:F1, A1:F1<>"")
then how can i get a true/false response if all values/strings in the filter array are equal?
Similar answer given here, but that was for a set of arbitrary cells, not a range.
Using range notation:
=COUNTUNIQUE(A1:F1)=1
As implied by the function name, it counts the number of unique values. If there is only one unique value, then we know all the cells are equal. Since COUNTUNIQUE disregards blank values, there is no need to use FILTER first. If you want TRUE for all blanks, change = to <=, as it will return 0 in that case.
If you later decide you do want to consider blank values:
=COLUMNS(UNIQUE(A1:F1, 1))=1
This counts the number of columns returned by UNIQUE(..., 1) (1 means "by column"). If it's 1, then all cells are equal.

Using COUNTIFS or dcounta instead of multiple COUNTIF

In our Staff timetable, employees can have an "A"shift (which starts at 9am) a "B" shift (which starts at 10:30am) etc.
I need to know how many shifts in total the employees make so what I use now is a multiple times COUNTIF to count the presents of a few arguments in a range of cells
=countif(D8:BM8;A43)+countif(D8:BM8;A44)+countif(D8:BM8;A45)+countif(D8:BM8;A46)++countif(D8:BM8;A47)
Where field A43 contains "A" field A44 cointains "B" etc.
This works perfect, however, I want to have a smarter way to do this, so I tried to use "COUNTIFS" but the result is always 0 and I can't find why
=COUNTIFS(D8:BM8;A43;D8:BM8;A44;D8:BM8;A45;D8:BM8;A46;D8:BM8;A47)
if looks like all arguments are checked with a logical and, but I need a logical and in this case or a solution with dcounta
You are getting a 0 because there is no cell that will meet ALL conditions.
Instead, maybe try something like
=sum(ArrayFormula(--regexmatch(D8:BM8; textjoin("|"; 1; A43:A47))))
Regexmatch returns a boolean, for all the cells in D8:BM8 (true if a match is found, false otherwise). These booleans are converted into 1 and 0 (see the -- in front of the regex). Then all those values are summed.
Copy and paste the code in a module.(VBA)
Select the cell you want to have the results
Use COUNTIFMATCH Function as the usally functions.
The first Argument is the range you want to count. The second Argument is the range with your criteria. e.g
=COUNTIFMATCH($A$1:$A$20,$C$1:$C$3) or =COUNTIFMATCH($A$1:$A$20,($B$1,$D$1))
whatever you need based on your needs.
Option Explicit
Function COUNTIFMATCH(Range As Range, Criteria As Range) As Integer
'counts the number of cells in one range by the values ​​of another range.
Dim datax As Range
Dim rslt As Range
Dim i As Integer
Set rslt = Range
For Each datax In Criteria
i = i + WorksheetFunction.CountIf(rslt, datax)
COUNTIFMATCH = i
Next datax
End Function

Loop through fields in rdlc report

I have an Rdlc report
In this report I have a field which takes its values by this expression
(Round(((First(Fields!Occurs.Value) / First(Fields!TotalDistance.Value))* 10000),2)
but in some cases (TotalDistance.Value) = 0 so the previous expression returns Infinity,
So I need to get the next record in case of that field equals 0 ,
If also next field equals 0 , I want to get the next one
I looked for way of getting next record but didn't find
I only found (First , Last) methods,
How can I do that ?
instead of using First or Last if you don't care which record as long as it isn't 0 then couldn't you use an aggregate function. ex:
(Round(((First(Fields!Occurs.Value) / MAX(Fields!TotalDistance.Value))* 10000),2)
you could use Max, Min or Avg to get a value. I am unaware of any way within the rdlc to loop through the records like you are asking.
Another completely different way could be to load the data into a datatable then add a column to contain the calculated value and use some code to calculate the values before being passed to the report.

zf2 form filter treat 0 as integer and empty string as null

This question may be obvious to some :)
I've got an input which needs to handle numeric values and then filter/validate when empty as null.
Every method I've tried has resulted in the value either being treat as 0 both when empty and having a value of 0 or as null when empty or having a value of 0.
Thanks in advance.

Resources