简体   繁体   中英

Highlighting with slicer Power BI

I have a Dashboard with different visuals. Data is made up of different values for insurance companies. I want my slicers/filters to not filter all data, but to only highlight the chosen company.

For example, in my slicer I choose the insurance ABN. Instead of showing me the value for ABN only in my visuals, I want all other values to still be visible and ABN's value to be highlighted in the visuals.

Does anyone know how to do this?

You can use conditional formatting to achieve this. Lets say that we will change the background color to "highlight" a row (or cells, to be precise).

First, we need a slicer, which will not filter our data. We can do this by duplicating our source table, removing the unnecessary columns and making sure there is no relationship between the source and the duplicate. So if we have a source table, named Table , like this:

在此处输入图片说明

Right click on it and select Duplicate :

在此处输入图片说明

Then right click the title of the column you want to keep and select Remove Other Columns to get a list of company names only (you may also remove the duplicates, but it's not required). Then in the model delete the relation between both tables:

在此处输入图片说明

Now you can place a table showing company name and sales from your data source, and a slicer for company name from the duplicate table. At this point selecting values in the slicer should not affect the table.

Now you need to capture the value of the slicer and use it in a measure, which will determine should current row be highlighted or not. You can use SELECTEDVALUE for that, but note that it will give you a value only if there is a one selected in the slicer. If you want to support highlighting of more than one company, it gets a bit more complicated.

Make a new measure in your source table, like this:

Measure = IF(HASONEVALUE('Table (2)'[Company name]);
    IF(SELECTEDVALUE('Table (2)'[Company name]) = MAX('Table'[Company name]); 1; 0);
    IF(ISFILTERED('Table (2)'[Company name]) && COUNTROWS(FILTER('Table (2)'; 'Table (2)'[Company name] = MAX('Table'[Company name]))); 1; 0))

In case there is only one value selected in the slicer (see HASONEVALUE ), then our measure will return 1 (highlight) or 0 (don't), comparing it with the current row.

Otherwise (ie there is no selection in the slicer, or there are 2 or more companies selected), then we will look at the filtered list of companies ( Table (2) ) - if it contains current row, then 1 (highlight), otherwise 0 (don't). But we will also handle the case, where there is no value selected in the slicer. In this case the list will contain all the companies, ie all rows will be highlighted. Here comes ISFILTERED . And at the end, if the list is filtered and current row exists in the filtered list, then 1 (highlight), otherwise 0 (don't).

Now, you need to use this measure to change the background of the column - right click each column in your table and select Conditional formatting -> Background color :

在此处输入图片说明

Then format by rules, where Measure >= 1 like this:

在此处输入图片说明

Now, when there is no selection in the slicer, there are no rows highlighted in the table:

在此处输入图片说明

If you select one company, it is highlighted:

在此处输入图片说明

It also work if there are multiple companies selected:

在此处输入图片说明

Thank you Andrey for your step-by-step explanation which as been incredible helpful. I'd like to follow up with a further question, particularly regarding the comment below.

"You can use SELECTEDVALUE for that, but note that it will give you a value only if there is a one selected in the slicer. If you want to support highlighting of more than one company, it gets a bit more complicated."

In my model, I've linked a third table (Table (3)) to Table (2) with a many to one relationship with Table (2). Therefore when I click on Table (3), it will filter Table (2), which acts as a slicer for Table (1).

When only 1 value is filtered in Table (2), it conditionally formats the cells in Table (1). However, when more than 1 value is filtered in Table (2), conditional formatting fails.

As I'm looking to avoid manually selecting multiple values in the slicer (Table (2)), I was wondering if there's a workaround for SELECTEDVALUE such that it is able to conditionally format when I filter more than 1 value in Table (2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM