Counting elements of a list based on a criteria

Iโ€™m trying to come up with an expression that counts the number of related trainees that have a status of โ€œactive approvedโ€. The below expression doesnโ€™t work because Iโ€™m not sure how to โ€œdereferenceโ€ or whatever you call it the [current status] column within the individual related trainee records. Please advise.

count(select([Related Trainees], ([current status]=โ€œActive Approvedโ€)))

Solved Solved
0 14 287
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

Try:

count(select([Related Trainees][_ROWNUMBER], ([current status]=โ€œActive Approvedโ€)))

View solution in original post

14 REPLIES 14

Where are you applying this formula? To a column or a name of a view?

This is just a virtual column.

Can you please explain it further? What table are you into? Are in the related trainees or other table?

The table the virtual column exists in contains a reference to the trainees table. There is a โ€œrelated traineesโ€ column as per usual, which contains that list.

Here is what I understand with your post and replies. There is a TABLE called TABLE 1 (I just named it), which has a reference table on it called RELATED TRAINEES. Is that correct?

Steve
Platinum 4
Platinum 4

Try:

count(select([Related Trainees][_ROWNUMBER], ([current status]=โ€œActive Approvedโ€)))

Interesting! Iโ€™ve always used SELECT(TableName[ColumnName],...).

I didnโ€™t realized you could use SELECT([Ref_Rows][ColumnName]...!

See Constructing a List from a List Dereference here:

That worked. Letโ€™s take it a step further now. I want to add the total number of โ€œactive approvedโ€ trainees to the number of โ€œgraduateโ€ trainees that graduated in the current year.

count(select([Related Trainees][_ROWNUMBER], ([current status]=โ€œActive Approvedโ€))))+count(select([Related Trainees][_ROWNUMBER], (and([current status]=โ€œGraduateโ€, year([graduated])=year(now()))))

The system basically ignores the second part altogether, stopping with only evaluating the first โ€œcountโ€ function. No errors, just ignores itโ€ฆ?

Is that your actual expression? The parentheses are mismatched. Try this instead:

count(
  select(
    [Related Trainees][_ROWNUMBER],
    ([current status] = โ€œActive Approvedโ€)
  )
)
+ count(
  select(
    [Related Trainees][_ROWNUMBER],
    and(
      ([current status] = โ€œGraduateโ€),
      (year([graduated]) = year(now()))
    )
  )
)

-Regardless of my usage of parenthesis or matching Steveโ€™s, the expression ignores the plus sign and everything after it. It does not generate an error, it simply does not even consider it.

-I decided to create an additional virtual column just for the second expression:
count(select([Related Trainees][_ROWNUMBER], (and([current status]=โ€œGraduateโ€, year([graduated])=year(now())))))

-The first virtual column works fine (where weโ€™re just counting active trainees). The new column, with the โ€œcurrent yearโ€ grad count, does not. It generates no error, but it returns no results (always zero). The parser may be having trouble with it because this is what the parser shows, which seems awkward:
COUNT(
โ€ฆThe list of values of column โ€˜_RowNumberโ€™
โ€ฆfrom rows of table โ€˜Traineesโ€™
โ€ฆwhere this condition is true: (ALL these statements are true:
โ€ฆ1: (The value of column โ€˜Current Statusโ€™) is equal to (โ€œGraduateโ€)
โ€ฆ2: (YEAR(
โ€ฆThe value of column โ€˜Graduatedโ€™)) is equal to (YEAR(
โ€ฆNOW()))))

Please post a screenshot of the complete expression.

I actually scrapped it and retyped it and suddenly the parser โ€œlikedโ€ itโ€ฆ?

Top Labels in this Space