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.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
- 755 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 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