Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
unnijoy
Post Prodigy
Post Prodigy

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.

IDNameAttriPositiveNegativeyear
12JamesHelath112021
12JamesPay022021
12JamesTransport112021
13RexHelath022021
13RexPay112021
13RexTransport022021
14SamHelath012021
14SamPay022021
14SamTransport032021
12JamesHelath012020
12JamesPay022020
12JamesTransport012020
13RexHelath022020
13RexPay112020
13RexTransport022020
14SamHelath012020
14SamPay022020
14SamTransport032020

 

 

1 ACCEPTED SOLUTION

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:

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@unnijoy Seems like:

COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('Table',[year]=2021),"ID",[ID])))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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

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 %

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:

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.