Forum Discussion
Dual relationship and filtering
(I just learned Power Bi two weeks ago - appreciate your patience)
Looking for some assistance
- I have a "Communications" table that includes line items for each communications from one PC to PC another. Each line includes date, originating and destination PC.
- I have a "flag" table that includes flags for special PCs. Say one of the flags is called "Lab"
I would like to be able to easily filter on my report and filter a line when a) originating b) destination c) originating and destination have the flag "Lab"
What I did on Power Query is to pull (merge) the flag on the communications table for each originating and destination and concatenate it. So I have resuls like (original flag, destination flag)
Lab, null
null, Lab
Lab, Lab
Lab, Office
Office, Lab
Office, Office
....
I concatenated this both on a single field and I can filter on a report but it is inconvenient because instead of me just selecting "Lab" I need to select many entries with the word Lab.
Appreciate any suggestions to make this easier
PS. I could use to "flag" tables but then the report can not filter "OR" only "AND"
OK, I hope you're ready for this!
We're going to create this model:
Each of these tables are related on [commPatternCode].
dimCommsBridge is just there to avoid MANY:MANY relationships.
Everything we do will be in Power Query initially, with just one DAX measure at the end.***Preparing your fact table (I will refer to this as factComms):
-- I am assuming that your flag table only has one row per PC (but may have duplicated flag names).
1) Merge your flag table onto your fact table on flagTable[PC] = factComms[origination], expand Flag field and change the name to flagOrig.
2) Do the same on flagTable[PC] to factComms[destination], expand and rename to flagDest.
-- You should now have two new columns in your fact table that give you the flag names of the PC's involved in each row.
3) Create a new column in factComms by merging [flagOrig] and [flagDest] together using '-' as the delimiter.-- You should now have a new column in factComms that looks something like this in each row: Office-Lab. Call this [commPatternCode].
***Creating dimComms:
4) Create a blank query and, in the formula bar, type this:= Table.Distinct(Table.SelectColumns(factComms, {"flagOrig", "flagDest"}))to give you a table with all unique combinations of orig/dest from factComms.
5) Filter out nulls from both columns if necessary.
6) Add a new [commPatternCode] column in dimComms by merging your two columns together as you did before.
7) Add another new column in dimComms called [commSearchTerm], using this code:{[flagOrig], [flagDest]}-- Note the use of curly braces here!
😎 Expand this column TO NEW ROWS.
9) Remove any other columns keeping only [commPatternCode] and [commSearchTerm] and change data types to text.***Creating dimCommsBridge
10) Create a blank query and type this in the formula bar:Table.Distinct(Table.SelectColumns(dimComms, "commPatternCode"))11) Apply these new tables to your model and relate as per my initial screenshot.
-- Take care to notice that dimComms > dimCommsBridge filters in BOTH directions.
12) Now create a measure in your factComms table like this:
_countFilter = COUNTROWS(factComms)-- Relate any other dimension you want directly to the fact table, use dimComms[commSearchTerm] in your single-word slicer, and add the [_countFilter] measure as visual-level filters to any slicers etc. that you want to react to filter changes, with the logic [_countFilter] > 0.
Voila!
Pete
20 Replies
- BA_Pete
Super User
Hi arcegabriel ,
Do you want to be able to filter separately/specifically where the communication is LAB>LAB, or are you happy for this to just be one of the result set when you filter on 'LAB'?
To just have it in the result set, then you could try something like the following. I'm assuming that your Flags table is a unique list of all the different names:
flagNameExists = SEARCH( SELECTEDVALUE(flagTable[flagName]), SELECTEDVALUE(commsTable[pcConc]), -1 )The [pcConc] field referenced is your concatenated field in he comms table.
You would then apply this measure as a filter on the visuals you want to be filtered by your flag slicer, with the logic: [flagNameExists] >= 1.
If you want to be able to identify specifically those comms that are from and to the same flag, then in your comms table you could create a new column, something like this:
if [originating] = [destination] then "Same" else "Different"You can then add this field to another slicer to allow this characteristic to be filtered on.
Pete
- arcegabriel
Helper I
No, I just want to click "Lab" to consider any/all possibilities
- BA_Pete
Super User
Ok. I've updated my original answer with the options as I see them.
Let me know how you get on.
Pete