Forum Discussion
Slicer to filter table before UNION
- Anonymous5 years ago
// First, you have to create // the RIGHT union: [Values] = // calculated table UNION( SELECTCOLUMNS( Letters, "Value", Letters[Letter], "Table", "Letters" ), SELECTCOLUMNS( Numbers, "Value", // Since the column in the first // table is text, all the numbers // must be turned into text as well, // hence the suffix >>& ""<<. Numbers[Number] & "", "Table", "Numbers" ) ) // The column 'Values'[Table] MUST // be hidden. It'll only be used // by the filtering measure below. // There should be *NO* relationship // from any of the original tables // to the one above. // To the table Numbers add a hidden column // called NumberAsText. This will help later // with the filtering measure. The definition // of the column is: [NumberAsText] = Numbers[Number] & "" // This is the filtering measure that you'll // use in the visual's Filtering Pane and // you'll only show the rows where the measure // returns 1. [Should Show Row?] = IF( ISINSCOPE( 'Values'[Value] ), var vCurrentValue = SELECTEDVALUE( 'Values'[Value] ) var vCurrentValueTable = SELECTEDVALUE( 'Values'[Table] ) return SWITCH( TRUE(), // Selections made from both tables ISFILTERED( Letters ) && ISFILTERED( Numbers ), var vLetters = DISTINCT( Letters[Letter] ) var vNumbers = DISTINCT( Numbers[NumberAsText] ) var vShouldKeepRowVisible = or( vCurrentValue in vLetters, vCurrentValue in vNumbers ) var vResult = int( vShouldKeepRowVisible ) RETURN vResult, // Selection made from Letters only ISFILTERED( Letters ), var vLetters = DISTINCT( Letters[Letter] ) var vShouldKeepRowVisible = or( vCurrentValue in vLetters, vCurrentValueTable = "Numbers" ) var vResult = int( vShouldKeepRowVisible ) return vResult, // Selection made from Numbers only ISFILTERED( Numbers ), var vNumbers = DISTINCT( Numbers[NumberAsText] ) var vShouldKeepRowVisible = or( vCurrentValue in vNumbers, vCurrentValueTable = "Letters" ) var vResult = int( vShouldKeepRowVisible ) return vResult, // If nothing is filtered... show everything. 1 ) )
Anonymous
When creating your Union Table, the model is updated with the results from both the tables, and values selected in the slicers are not visible at that stage. Slicer selections cannot influence the table.
If you want to achieve this, you can create a measure and assign it to the union table on the filter pane under the visual filter.
I am not sure what is the use case here.
Apoogies for being too abstract.
The use case here is the following:
1. in a region there are 15 homecares (the Letters)
2. in the same region there are 100 homecarers (the Numbers)
When I select a Homecare, I'd like to see it on a list along with all homecarers on a 20 mile radius, so that I can plot it on a map visual.
Hope it shed some light on the matter!
Cheers!
Tiberiu