Counting Records in a Form - ms-access

Ok we know that Count will not count null values. So ...
qty_rec is a numeric field.
=Count(Nz([qty_rec],0)<1)
This is what I have for my Control Source on a textbox.
It returns the total number of records rather than the 5 that are null or zero.
What I need is a count of items that do not have a received quantity or a zero quantity.

If your goal is to count the number of records where qty_rec is Null, consider Sum of an IIf expression.
=Sum(IIf(IsNull([qty_rec]), 1, 0))
If the goal is actually count of zero or Null, use this instead:
=Sum(IIf(Nz([qty_rec], 0) = 0, 1, 0))
If you prefer Count instead of Sum, this should give you the same result as the second example:
=Count(IIf(Nz([qty_rec], 0) = 0, 1, Null))

Related

Mysql order by field with given values which has NULL in between

I'm trying to sort a query by given values like this:
ORDER BY FIELD(items.stock_id, 1, 5, NULL, 3, 6)
But it seems it doesn't work and null comes first or last depending on it being descending or not.
The order is not always the same hence [1,5,NULL,3,6] changes every time and is dynamic.
FIELD-function does not match the NULL-stock_id as NULL value (NULL does not have any value).
You could use a magic number:
ORDER BY FIELD(IFNULL(items.stock_id,-1), 1, 5, -1, 3, 6)

sql count the date less than current date

I have a table where user input a target date, and then I want to output the count of names where their associated target date is greater than current date.
I tried but I'm getting the same results
below is the code
$select1_query = "
SELECT ACCOUNT_NAME
, COUNT(NCI_NUMBER)
, COUNT(CURDATE()>TARGET_DATE)
FROM sim_tracker
WHERE NCI_STATUS != 'Closed'
GROUP
BY ACCOUNT_NAME
";
Don't use count(). Use sum():
SELECT ACCOUNT_NAME,
COUNT(NCI_NUMBER),
SUM(CURDATE() > TARGET_DATE)
FROM sim_tracker
WHERE NCI_STATUS <> 'Closed'
GROUP BY ACCOUNT_NAME;
This works because MySQL treats booleans expressions as "1" for true and "0" for false in a numeric context. SUM() then counts the number of "true" values.
COUNT() does not work, because COUNT(<expression>) counts the number of non-NULL values. "true" and "false" are both non-NULL, so they both get counted.

How to use count number of rows which meet the condition in ssrs report?

In my report I want to count number of rows with condition. For example Count Mondays, count weekdays, count Saturdays, etc.
I try with this :
=countdistinct(iif(weekday(Fields!DATE_YYYYMMDD.Value,2)=1,Fields!N_ENTERED.Value,0))
but give me the result 18. I expected 1, because I have only 1 monday between 09.06.2019 and 16.06.2019
The entered value is entered calls from employees.
Your countdistinct is returning the number of unique values you have in your N_ENTERED field, not the number of Mondays.
To just count the number of Mondays, you need to reference the result of your iif instead:
=sum(iif(weekday(Fields!DATE_YYYYMMDD.Value,2)=1, 1, 0))

MySQL avoiding null values for sum operations?

I need to make a column that counts the amount of variables which are above 0, and that won't return null if there is any non-null value in it, for each value in an id column.
What I managed to make is using a sum between some boolean operations:
IF 'A' THEN 'B' ELSE 'C' (at least that's what I've got)
select ID, `jul`, `aug`, `set`, `oct`, `nov`, `dec`,
((((not `jul`) or 1) and (`jul` or 0))
+(((not `aug`) or 1) and (`aug` or 0))
+(((not `set`) or 1) and (`set` or 0))
+(((not `out`) or 1) and (`out` or 0))
+(((not `nov`) or 1) and (`nov` or 0))
+(((not `dec`) or 1) and (`dec` or 0))) as sum from table;
It works at first view, but if there is any null value in a line, the sum returns null for each respective id.
What could I do to avoid this problem?
try
SUM( IFNULL(jul,0)+IFNULL(ago,2) ) as sum from table
/*
obs: the SUM is good to sum multiple values
IFNULL returns 0 to the sum if jul is null and 2 for ago if ago is null in the example.
*/
i think it works. :)
You need to use a coalesce or variant to deal with nulls. Null value represents an unknown. You can't add unknowns and get something other than an unknown.
NULL + 1 = NULL
COALESCE(NULL, 0) + 1 = 1
Use isnull(columnname, 0) to turn nulls into 0s. So isnull('jul',0)+isnull('aug',0) etc.

How to add total for calculated (using expression)column in SSRS

Column expression:
IIf(Left(Fields!EmployeeNo.Value,1)<>"2",Count(Fields!EmployeeNo.Value),"")
TOtal expression is:
Sum(IIf(Left(Fields!EmployeeNo.Value,1)<>"2",Count(Fields!EmployeeNo.Value),""))
if use this expression for total getting message as "#Error" in report preview.
Please tell me how to get this done.
Your column expression doesn't need a Count - that is for aggregation across multiple rows. Your total expression also can't have a Sum and a Count.
Try this for your column expression:
=IIF(Left(Fields!EmployeeNo.Value, 1) <> "2", 1 , 0)
and sum that for your total expression:
=Sum(IIF(Left(Fields!EmployeeNo.Value, 1) <> "2", 1 , 0))