Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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.
Solved! Go to Solution.
Hi @vyacheslavg,
Try this formula please:
Table = FILTER ( NATURALINNERJOIN ( 'Orders', Products ), [City] = "Paris" && [ID 1] = 3 )
Best Regards!
Dale
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.
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.
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]))
I want to extend it now to work with more complicated filters, but struggling so far...
Assume, that you have Products and Orders tables.
Table "Products"
ID Details
1 red
2 blue
3 green
4 black
Table "Orders"
ID City
1 London
2 Frankurt
2 Paris
3 London
3 Paris
3 Berlin
I want to create the table, where ID =3 and City = Paris.
This is how to solve it (phew...)
Unique_Filter v2 = SUMMARIZECOLUMNS(Orders[ID], FILTER(Orders, Orders[City]="Paris" && Orders[ID] = 3))
There SHOULD BE simpler way to do from Orders side, not Products... But I want to get all details about products from Products table into this new table.
In pseudocode, it should be something like this.
Filter Orders table by ID = 3 and City = Paris. Easy.
Get all details from Products, using ID. Hard.
I think it could be some kind of join on already filtered Orders table.
Hi @vyacheslavg,
Try this formula please:
Table = FILTER ( NATURALINNERJOIN ( 'Orders', Products ), [City] = "Paris" && [ID 1] = 3 )
Best Regards!
Dale
Hi Dale,
this is it - this is one step creation of table from Many side with all details from One side.
(I expected that IDs will go into single column during join, but this is minor stuff - I can easily remove this column later).
Thanks!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
93 | |
84 | |
66 |