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
Anonymous
Not applicable

Need help writing a DAX to count distinct values with multiple filters

I have this table

 

thorton_0-1652713895001.png

I need to write a DAX that finds Admit Status of 'N' or 'E'

Then it need to modify FAYEAR to get the left two characters and change that to 202110

So it would be "20" & Left(FAYEAR,2) & "10"  newvalue

 

So then it would (Admit Status of 'N' or 'E') and "20" & Left(FAYEAR,2) & "10"  newvalue

 

I wrote this but I am doing something wrong.

THANK YOU!

 

H21 = CALCULATE(DISTINCTCOUNT('Main'[ID]), FILTER('Main',Main[ADMITSTATUS] = "N" || 'Main'[ADMITSTATUS] = "E" && Main[ADMITTERM] = "20" & LEFT(CALCULATE(DISTINCT(H2A_FR[FAYEAR])), 2)& "10"))
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

In the formula, "ADMITTERM" uses the same name as the Main[ADMITTERM] field, you need to replace it, such as "ADMITTERM 2".

 

vkkfmsft_0-1653010852396.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.


Best Regards,
Winniz

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@Anonymous Perhaps:

H21 = 
  COUNTROWS(
    DISTINCT(
      ADDCOLUMNS(
       FILTER('Main',Main[ADMITSTATUS] = "N" || 'Main'[ADMITSTATUS] = "E"),
        "ADMITTERM", "20" & LEFT(CALCULATE(DISTINCT(H2A_FR[FAYEAR])), 2)& "10"
      )
    )
  )

@ 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...
Anonymous
Not applicable

Error that it cannot add columns because already exists.

 

thorton_0-1652717525946.png

 

Hi @Anonymous ,

 

In the formula, "ADMITTERM" uses the same name as the Main[ADMITTERM] field, you need to replace it, such as "ADMITTERM 2".

 

vkkfmsft_0-1653010852396.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.


Best Regards,
Winniz

Anonymous
Not applicable

Thank you!

Anonymous
Not applicable

I think I figured it out, 

H21 = CALCULATE(DISTINCTCOUNT('Main'[ID]), FILTER('Main',Main[ADMITSTATUS] in {"N","E"} && Main[ADMITTERM] = "20" & LEFT(CALCULATE(DISTINCT(H2A_FR[FAYEAR])), 2)& "10"))
 
But my question still remains what is I had to combine filters
 
(Filter A = "b" or Filter B = "b") and Filter C = "x"
 
How would you write the above filter in DAX?
 

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.

Top Solution Authors