Getting no data in calculation in my beast mode.
I am trying to calculate the %age change in headcount with respect to the previous vs this month but by using below beast mode I am not getting any results in the trend line. It gives 0 as a value.
( (SUM(CASE WHEN MONTH(Date
) = MONTH(CURDATE()) THEN Headcount
END) / COUNT(DISTINCT(CASE WHEN MONTH(Date
) = MONTH(CURDATE()) THEN Date
END))
) - (
SUM(CASE WHEN MONTH(Date
) = MONTH(CURDATE())-1 THEN Headcount
END) / COUNT(DISTINCT(CASE WHEN MONTH(Date
) = MONTH(CURDATE())-1 THEN Date
END))) )
/ NULLIF((SUM(CASE WHEN MONTH(Date
) = MONTH(CURDATE())-1 THEN Headcount
END) / COUNT(DISTINCT(CASE WHEN MONTH(Date
) = MONTH(CURDATE())-1 THEN Date
END))))
Best Answer
-
I would not use the -1 as that is going to just change it from July 31st to July 30th and is not what you want. I would use this to get the previous month:
LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 month))
Also, in your NULLIF function, your 2nd parameter is just inserting a blank. That will be problematic as a denominator. I would rethink what you want your denominator to be for this equation.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1
Answers
-
You have a lot of parantheses going on so it is a little hard to tell, but I don't think you have a second argument for your NULLIF function.
Additionally, I would recommend evaluating months by using the LAST_DAY() function instead of just the MONTH function. Depending on the date range of your data, you can be looking at multiple years when you don't intend to. Also, for January, MONTH(date)-1 will result in 0, which will be a problem. Doing the following for each, should work better:
LAST_DAY(date)
LAST_DAY(CURDATE())
DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 month)
Substituting these into the equivalent spots above should help with better evaluations.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
@MichelleH My data has number of employee data which we are calling headcount. It is mentioned as days. So we have number of employees day by day. Our date coulmn has mmddyyyy.
I tried to calculate total number of headcount for each month. If we consider we are in July so its our current month and the previous month will be June.
I am trying to calculate the percentage change in number of employees of this month and last month.
Example: if this month has 110 employees and last month had 100. So our result will be 10%.
In my chart - its a grouped bar and line chart. In grouped bar, i have headcount for current month and previous month. I want to show the percentage value on the trend line.with this above formula in question i was trying to calculate the percentage. But i am getting 0 as a value in resulte of the formula.
0 -
@MarkSnodgrass after fixing with the recommended. I am still not able to get results.
I verified the parenthesis they are correct.
Here is what I updated:( (SUM(CASE WHEN LAST_DAY(
Date
) = LAST_DAY(CURDATE()) THENHeadcount
END) / COUNT(DISTINCT(CASE WHEN LAST_DAY(Date
) = LAST_DAY(CURDATE()) THENDate
END))
) - (
SUM(CASE WHEN Last_day(Date
) = LAST_DAY(CURDATE())-1 THENHeadcount
END) / COUNT(DISTINCT(CASE WHEN LAST_DAY(Date
) = LAST_DAY(CURDATE())-1 THENDate
END))) )/ NULLIF((SUM(CASE WHEN LAST_DAY(
Date
) = LAST_DAY(CURDATE())-1 THENHeadcount
END) / COUNT(DISTINCT(CASE WHEN LAST_DAY(Date
) = LAST_DAY(CURDATE())-1 THENDate
END))),' ')0 -
I would not use the -1 as that is going to just change it from July 31st to July 30th and is not what you want. I would use this to get the previous month:
LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 month))
Also, in your NULLIF function, your 2nd parameter is just inserting a blank. That will be problematic as a denominator. I would rethink what you want your denominator to be for this equation.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 298 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 54 App Studio
- 40 Variables
- 680 Automate
- 175 Apps
- 451 APIs & Domo Developer
- 46 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 33 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive