Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Typhoon74
Helper I
Helper I

How to apply a filter to same attribute on multiple table for a report?

Here you can find an example file with data 

 

I have the following situation in my data model. I hope I manage to describe it clearly.

The data tables each have their own archive attribute, which is cascaded down, based on the table relationships, when the upper level is put into the archive.

However, not in the form that the lower level is also set the attribute 0 or 1, but somehow simulated by a logic.

e.g. If project A is set to archive (1), then all components, phases, and tests are also shown as archived, but without also setting archive to (1) in the corresponding table.

Area 
|_Customer 
  |_ Model 
  |_ Project A (1) 
    |_ Component 
      |_ Phase 
    |_ Tests 
  |_ Project B 
  |_ Component 
  |_ Phase 
|_ Tests 
  |_ Component 
  |_ Phase 
|_ Tests 
  |_ Project C 
  |_ Component 
  |_ Phase 
|_ Tests 

Now, in order for the user to include or exclude all archived entries, it is necessary to select archive 0 or 1 for each table, as I have prepared in the sample file.

However, I would like to provide users with a single button to filter all tables to archive 0 or 1.

Is there any way to do this using a single slicer, if so how can I solve this?

 

This is the table relation

Table RelationTable Relation

 

And this is the report view

ReportReport

 

Thanks beforehand for any idea.

1 ACCEPTED SOLUTION

Use the Enter Data functionality to create a table like 

johnt75_0-1645782642710.png

 

This new table does not need a relationship to any other tables, all you're going to do with it is use it on a slicer instead of all the slicers on individual columns which you currently have. You can delete all those other slicers.

Looking at the image you posted it looks like you already have defined a measure COST which you're using on the column chart. Assuming that is the case, you can define a new measure as 

COST Filtered =
var chosenFilter = SELECTEDVALUE( 'Archive Selection'[Archived] )
var result = IF ( chosenFilter = "Archived",
CALCULATE( [COST],
TREATAS( { 1 }, 'AREAS'[Archive] ),
TREATAS( { 1 }, 'CUSTOMER'[Archive]),
TREATAS( { 1 }, 'MODELS'[Archive] )
),
CALCULATE( [COST],
TREATAS( { 0 }, 'AREAS'[Archive] ),
TREATAS( { 0 }, 'CUSTOMER'[Archive]),
TREATAS( { 0 }, 'MODELS'[Archive] )
)
)
return result

On the column visual you could then replace the COST measure with the new COST Filtered measure and the values will change depending on the user selection on the Archived slicer

View solution in original post

12 REPLIES 12
Typhoon74
Helper I
Helper I

Hi @johnt75 ,
thanks for your solution approach. I am not able to follow your thoughts.
There are no measures for the current Archive slicer, these slicers are directly connected to the table column.

Can you give some more details on what disconnected table and My Measure I need to define?

Many thanks

 

I did create the following table

009 Image.png

 

And for Measure, I created the following

010 Image.png

Use the Enter Data functionality to create a table like 

johnt75_0-1645782642710.png

 

This new table does not need a relationship to any other tables, all you're going to do with it is use it on a slicer instead of all the slicers on individual columns which you currently have. You can delete all those other slicers.

Looking at the image you posted it looks like you already have defined a measure COST which you're using on the column chart. Assuming that is the case, you can define a new measure as 

COST Filtered =
var chosenFilter = SELECTEDVALUE( 'Archive Selection'[Archived] )
var result = IF ( chosenFilter = "Archived",
CALCULATE( [COST],
TREATAS( { 1 }, 'AREAS'[Archive] ),
TREATAS( { 1 }, 'CUSTOMER'[Archive]),
TREATAS( { 1 }, 'MODELS'[Archive] )
),
CALCULATE( [COST],
TREATAS( { 0 }, 'AREAS'[Archive] ),
TREATAS( { 0 }, 'CUSTOMER'[Archive]),
TREATAS( { 0 }, 'MODELS'[Archive] )
)
)
return result

On the column visual you could then replace the COST measure with the new COST Filtered measure and the values will change depending on the user selection on the Archived slicer

Hi @johnt75,
there are NO other measures in my data set. COST is just a column having cost vale in.
Is this solution working without additional measures?

OK, in the code I posted above just replace both instances of [COST] with SUM( 'TableName'[COST] ) and then use this new measure on your visual instead of the COST column

It is not working,
When using the Measure on my visual it is already showing a reduced value.
If I then select Archived the visual is showing blank and if I select Not archived nothing happens

By default it will show a Not Archived value, that's why you're seeing no change when you choose Not Archived.

Can you check the values in the Archive columns on the 3 tables that have them. Are they text or integer, and if they are text is it possible that they would have trailing spaces ? The code I wrote is assuming that they are simple integers but if there are other values in there then it would need to be adapted to account for that

All Archive values are integer values.

Please have a look at the PBIX file with all the changes  ExampleData Central Archive.pbix

Hi @Typhoon74 ,

In your sample, if you want to calculate the cost when all the below attribute are archived, it will return nothing, it's correct.

Area 
|_Customer 
  |_ Model 
  |_ Project
    |_ Component 
      |_ Phase 
    |_ Tests 

For the TESTS table, when the ARCHIVE is 1, the PHASE ID are58,59,63,64,65,66,67,68,69,70,71,73,75,76,78,79,80

vkalyjmsft_0-1646191185876.png

For the PHASES table, when the ARCHIVE is 1, the PHASE ID are 61 and 73.

For the two tables, TESTS and PHASES, when both tables only select archived as 1, only when the PHASE ID is 73, the corresponding COMPONENT ID is 54.

vkalyjmsft_1-1646191311633.png

For the COMPONENTS table, when the ARCHIVE is 1, the COMPONENT ID is 55, not 54, so there's no overlapping value when the ARCHEVE of all these attribute is 1. 

vkalyjmsft_2-1646191784023.png

 

So when you select Archived the visual is showing blank.

What do you want it to show, or do you have more requirements for the calculation?

 

Best Regards,
Community Support Team _ kalyj

Hi @v-yanjiang-msft,
thanks for your feedback, my requirement was that I want to calculate the cost of all the archived when 1 is selected and all the cost of the non-archived when 0 is selected.

Hi @Typhoon74 ,

As I mentioned before, when 1 is selected in all attributes, no cost will return, because the values all attributes filtered out are not overlapping.

I 'm not sure whether I understand your requirement correctly, just in your sample, please kindly let me know what's value of "the cost of all the archived when 1 is selected" as you think.

Best Regards,
Community Support Team _ kalyj

You're right, I must have had a knot in my mind somehow. Sometimes you don't understand your own thoughts.

It is true, as you said, if I click 1 in Area, then there is no further data to be displayed.
The solution that @johnt75 is what I will use.

johnt75
Super User
Super User

I'd set up a disconnected table to use on the slicer, then have your measure check the value of that slicer and depending on whether or not they've chosen "archived" then apply the filters within the slicer.

Assuming you already have measures defined to do the calculation, you could do something like the below

My Measure Filtered =
var chosenFilter = SELECTEDVALUE( 'Archive Selection'[Value] )
var result = IF ( chosenFilter = "Archived",
CALCULATE( [My Measure],
TREATAS( { 1 }, 'AREAS'[Archive] ),
TREATAS( { 1 }, 'CUSTOMER'[Archive]),
TREATAS( { 1 }, 'MODELS'[Archive] )
),
CALCULATE( [My Measure],
TREATAS( { 0 }, 'AREAS'[Archive] ),
TREATAS( { 0 }, 'CUSTOMER'[Archive]),
TREATAS( { 0 }, 'MODELS'[Archive] )
)
)
return result

It looks from your model like filters on those 3 tables would propagate to everywhere else, but you can add more tables in to the TREATAS section as needed.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.