Forum Discussion
How to filter from Many table to One table in DAX?
Dear community,
I have two simple one-to-many tables.
Table "One"
VersionID
1
2
Table "Many"
VersionID
1
2
2
3
3
3
I can easily create new filtered Table for Many, based on One. Below is the example, where I filter ID = 2
Table1 = FILTER(Many, RELATED(One[One.VersionID])=2)
However, it is very complicated to do the reverse (filter from Many to One) in DAX...
I can see, that filtering works fine, using filters in Report view - i.e. One table is being filtered by ID in Many table. It works absolutely fine! (relationship is one to many, cross-filtering is enabled, of course).
When I try to use Related - it obviously does not work (DAX Related works only from One to Many). I tried to apply RELATEDTABLE, but it seems it works well only for aggregations, and I cannot wrap my head around on how to use for filtering...
I saw several videos by Curbal and Rob Kerr on the topic - still do not understand how to crack it.
Filter is working in Report GUI !
Hi vyacheslavg,
Try this formula please:
Table = FILTER ( NATURALINNERJOIN ( 'Orders', Products ), [City] = "Paris" && [ID 1] = 3 )Best Regards!
Dale
7 Replies
- AnonymousNot applicable
Hi,
There is a dax to filter from many side to one side - Crossfilter. just type that and use the relationship "both" in the syntax. This should help.
Thanks,
Rahul.
- BILASolutionSolution Specialist
- vyacheslavgHelper II
thanks. As I said, filtering from many to one is working in Report view.
I'm pretty much sure, that Power BI uses some aggregation in Many behind the scenes.
I just want to replicate this behaviour in DAX, so I will be able to produce tables, based on table "One", with filter applied on some columns and values in table "Many".
For example, below is pseudocode (it will not work in DAX) . I want to create a DAX code for it...
Table = Filter (One, Related(Many[ID]) = 1)
My thought is I need to use RelatedTable and Count functions somehow, but I cannot figure out now.
- vyacheslavgHelper II
I solved this, solution is below - maybe someone can find it helpful...
First, create temp table with distinct IDs.
Unique_Filter = SUMMARIZECOLUMNS('Many'[ID])
Then create relationship in datemodel.
and apply filter thru related! Great, it works the same as in Report view!
Not very elegant, but it does the work just fine.
One_filter_applied = FILTER(One, RELATED(Unique_Filter[ID]))