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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
mellomoon3
Regular Visitor

Count distinct ID if group by ID_2 greater than 1

I have the following table:

ID     ID_2     Date

1      234       Jan '24

1      829       Feb '24

2      981       Jan '24

2      146       Mar '24

2      286       Nov '24

3      321       May '24

3      743       Feb '24

 

I want to create a measure in Power BI so that I am able to count distinct ID if there are more than 1 ID_2. For example, from Jan '24 to Dec '24, there are 3 IDs that have more than 1 ID_2 and from Jan '24 to Mar '24, there are 2 IDs that have more than 1 ID_2.

 

I tried creating two measures and it gave me the desired output, but it does not take into account for the Date filter which I want it to be able to.

Measure 1 = CALCULATE(DISTINCTCOUNT(ID_2), ALLEXCEPT(ID))

Measure 2 = CALCULATE(DISTINCTCOUNT(ID), FILTER([Measure 1] > 1))

 

Appreciate any guidance. Thanks in advance!

1 ACCEPTED SOLUTION
miTutorials
Super User
Super User

Try the below measure and make sure your the data type of your Date column is a Date and not Text.

 

DistinctID_Count = 
VAR IDsWithMultipleID2 =
    ADDCOLUMNS(
        VALUES('Table'[ID]),
        "@ID2Count", 
            CALCULATE(DISTINCTCOUNT('Table'[ID_2]))
    )

RETURN
CALCULATE(
    DISTINCTCOUNT('Table'[ID]),
    FILTER(IDsWithMultipleID2, [@ID2Count] > 1)
)

 

Sample pbix attached..

View solution in original post

2 REPLIES 2
miTutorials
Super User
Super User

Try the below measure and make sure your the data type of your Date column is a Date and not Text.

 

DistinctID_Count = 
VAR IDsWithMultipleID2 =
    ADDCOLUMNS(
        VALUES('Table'[ID]),
        "@ID2Count", 
            CALCULATE(DISTINCTCOUNT('Table'[ID_2]))
    )

RETURN
CALCULATE(
    DISTINCTCOUNT('Table'[ID]),
    FILTER(IDsWithMultipleID2, [@ID2Count] > 1)
)

 

Sample pbix attached..

This works, thank you for your help!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.