cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
dming
Advisor

Filter context in bi-directional model

Hi,

I'm facing a problem on filter context in bi-directional model. I need a bi-direction relationship because i need a count in dimension can work in other dims.

For example, from AdvantureWorkDW, i load FactInternetSales, DimDate, DimCustomer.  And create relationship between Fact & DimCustomer as bi-direction, single direction between fact & DimDate.

 

Then, i create a meausre CustomerCount:=

DISTINCTCOUNT(DimCustomer[CustomerKey]). it's working as expected when I pull CalendarYear & CustomerCount into a table, it shows different no of customer per year.
 
Now, i would like to calculate below, 
Total Customer by Geo = CALCULATE(DISTINCTCOUNT(DimCustomer[CustomerKey]), ALLEXCEPT(DimCustomer, DimCustomer[GeographyKey])), this measure needs to ignore filter context from other dim/fact so that it's real Total. Unfortunately, it's not working as expected when drag 
GeographyKey into pivot. 
 
So i tried below to overwrite filter context, but it will give grand total and ignore GeographyKey filter.
Total Customer by Geo 2 = CALCULATE(DISTINCTCOUNT(DimCustomer[CustomerKey]), ALLEXCEPT(DimCustomer, DimCustomer[GeographyKey]), ALL(FactInternetSales))
 
Any advise?
Thanks, Di
1 ACCEPTED SOLUTION

Accepted Solutions
LivioLanzo Super Contributor
Super Contributor

Re: Filter context in bi-directional model

Hi @dming

 

I would discourage the use of bi-directional relationships:

https://www.sqlbi.com/articles/bidirectional-relationships-and-ambiguity-in-dax/

 

You can use cross filter to simulate the biredictional filter temporarily

https://www.wiseowl.co.uk/blog/s2597/cross_filter.htm

 


 


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


Proud to be a Datanaut!  

View solution in original post

2 REPLIES 2
LivioLanzo Super Contributor
Super Contributor

Re: Filter context in bi-directional model

Hi @dming

 

I would discourage the use of bi-directional relationships:

https://www.sqlbi.com/articles/bidirectional-relationships-and-ambiguity-in-dax/

 

You can use cross filter to simulate the biredictional filter temporarily

https://www.wiseowl.co.uk/blog/s2597/cross_filter.htm

 


 


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


Proud to be a Datanaut!  

View solution in original post

dming
Advisor

Re: Filter context in bi-directional model

Awsome, thank you very much for such prompt response. 

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors