AND's & OR's - Nested in an IF

Hey all,

I always have trouble with this and don’t know why!

Basically, I want to COUNTIF a DATE has a Month = January and a Year = 2022.

Example in the screenshot.

Screen Shot 2022-01-18 at 8.02.45 am

Hey @Danny_Pettiona !

Unfortunately you committed 3 big Coda worst practices.

But FORTUNATELY you made them all at once, will probably never make them again, and will unlock some serious new possibilities in you docs. It’s gonna be great

Here’s some general rules to live by:

  1. User filter().count() in place of countIf(). countIf() is not optimized in terms of performance/speed
  2. Never use and() Just type the word “and” in between your conditions
  3. Always compare like data types (your first argument tried to compare a single monthName to a list of names which will always be false)

So following those rules, your formula should look more like
Table.filter( date.monthName() = monthText and date.year() = yearText).count()

Or alternatively, if you do want to identify if a single value is in a list of values write it like:
Table.filter (date.monthName().in(monthText) and date.year().in(yearText))

7 Likes

Amazing thank you so much Scott! So detailed. I really appreciate it!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.