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.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 56 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive