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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Rdarshana
Helper II
Helper II

Formula Explanation

Hi,
Can someone explain to me what this formula does - 

ID Count = COUNTROWS(DISTINCT(SELECTCOLUMNS('Fact 1', "ID Column", RELATED('Dim 2 '[ID Column]))))

From what I understand, we are picking distinct values of the ID attribute from Dim 2 table, but only those relevant to having data in the fact 1 table). Is this correct?
 
Rdarshana_0-1722027239232.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Rdarshana ,

I created a sample pbix file(see the attachment), you can find the details in it. And for below formula, it will return the count of ID in the table 'Fact 1' which ID also in the dimenison table 'Dim 2'. However, it will also include the IDs in 'Fact 1' table which not exist in the table 'Dim 2' as blank values. All these blank values count as 1. Please check the below screenshot:

ID Count = COUNTROWS(DISTINCT(SELECTCOLUMNS('Fact 1', "ID Column", RELATED('Dim 2 '[ID Column]))))

vyiruanmsft_0-1722240843479.png

So you can update the forumula as below to get the correct count of ids.

ID Count_new =
COUNTROWS (
    FILTER (
        DISTINCT (
            SELECTCOLUMNS ( 'Fact 1', "ID Column", RELATED ( 'Dim 2'[Dim ID] ) )
        ),
        [ID Column] <> BLANK ()
    )
)

vyiruanmsft_1-1722241005100.png

Best Regards

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Rdarshana ,

I created a sample pbix file(see the attachment), you can find the details in it. And for below formula, it will return the count of ID in the table 'Fact 1' which ID also in the dimenison table 'Dim 2'. However, it will also include the IDs in 'Fact 1' table which not exist in the table 'Dim 2' as blank values. All these blank values count as 1. Please check the below screenshot:

ID Count = COUNTROWS(DISTINCT(SELECTCOLUMNS('Fact 1', "ID Column", RELATED('Dim 2 '[ID Column]))))

vyiruanmsft_0-1722240843479.png

So you can update the forumula as below to get the correct count of ids.

ID Count_new =
COUNTROWS (
    FILTER (
        DISTINCT (
            SELECTCOLUMNS ( 'Fact 1', "ID Column", RELATED ( 'Dim 2'[Dim ID] ) )
        ),
        [ID Column] <> BLANK ()
    )
)

vyiruanmsft_1-1722241005100.png

Best Regards

This was indeed very helpful. 

Rdarshana
Helper II
Helper II

Thanks Matt.
The Dim ID in this screenshot above is not the primary key, but another attribute (ID). 
I will need to test the other calcs to see if that works.

if it's not the primary key, just insert the VALUES function inside the countrows function

COUNTROWS(VALUES(table[column]))



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.
MattAllington
Community Champion
Community Champion

That's what it looks like to me, but it also looks overly complex. Assuming Dim ID in dim 2 is the primary key, this should work. 

 

ID Count = calculate(countrows('Dim 2 '),'Fact 1')

Or this next version is a bit easier to understand 

Calculate(countrows('Dim 2'),crossfilter(fact1[key],DIM2[key],BOTH))

 

They both do the same thing; force the fact table to filter the Dim table based on the existence of matching data in the fact table. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.