I am trying to visualize a "rate" metric, aka what percent of a certain column contains a value. Each cell in this column either contains a numerical value or is empty. I'm struggling with how to get Metabase to treat the empty cells as 0s. If I use something like Share in Summarize, the empty cells are just ignored. (e.g. Share([column] > 0) just returns "1")
I saw in another forum post that a value of 0 could be assigned to empty cells by creating a custom column =coalesce([column], 0). I did this, and it worked. However, using that custom column further hasn't worked.
E.g., I thought to create a second custom column that assigns a value of 0 for empty cells and a value of 1 for non-empty cells, then summarize by averaging that custom column:
Hi @Kierpatel
Why can't you use Average(coalesce([column], 0)) directly as a Custom Expression in summarize?
Perhaps it would be easier if you wrote the SQL that you want to have, then it's easier to understand and provide an example in the GUI.
I'm not incredibly practiced with SQL unfortunately, much less in relation to Metabase, or else this would've been a lot easier for me to reverse engineer.
I'll try to be clearer in what I'm trying to do. Let's say my column looks like this:
There's 5 rows in this column; 3 of the rows have a numerical value and 2 of the rows are empty. Aka, 3/5 or 0.6 of the column is non-empty. I'm trying to get that kind of rate.
@Kierpatel This works fine for me on the latest release querying Postgres.
You need to include a screenshot of the error, so it is possible to have context.
I've figured out that the error message was resulting from trying to apply the "isnull" expression to a column with empty values, rather than null values.
However, if I take the steps I listed in my first post, e.g., setting empty values in the column to 0, I'm still not able to get the result I want.
Thanks for your involved help. I'm going to walk through exactly what I need conceptually, and hopefully that'll allow you to identify how I can achieve this in Metabase.
I have a column with some rows containing numerical values, and some columns that are empty (as in, not "0," but containing no value). I want to create a visualization metric of how many rows in that column contain something, aka "the number of rows containing something" divided by "the number of rows in total."
Thanks again for all your help. Let me know if there's anything else I can provide.
@Kierpatel In database language an empty cell is called null. It is very important to understand the distinction between empty and null, especially when you are dealing with string columns.
That is exactly what my table looks like! And exactly what I am trying to calculate. However, I tried your custom expression, and it's giving me a result of 0 just like every other method I've tried
@Kierpatel Then it's likely because your columns are not null.
I don't think I can help you further. Try using SQL instead or getting help from your database admin.
So I'm not sure if this is something you could help me with; but I went in through the SQL editor to filter out rows in the column that were null and that did filter out the rows that appeared empty. Vice versa when I filtered for IS NOT NULL. If these empty rows are actually null , is there any reason that they wouldn't be counted by the custom expression CountIf(isnull([col1]) ?
@Kierpatel No, it should work, but you are not providing screenshots or SQL queries, so it's not possible to know anything. If it works with SQL, then use that.