'Creating a column in metabase query tool depending on if another column contains unique value
I am trying to use the matabase query tool to create a new column of 1s and 0s.
example data
id value
1 10
2 0
2 15
2 10
I want to create a new column that contains a 1 if the id is unique and value > 0 and 0 otherwise. Using the query tool in Metabase I can create a new column that is 1 or 0 depending on if value > 0 using
case([value] > 0, 1, 0)
But this gives,
id value new_col
1 10 1
2 0 0
2 15 1
2 10 1
As I want to calculate sum([new_col]) later in the query this gives the wrong answer as I would get 3 instead of 2 (as only 2 unique id's have value > 0)
How can my case statement also check if the id is unique?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
