Count Number of Log Ins this Year (2019)
I would like to create an insight card that divides the number of Last Logins in 2019 (125) against my total users (214) to show total percentage of users this year (58%). I am attempting to show this through a chart type of Progress Bar, Filled or Compartive Gauge (any suggestions appreciated).
However before I can create this, I need to use Beast Mode to adjust the Last Login column which is a date field that goes back to 2016. I need a formula that can count the Last Login dates that have a year of 2019.
I have tried in Beast Mode both a statement and a case, and neither is working.
Statement
COUNT(`Last Login`, YEAR(2019))
Case Statement:
(CASE when `Last Login`>= YEAR(2019) then COUNT(`Last Login`) end)
Any ideas how I can get it to count the 2019 dates? Thanks.
Best Answer
-
Hi, @SusieQ,
The case statement approach makes sense to me. That said, let me recommend a couple of changes.
First, the case statement operates at the row level. What you want to do is determine which rows pertain to 2019, and then count those. Therefore, you want the count() outside the case. Second, the year() function operates by returing the year portion of an inputted date. Making adjustments for those two things, try something like this:
COUNT(CASE WHEN YEAR(`Last Login`) = 2019 THEN `Last Login` END)
I hope that works for you.
You could also make the year logic dynamic such that it always returns the last login for the current year. That way, you wouldn't need to change your logic when year 2020 rolls around. If that is of interest, check out the current_date() function.
Best,
Dan
0
Answers
-
Hi, @SusieQ,
The case statement approach makes sense to me. That said, let me recommend a couple of changes.
First, the case statement operates at the row level. What you want to do is determine which rows pertain to 2019, and then count those. Therefore, you want the count() outside the case. Second, the year() function operates by returing the year portion of an inputted date. Making adjustments for those two things, try something like this:
COUNT(CASE WHEN YEAR(`Last Login`) = 2019 THEN `Last Login` END)
I hope that works for you.
You could also make the year logic dynamic such that it always returns the last login for the current year. That way, you wouldn't need to change your logic when year 2020 rolls around. If that is of interest, check out the current_date() function.
Best,
Dan
0 -
This worked! Brilliant. Thank you!
Also, I took your suggestion and used the current date. For anyone who is reading this post, the solution for me was:
COUNT(case when YEAR(`Last Login`) = year(CURRENT_DATE()) then `Last Login` end)
I used the Progress Bar chart type and got the results needed.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive