Count distinct values using Month, Year from another sheet
I need to count the unique values from another sheet using MONTH and YEAR. Here is the formula I have:
=COUNTIFS(DISTINCT(COLLECT({[2021] Case Cleaning Schedule Range 1}, {[2021] Case Cleaning Schedule Range 2}, MONTH(@cell) = 1
, {[2021] Case Cleaning Schedule Range 2}, YEAR(@cell) = 2022)))
A few details:
- I am referencing another sheet [2021] Case Cleaning Schedule
- Range 1 = Zone: column
- Range 2 = Service Date: column
- I want to count the unique values in the Zone: column
Thanks for the help in advance.
Best Answer
-
Hey @Justin Mauzy,
For whatever reason COLLECT with MONTH(@cell) and YEAR(@cell) has some bugs so instead I used VALUE combined with LEFT and RIGHT.
=COUNT(DISTINCT(COLLECT(Zone:Zone, [Service Date]:[Service Date], AND(VALUE(LEFT(@cell, 2)) = 1, VALUE(RIGHT(@cell, 2)) = 22))))
If it wasn't buggy something like this would work but for whatever reason it doesn't.
=COUNT(DISTINCT(COLLECT(Zone:Zone, [Service Date]:[Service Date], AND(MONTH(@cell) = 1, YEAR(@cell) = 2022))))
Another option is to add two columns and make them MONTH([Service Date]@row) and YEAR([Service Date]@row) as column formulas and then something like this works.
=COUNT(DISTINCT(COLLECT(Zone:Zone, Month:Month, @cell = 1, Year:Year, @cell = 2022)))
Answers
-
Hey @Justin Mauzy,
For whatever reason COLLECT with MONTH(@cell) and YEAR(@cell) has some bugs so instead I used VALUE combined with LEFT and RIGHT.
=COUNT(DISTINCT(COLLECT(Zone:Zone, [Service Date]:[Service Date], AND(VALUE(LEFT(@cell, 2)) = 1, VALUE(RIGHT(@cell, 2)) = 22))))
If it wasn't buggy something like this would work but for whatever reason it doesn't.
=COUNT(DISTINCT(COLLECT(Zone:Zone, [Service Date]:[Service Date], AND(MONTH(@cell) = 1, YEAR(@cell) = 2022))))
Another option is to add two columns and make them MONTH([Service Date]@row) and YEAR([Service Date]@row) as column formulas and then something like this works.
=COUNT(DISTINCT(COLLECT(Zone:Zone, Month:Month, @cell = 1, Year:Year, @cell = 2022)))
-
That work perfectly! Thank you for the help.
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 65.2K Get Help
- 445 Global Discussions
- 143 Industry Talk
- 476 Announcements
- 5K Ideas & Feature Requests
- 84 Brandfolder
- 150 Just for fun
- 71 Community Job Board
- 488 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 301 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!