Forum Discussion
Measure across two tables
- 6 years ago
Anonymous
It is highly recommended to have relationships as one-to-many. It's easy to solve, and in fact, if you do not need to keep all rows iin your "Tools_Idefix_Order_Pane" table for some calculation (counting rows or something of that sort), you can simply remove duplicate rows in Power Query in this table and then proceed with loading to the model and creating the one-to-many relationship.
For the sake of this exercise, however, I'm assuming you need to keep the original "Tools_Idefix_Order_Pane" table intact. So we are going to create a new table which will be referenced to this "Tools_Idefix_Order_Pane" (so that any changes in the data source are reflected in the new table), and set it up as a lookup table for your model.
to proceed, go into Power Query and:
1) select your "Tools_Idefix_Order_Pane" table,
2) right click on it and choose "Reference" form the dropdown
this will create a new table (same as your original "Tools_Idefix_Order_Pane" table). Change its name (in my example I've called it Table B lookup).
3) now select the column, and in the Home tab, go to "Remove Rows" and select "Remove Duplicates"
4) Now select "close and Apply" to load the tables into the model and close Power Query.
5) go to the modeling pane and join you GUID column from your lookup table to your other table in a one-to-many relationship
it should look like this:
6) build the visual using the column from this lookup table
Let us know if you encounter any problems!
Try
countx(filter(crossjoin(TableA,TableB ),TableA[GUID] = TableB[GUID] && TableA[Unit]= 4100 && TableA[EM] = 400),TableA[GUID])
But this might give issues with common column names. Some rename might be needed
Thank you again
It doesn't give any message, so I guess the code is accepted. But it doesn't give out any value. I can see the cursor is indicating that the measure is in progress.
I've tried to rename TableB[GUID] to TableB[ShortGUID] but same outcome.
- amitchandak6 years ago
Super User
crossjoin is costly. check on small data first.
- Anonymous6 years agoNot applicable
amitchandak Thanks, you're right. It's working, although a bit too slow.
- amitchandak6 years ago
Super User
One method is that you add the column in table A
New column in table A= countx(filter(tableB,TableA[GUID] = TableB[GUID]),TableB[GUID])
This can act like a flag now