Forum Discussion
Sum based on filter
I have a survay data. I need to find the positive %. So in the Positive column we will be counting the total 1. and that count should be divided by total distinct dount of ID. and for 2021 i have to use the FILTER
now the formula is Positive%= calculate(count (Positive)/distinct count(ID),filter (Year =2021).
Now the ussue is that if ant of the employee if his positive is coming as 0 then their ID is not counting. I need the distinct count of all ID irresoective of Positive 1 0r 0. how can i do that. below is the sample.
| ID | Name | Attri | Positive | Negative | year |
| 12 | James | Helath | 1 | 1 | 2021 |
| 12 | James | Pay | 0 | 2 | 2021 |
| 12 | James | Transport | 1 | 1 | 2021 |
| 13 | Rex | Helath | 0 | 2 | 2021 |
| 13 | Rex | Pay | 1 | 1 | 2021 |
| 13 | Rex | Transport | 0 | 2 | 2021 |
| 14 | Sam | Helath | 0 | 1 | 2021 |
| 14 | Sam | Pay | 0 | 2 | 2021 |
| 14 | Sam | Transport | 0 | 3 | 2021 |
| 12 | James | Helath | 0 | 1 | 2020 |
| 12 | James | Pay | 0 | 2 | 2020 |
| 12 | James | Transport | 0 | 1 | 2020 |
| 13 | Rex | Helath | 0 | 2 | 2020 |
| 13 | Rex | Pay | 1 | 1 | 2020 |
| 13 | Rex | Transport | 0 | 2 | 2020 |
| 14 | Sam | Helath | 0 | 1 | 2020 |
| 14 | Sam | Pay | 0 | 2 | 2020 |
| 14 | Sam | Transport | 0 | 3 | 2020 |
Measure = VAR __Table = FILTER('Table',[year]=2021) VAR __Denominator = COUNTROWS(DISTINCT(SELECTCOLUMNS(__Table,"ID",[ID]))) VAR __Numerator = COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER(__Table,[Positive]=1),"ID",[ID]))) RETURN DIVIDE(__Numerator,__Denominator,0)unnijoy Try:
4 Replies
- Greg_DecklerCommunity Champion
unnijoy Seems like:
COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('Table',[year]=2021),"ID",[ID])))- unnijoyPost Prodigy
hi Greg_Deckler ,
thanks for the qucik reply. can i need the filter in over all. Like = count (positive)/dist(ID),filter 2021. How can i achive this
- unnijoyPost Prodigy
hi Greg_Deckler , as per the above table the expected result is as follows.
positive = 2
total dist count of id = 3. as u can see that the for the third guy positive is coming as 0 but still we need to count him.
Positive % = 2/3= 67 %