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
jacob2102
Helper II
Helper II

CountX or other DAX expression

Hi,

 

I have a data table with different publications and the participating groups in each publication.

PublicationGroup
P1a
P1b
P1c
P2a
P2c
P3b
P4a
P4b
P4c
P4d
P5d

 

If I want to count the number of publications that has 3 or more participating groups, what is the correct DAX expression?

At this moment, I have tried this expression "countx(filter(table,count(table[group])>3),table[publication])", but the resoult is not correct, the resoult should be 2 not 11.

 

How can I solve it? What is the correct DAX expression?

 

Thanks,

Jacob

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

@jacob2102 

this code could be work

PublicationCount:=COUNTROWS(FILTER(ALL(Table1[Publication]),CALCULATE(DISTINCTCOUNT(Table1[Group]),ALLEXCEPT(Table1,Table1[Publication]))>2))

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

@jacob2102 

this code could be work

PublicationCount:=COUNTROWS(FILTER(ALL(Table1[Publication]),CALCULATE(DISTINCTCOUNT(Table1[Group]),ALLEXCEPT(Table1,Table1[Publication]))>2))
CNENFRNL
Community Champion
Community Champion

Hi, @jacob2102 , you might want to try this measure without COUNTX but with COUNTDISTINCT instead,

Measure =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Publication] ),
    FILTER (
        ALL ( 'Table'[Publication] ),
        CALCULATE ( DISTINCTCOUNT ( 'Table'[Group] ) >= 3 )
    )
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi,

 

Thanks for your answer, but with this measere I get a blank result.

Maybe I can use another measure?

 

Thanks.

Jacob

camargos88
Community Champion
Community Champion

@jacob2102 ,

 

Try this measure:

 

_Count = COUNTX(FILTER(SUMMARIZE('Table', 'Table'[Publication], "Count", DISTINCTCOUNT('Table'[Group])), [Count] >= 3), [Count])

 

Or this one:

_Count = COUNTX(FILTER(ADDCOLUMNS(VALUES('Table'[Publication]), "Count", CALCULATE(DISTINCTCOUNT('Table'[Group]))), [Count] >= 3), [Count])

 



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

Proud to be a Super User!



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