beast mode % calculation


I wanted to calculate % of active user using the following beast mode, but soemhow it only gives 100%.  I could not figure out what went wrong. 

In this exmaple, %of active user should be  2215/(2215+3273) , but it shows 100%.


This is my beast mode: 

COUNT(DISTINCT case when `useractivity_status` = 'Active User' then `usersid` end)/COUNT(DISTINCT `usersid`)


Thank you.



Best Answer

  • ST_-Superman-_
    Accepted Answer

    You could try this:

    (COUNT(DISTINCT case when `useractivity_status` = 'Active User' then `usersid` else 'Inactive User' end)-1)/ (COUNT(DISTINCT `usersid`) over ())


  • MarkSnodgrass
    MarkSnodgrass Portland, Oregon 🔴

    I wonder if the distinct is throwing it off. Here is a beast mode that shows login failure rate that is similar to what you are trying to do. I got it from one of the cards in the DomoStats quickstart if you have that in your instance and want to compare. 

    (COUNT((CASE  WHEN (`Action` = 'FAILED_LOGIN') THEN `Action` END )) 

    You might try copying this code and swap in/out the appropriate column names and values that you are looking for and see if this works for you.

  • I'm not sure if the picture that you shared is the table you are using this metric in, but if it is then the issue is with how you have built the table card.


    You need to remove the `useractivity_status` field from the table.  As it is built now, the beastmode is being given a list of all 'Active User's first, of which 100% are active and then it is given the list of inactive users, of which 0% are active.



  • Hi, Superman, 


    I actually wanted to create a line chart to show the active user % overtime.  But I got a line at 1, so I try to use table to check the data.  


    I do need to count(distinct) because an userid is recorded  every time there is an action.  





  • Hi, Mark, it does not work for my case because I do need to count(distinct).  The userid is recorded for every action an user took. I need to remove the dublications.


  • Can you share the rest of the settings for that chart?

  • I did not set up anything in the line chart.

  • (COUNT(DISTINCT case when `useractivity_status` = 'Active User' then `usersid` else 'not active' end)-1)/COUNT(DISTINCT `usersid`)

    You could try something like this.  The issue might be that the case statement has no where to go if the status is not "Active User"

  • MarkSnodgrass
    MarkSnodgrass Portland, Oregon 🔴

    Have you tried changing your date selector grouping? If it is set to None, that could be your issue if your date field has a time stamp in it. Try setting it to group by Month and see if your calculation works properly.

  • (COUNT(DISTINCT case when `useractivity_status` = 'Active User' then `usersid` else 'Inactive User' end)-1)/COUNT(DISTINCT `usersid`)


    I changed the beast mdoe to this and also grouped date to month, but got the same chart - still 100% active users.  


    I thought this is an easy chart to draw :( 



  • Thanks for the idea -- I grouped date by month, but nothing changed :(

  • I think this has more to do with the dataset. My guess is that if you look at the events that 'occurredat' the time frame you are graphing, you will find that the users that performed actions in that time are all still active users. You need to identify a way to identify the users that don't have activities

  • Hi


    If you were to split your beast mode would you get

    Active Users:2215

    Users: 2215



    Active Users:3273

    Users: 3273


    The answer might give you a clue. You might find the inactive users due nto come up at all in the activity log during the peroid or something like that.

  • Superman, 


    You are genius  -- It works now. 


    But I wanted to point out that 


    COUNT(DISTINCT case when `useractivity_status` = 'Active User' then `usersid` else 'Inactive User' end) -1 reduced the active number by 1.  For example, I suppose to have 127 active users, using -1, I only got 126.  





  • Good point.  It should really be:

    (COUNT(DISTINCT case when `useractivity_status` = 'Active User' then `usersid` end))/ (COUNT(DISTINCT `usersid`) over ())
  • Hi, Superman,


    can you also help me with this -- I need to report on Active user/Inactive user by group.  


    I am able to report on overall active user /inactive user, but as you have figured out in the previous post, the occurred date is only associated with Active user, meaning when there is an action, there is a date recorded.  Thus the inactive users are not associated with date.


    theoretically, the inactive user = total user - active user for each group, is it possible to somehow to link the inactive users?


    Thank you very much.




This discussion has been closed.