cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

COUNTIF Question

HI all,

I have a data set with columns like this:

 

Donor ID  Staff Donor

01             TRUE

02             TRUE

02             TRUE

03             FALSE

04             FALSE

05             TRUE

06             TRUE

07             FALSE

07             FALSE

 

I want to calcuate the percentage of staff donors to all donors. My thought is first to calcuate the number of staff donor first by distinct count donor ID if staff donor = TRUE. I created a new measure like this:

 

Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor] = "TRUE")
 
When I tried to visualise the new measure in a card this to see if my DAX is correct it shows an error message, even though the DAX itself has no red flag...
 
Also, this method probably is not the quickly way to get percentage? I would love to know if there is a better solution.
 
Many thanks for your help.
 
Keep well and stay safe!
 
Diana
 

 

2 ACCEPTED SOLUTIONS
Super User IV
Super User IV

The error could be that it is a boolean column and you are comparing it to text? Not sure, can you click the More details and post what it says? Also is Lookup ID correct or Donor ID? Whatever your final formula, you can get percentage by right clicking, Show as and then Percent of Total.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Super User II
Super User II

@DianaT If it's the boolean that's being problematic, you could try these:

 

Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor] = true())
 
Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor] =1)
 
Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor])
 
Also, is [Lookup ID] the same as your [Donor ID]?

Respectfully,
DataZoe

See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

5 REPLIES 5
Super User II
Super User II

@DianaT If it's the boolean that's being problematic, you could try these:

 

Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor] = true())
 
Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor] =1)
 
Number of staff donors = CALCULATE(DISTINCTCOUNT('SOS Appeal'[Lookup ID]),'SOS Appeal'[Staff donor])
 
Also, is [Lookup ID] the same as your [Donor ID]?

Respectfully,
DataZoe

See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

Hi,

 

Thank you so much for your help. I changed the filter to [Staff donor] = true() and it is working like a dream now!

 

🙂 Diana.

Super User IV
Super User IV

The error could be that it is a boolean column and you are comparing it to text? Not sure, can you click the More details and post what it says? Also is Lookup ID correct or Donor ID? Whatever your final formula, you can get percentage by right clicking, Show as and then Percent of Total.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Hi Greg,

 

Thank you so much for your help. It is a indeed a problem with the boolean column. All sorted now!

 

🙂 Diana

Great! 🙂

---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors