Forum Discussion
Anonymous
4 years agoNot applicable
DAX - IF, AND & OR
Hello -
I'm trying to write a DAX formula but seem to be falling short, not sure if this can be achieved by 'adding a new column' within BI:
Example Question:
Within the UK, we have X amount of employees who are black or arabic and female - (i'm trying to find the number X).
Example Sample Data:
Current DAX formula:
= IF(OR((AND(Sheet1[Country]="UK",Sheet1[Gender]="Female"),(AND(Sheet1[Ethnicity]="Black",(Sheet1[Ethnicity]="Arabic")), "Yes", "No")))
Thank you in advance!
Hi Anonymous
Try this oneColumn = SWITCH(TRUE(),'Table'[Country] = "UK" && 'Table'[Gender] = "Female" && 'Table'[Ethnicity]="Black" || 'Table'[Ethnicity]="Arabic", "Yes","No")Then you can countrows
= Calculate(Count('Table'[Country]),'Table'[Column] = "Yes")If you have any question, please let me know.
If solve your requirement, please mark this answer as SOLUTION
If this comment helps you, please LIKE this comment/KudosYou could do it with a calculated column but I would suggest a measure like:
# Needed = CALCULATE ( COUNTROWS ( Sheet1 ), Sheet1[Ethnicity] IN { "Black", "Arabic" }, Sheet1[Gender] = "Female" )
4 Replies
- bcdobbs
Community Champion
You could do it with a calculated column but I would suggest a measure like:
# Needed = CALCULATE ( COUNTROWS ( Sheet1 ), Sheet1[Ethnicity] IN { "Black", "Arabic" }, Sheet1[Gender] = "Female" )- AnonymousNot applicable
Thanks Ben for the input, this also worked!
- PijushRoy
Community Champion
Hi Anonymous
Try this oneColumn = SWITCH(TRUE(),'Table'[Country] = "UK" && 'Table'[Gender] = "Female" && 'Table'[Ethnicity]="Black" || 'Table'[Ethnicity]="Arabic", "Yes","No")Then you can countrows
= Calculate(Count('Table'[Country]),'Table'[Column] = "Yes")If you have any question, please let me know.
If solve your requirement, please mark this answer as SOLUTION
If this comment helps you, please LIKE this comment/Kudos- AnonymousNot applicable
Thank you this worked!