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

  • MarkSnodgrass
    edited July 2023 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 <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.

Answers

  • @MayaU_01 Can you please share some more information about your data and what the beast mode calculation represents?

  • 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 <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.
  • MayaU_01
    MayaU_01 Member
    edited July 2023

    @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.

  • @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()) THEN Headcount END) / COUNT(DISTINCT(CASE WHEN LAST_DAY(Date) = LAST_DAY(CURDATE()) THEN Date END))
    ) - (
    SUM(CASE WHEN Last_day(Date) = LAST_DAY(CURDATE())-1 THEN Headcount END) / COUNT(DISTINCT(CASE WHEN LAST_DAY(Date) = LAST_DAY(CURDATE())-1 THEN Date END))) )

    / NULLIF((SUM(CASE WHEN LAST_DAY(Date) = LAST_DAY(CURDATE())-1 THEN Headcount END) / COUNT(DISTINCT(CASE WHEN LAST_DAY(Date) = LAST_DAY(CURDATE())-1 THEN Date END))),' ')

  • MarkSnodgrass
    edited July 2023 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 <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.