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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
unnijoy
Post Partisan
Post Partisan

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:

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@unnijoy Seems like:

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

@ 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!:
The Definitive Guide to Power Query (M)

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:

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.