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
Anonymous
Not applicable

Count of dimension with common attribute in other dimensions considering filter context

Hi guys, I've a doubt about the best practice in a case like the one below.

 

fabiuzz_1-1647027813722.png

 

The datamodel is obviously more complex than this, but the core question is summarized here and is about the dimensions "Customers", "Sercives" and "Practices".

 

In "Practices" there are reference to customer and services (in other terms 1 practices reference 1 customer, 1 service). Actually there are other dimension and common attributes (7-8), but here I've made a semplification with only 2.

 

I want to count "Practices" using only the common attributes present in filter context as a filter of "Practices" dimension.

 

I've found two ways to solve:

 

1. Handling all in measure

 

Practices (Filtered) = 
VAR SelectedCustomers = VALUES(Customers[K_Customer])
VAR SelectedServices = VALUES(Services[K_Service])
VAR ... = VALUES(...)

RETURN
CALCULATE(
    COUNTROWS(Practices),
    Practices[K_Customer] IN SelectedCustomers,
    Services[K_Service] IN SelectedServices,
    ...[...] IN ...
)

 

 

2. Create a Bridge/FakeFact table with every single possibile K_ related to common dimension

fabiuzz_2-1647029674309.png

and then create a simple measure with DISTINCTCOUNT (or SUMMARIZE + COUNTROWS)

Practices (Filtered) V2 = DISTINCTCOUNT(PractiesFakeFact[K_Pratice])

 

Which one you think is the best in terms of readability? The first one could have performance problem?

Other suggestion?

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Go with the first one.  Remember that filter context is a list of values.  You can simplify your measure

 

Practices (Filtered) = 
VAR SelectedCustomers = VALUES(Customers[K_Customer])
VAR SelectedServices = VALUES(Services[K_Service])
VAR ... = VALUES(...)

RETURN
CALCULATE(
    COUNTROWS(Practices),
    SelectedCustomers,
    SelectedServices,
    ...
)

View solution in original post

5 REPLIES 5
lbendlin
Super User
Super User

Go with the first one.  Remember that filter context is a list of values.  You can simplify your measure

 

Practices (Filtered) = 
VAR SelectedCustomers = VALUES(Customers[K_Customer])
VAR SelectedServices = VALUES(Services[K_Service])
VAR ... = VALUES(...)

RETURN
CALCULATE(
    COUNTROWS(Practices),
    SelectedCustomers,
    SelectedServices,
    ...
)
Anonymous
Not applicable

Thank you @lbendlin but I dont' understand how it could work with your statement... I reply here cause maybe the approach is different from the one you think is the best one.

 

Customer dimension is not related with Practices dimension and I need to filter Practices[K_Customer] with a list of values of Customer[K_Customer] coming from filter context .

 

The original statement (there was a little mistake in the text... here below the correct one):

Practices (Filtered) = 
VAR SelectedCustomers = VALUES(Customers[K_Customer])
VAR SelectedServices = VALUES(Services[K_Service])
VAR ... = VALUES(...)

RETURN
CALCULATE(
    COUNTROWS(Practices),
    Practices[K_Customer] IN SelectedCustomers,
    Practices[K_Service] IN SelectedServices,
    ...[...] IN ...
)

  

I think is different from your:

Practices (Filtered) = 
VAR SelectedCustomers = VALUES(Customers[K_Customer])
VAR SelectedServices = VALUES(Services[K_Service])
VAR ... = VALUES(...)

RETURN
CALCULATE(
    COUNTROWS(Practices),
    SelectedCustomers,
    SelectedServices,
    ...
)

 

How DAX CALCULATE could know which columns use to apply the filters in Practices dimension?

Your variables are tables. DAX knows the lineage of their columns.

 

If you want you can make the link between facts and practices bidirectional.

Anonymous
Not applicable

I can't use bidirectional relationship, the model has 3 facts and many dimension, I will broke some logic in other points. Furthermore the fact doesn't have all the istance of practices/services/customer... is a fact. In very particular situation should also be empty.

 

There's no direct relationship between Practices and Customer, your formula retruns the total rows of Practices. It will work only with bidirectional or with a countrows on the fact... but it's not the aim of the question.

Consider using TREATAS() or (shudder) LOOKUPVALUE()

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