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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
TCavins
Helper V
Helper V

DAX: Count IDs that have a specific value in ColumnB 3 or more times.

I'm trying to create a measure that gives me the count of ID's (Column A) where column B = 'xxx' and it occurs 3 or more times. For the following table, the measure would return 2(IDs 1 and 3 have XXX 3 or more times). However, I'm struggling with the DAX for the measure. Any ideas? Assume table is named MyTable.


IDColumnB
1XXX
2ABC
1XXX
1XXX
3XXX
3XXX
3XXX

 

1 ACCEPTED SOLUTION

I was able to get it to work in two steps. Creating a table, then a measure off of that table. Still trying to figure out how to do it all in one step. Added a column in the grouping to get people by provider that have 3 or more values of XXX in the ColumnB table.

IC =
SUMMARIZE(
    FILTER(
        'Table',
        'Table'[ColumnB] = "XXX"),
        'Table'[ID],
        'Table'[ProviderName],
        "tc", COUNT('Table'[ID])
)

MEASURE4 =
CALCULATE(COUNTROWS(IC), IC[tc] >=3)

 

View solution in original post

11 REPLIES 11
v-kelly-msft
Community Support
Community Support

Hi  @TCavins ,

 

Create 2 measures as below:

Count1 =
VAR _count1 =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] = MAX ( 'Table'[ID] )
                && 'Table'[ColumnB] = MAX ( 'Table'[ColumnB] )
        )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        FILTER ( ALL ( 'Table' ), _count1 >= 3 && 'Table'[ID] = MAX ( 'Table'[ID] ) )
    )
Count =
SUMX ( VALUES ( 'Table'[ID] ), 'Table'[Count1] )

And you will see:

vkellymsft_0-1632736715534.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

smpa01
Super User
Super User

@TCavins  try this

 

 

Measure =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        GROUPBY (
            CALCULATETABLE (
                'Table',
                FILTER ( VALUES ( 'Table'[ColumnB] ), 'Table'[ColumnB] IN { "XXX" } )
            ),
            'Table'[ID],
            "X", COUNTX ( CURRENTGROUP (), [ColumnB] )
        ),
        [X] >= 3
    )
)

or 

Measure2 =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER ( 'Table', 'Table'[ColumnB] = "XXX" ),
                'Table'[ID],
                'Table'[ColumnB]
            ),
            "X", CALCULATE ( COUNT ( 'Table'[ColumnB] ) )
        ),
        [X] >= 3
    )
)

 

 

smpa01_0-1632508835874.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I was able to get it to work in two steps. Creating a table, then a measure off of that table. Still trying to figure out how to do it all in one step. Added a column in the grouping to get people by provider that have 3 or more values of XXX in the ColumnB table.

IC =
SUMMARIZE(
    FILTER(
        'Table',
        'Table'[ColumnB] = "XXX"),
        'Table'[ID],
        'Table'[ProviderName],
        "tc", COUNT('Table'[ID])
)

MEASURE4 =
CALCULATE(COUNTROWS(IC), IC[tc] >=3)

 

Hi  @TCavins ,

 

Glad to hear it.

Could you pls mark the reply as answered to close it?

If possible,would you pls also mark other correct replies as well.Thus others could also check them.

Thanks in advance.

 

Best Regards,
Kelly

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

@TCavins  well done. Make sure you understand the secrets of SUMMARIZE if you are to perform aggregation inside SUMMARIZE. 

https://www.sqlbi.com/articles/all-the-secrets-of-summarize/

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I'm not getting the correct results with either of those.

@TCavins  my solution is based on the data you gave me and as you can see the measure is performing as desired in the sample dataset you gave. Is there something you did not include?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I needed a count of IDs that have have XXX 3 or more times.

 

The measure should return 2 because there are 2 IDs that have XXX at least 3 times in ColumnB.


@TCavins  change to this

 

 

Measure2 = 
CALCULATE (
    DISTINCTCOUNT('Table'[ID]),
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER ( 'Table', 'Table'[ColumnB] = "XXX" ),
                'Table'[ID],
                'Table'[ColumnB]
            ),
            "X", CALCULATE ( COUNT ( 'Table'[ColumnB] ) )
        ),
        [X] >= 3
    )
)

 

 

smpa01_0-1632514578475.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
amitchandak
Super User
Super User

@TCavins , A new measure 

 

countx(filter(summarize(Table, Table[ID],"_1" ,Count(Table[columnb])) ,[_1] >=3) ,[ID])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Where in the measure is it checking if ColumnB = "XXX"?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors