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
olimilo
Continued Contributor
Continued Contributor

DISTINCTCOUNT of unrelated table

I have 2 unrelated tables, Audits and Improper Offer. Trying to get the DISTINCTCOUNT of ImproperOffer[AuditID] based on the Audits[ID] but the formula below results in an error:

 

Column = 
    CALCULATE(
        DISTINCTCOUNT('Improper Offer'[AuditID]),
        'Audits'[ID] = 'Improper Offer'[AuditID]
    )

 

While the formula below results in an incorrect value (which is the total items from the unrelated table):

Column = 
    CALCULATE(
        DISTINCTCOUNT('Improper Offer'[AuditID]),
        'Audits'[ID] = MIN('Improper Offer'[AuditID])
    )

 
Is it possible to do this as a calculated column?

1 ACCEPTED SOLUTION
Shahid12523
Community Champion
Community Champion

For a calculated column with unrelated tables, use FILTER + EARLIER:

 

ImproperOfferDistinctCount =
CALCULATE(
DISTINCTCOUNT('Improper Offer'[AuditID]),
FILTER(
'Improper Offer',
'Improper Offer'[AuditID] = EARLIER('Audits'[ID])
)
)

Shahed Shaikh

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @olimilo 

 

Try this calc column

COUNTROWS (
    // FILTER creates a table of unique AuditIDs from Improper Offer
    FILTER (
        VALUES ( 'Improper Offer'[AuditID] ),

        // Keep only the rows where the AuditID from Improper Offer
        // matches the current row context in Audits[ID]
        'Audits'[ID] = EARLIER ( 'Improper Offer'[AuditID] )
    )
    // COUNTROWS then counts how many matching rows remain
)




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Shahid12523
Community Champion
Community Champion

For a calculated column with unrelated tables, use FILTER + EARLIER:

 

ImproperOfferDistinctCount =
CALCULATE(
DISTINCTCOUNT('Improper Offer'[AuditID]),
FILTER(
'Improper Offer',
'Improper Offer'[AuditID] = EARLIER('Audits'[ID])
)
)

Shahed Shaikh
rohit1991
Super User
Super User

Hi @olimilo 

I created these two sample tables. You can replace them with your own table names:

1. Audits Table

image.png 

 

 

 

 

 

 

2. Improper Offer Table

image.png 

 

 

 

 

 

 

 

Create Measure: Because the tables are unrelated, we need to use TREATAS.

ImproperOffer DistinctCount = 
VAR auditsInScope = VALUES ( Audits[ID] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'Improper Offer'[AuditID] ),
        TREATAS ( auditsInScope, 'Improper Offer'[AuditID] )
    )

 

Outcome : 

image.png

 

 

 

 

 

 

 

 

 


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
ryan_mayu
Super User
Super User

@olimilo 

you can try this

 

ImproperOfferCount =
CALCULATE(
DISTINCTCOUNT('Improper Offer'[AuditID]),
FILTER(
'Improper Offer',
'Improper Offer'[AuditID] = 'Audits'[ID]
)
)

 

if this does not work,pls provide some sample data and expected output.





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

Proud to be a Super User!




Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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