Power BI – Using a Slicer to show different measures
I was on the Power BI Community where a question was asked how to use a Slicer to show different measures in a chart. I personally do it all the time, but after some searching trying to find a potential blog post to reference, I could not find anything suitable. So here is how to do it.
Example
- I created the following dataset below, which has got Sales and Costs amounts.
-
I then created the following 3 measures as shown below.
- NOTE: The reason I created the measures, is it is recommended best practise to always use measures. Which as you will see below makes additional measures easier to write.
-
Measures
- Sales = SUM(Sales[Sales Amount])
- Costs = SUM(Sales[Cost Amount])
- Margin = [Sales] – [Costs]
- So once created this is what my table looked like
Creating the Disconnected Table
Next what I had to do was to create my disconnected table.
What the disconnected table does, is it is a way for me to store my values that I want to display in my slicer.
The reason that it is called a disconnected slicer is that it is not connected to anything. And it is used for the slicer, as well as for my measure to control which measure to show.
-
I clicked on Enter Data and put in the following as shown below.
- I gave it the name of Measure Selection
-
You will also see above I put in an Order column, this is so that I can control the order of the measures shown in the slicer.
- Once the table has loaded I clicked on the Measure Name column, then in the Ribbon I went to Modeling and then clicked on the Sort By Column and selected Order
Creating my dynamic measure using the Disconnected table (Measure Selection)
In the steps below, I will demonstrate the how to create my dynamic measure which will change based on what is selected from the Disconnected table.
-
Below is my measure, with an explanation afterwards
- Line 1, is the name of my measure called “Selected Measure”
- Line 2, is where I am creating a variable called “My Selection” and this will store my DAX measure in the variable called “My Selection”
-
Line 3, I have used the SELECTEDVALUE DAX function, which will get the selected value from my disconnected table with the column called [Measure Name]
- And if nothing is selected default to “Sales”
- If I select “Costs” from the disconnected table, the Variable MySelection will hold the value of “Costs”
- Line 4, once I have finished with my variables, you have to put in the RETURN to continue with the standard DAX functions.
- Line 5, I am using the SWITCH DAX function, which will allow me to switch through different values, based on what I select.
- Line 6, I use the TRUE() DAX function, which allows me to define multiple values to switch through.
- Line 7, I am using the Variable from line 2 & 3, as my Starting Comparison, and then after the “=” is what value I am looking for, and in line 7 it is called “Sales”, which I then want to return the measure of [Sales]
- Line 8, I am using the Variable from line 2 & 3, as my Starting Comparison, and then after the “=” is what value I am looking for, and in line 7 it is called “Costs”, which I then want to return the measure of [Costs]
- Line 9, I am using the Variable from line 2 & 3, as my Starting Comparison, and then after the “=” is what value I am looking for, and in line 7 it is called “Margin”, which I then want to return the measure of [Margin]
- And then for the SWITCH syntax if nothing is evaluated to true, then I default it to the measure of [Sales], which is also the default value if nothing is selected in the SELECTEDVALUE
Using the Dynamic Slicer to display different measures
Now finally I put it all together to show how when selecting a value from the slicer, it will then change to show the selected measure.
-
I created the Slicer using the values from my “Measure Selection” table
- I then created 2 tables, one to show all the measures.
- The second table has got the “Selected Measure” that I created earlier to show when I click on the Slicer it displays the correct measure. Which I can validate by comparing the 2 tables.
Conclusion
As you can see I have demonstrated how to use Disconnect tables and a slicer to show different measures in one table, which could also be used in a visualization, making it more dynamic and flexible for users consuming the reports.
You can download a copy of the PBIX file here: Multiple Disconnected Slicers.pbix
Very Nice.
Thanks
Useful technique, I’ve tried before but couldn’t get around formatting, I was switching between a quantity measure and a sales amount measure, whatever you put in the bar chart by default in the data well was the formatting it used, do you know of a work around?
Hi Mike,
Do you perhaps have an example?
Was it that for the quantity measure you wanted it as 12,887.90
Whilst for the Sales Amount you wanted it as: $ 36,373.69
Yep, qty I wanted as 3,517 and dollar amount as $124,127.
Hello, I was wondering if you had found a solution to this?
Loved the thecnic
Hi Sam,
Unfortunately not at this time!
Thanks for sharing the technique. I have worked on Tableau with this dynamic measure selection but always wondered how to do the same in Power BI.
Btw is there a way around to name this dynamic column as Sales or Cost or Margin based on selection instead of static name ‘Selected Measure’
Hi, thanks for the nice comments.
Unfortunately as it currently stands with Power BI, the measure names cannot be changed dynamically.
You can create a measure using the name of the selected metric to create a dynamic title and place above the viz and use a card to display it with the measure as the the only value or another option is to put the slicer above the viz.
If I want to see the result for example in a column chart.
Is it possible to see 2 measures at the same time. (Like 2 columns)
Yes this can be done. As long as there is nothing on the Category axis
Even in the case of a clustered column chart? E.g., I would want to show each selected measure compared to each other over time.
I’m trying that but the measures pile up on top of each other when I enable multi-selection on the slicer.
What you would need to do, is to have to slicers and create two measures one for each slicer.
And then put measure one on the Column Values, and the second measure on the Line Values.
Hi Gilbert, Great Post.
Quick Question. Would this work if both sales and cost are both in Rows vs. in columns and the measures are defined using calculate?
I am trying this trick, however, the measures displayed are incorrect when using the “selected measure”, but show up correctly when displaying the actual measure “Margin”
Hi there I have not tested it with having the measures on Rows.
In theory it should work, but not 100% sure.
Do you perhaps have a sample dataset that I could test it out on?
Hi, Its is a very informative and nicely explained post. Is it possible to select multiple measures from the slicer? for example, if I want to compare sales and margin, I could select both from the slicer and see them. Can you please help?
Hi there, currently I do not think it is possible, because the measure can only return 1 value
Hi there
Just to let you know I created a new blog post solving your initial question here: https://www.fourmoo.com/2019/02/19/do-you-know-how-to-use-multiple-disconnected-slicers-in-power-bi/
Hi,
thanks for this example.
I’m not able reproducing this example (especially the big measure)
Please deliver this example in your link (actually in your link this example is not included)
—————-
You can download a copy of the PBIX file here: Disconnected Slicers.pbix
—————
Thanks !!!
Hi there, I just tested and the link does currently work correctly.
Hi,
This is great and I was able to get it to work for my scenario. However an additional issue I have is the 2 measures I am toggling with the slicer need to display in different formats. One of the measures is a decimal to 1 decimal place. The other is a decimal to 4 decimal places. But in my table I can only see a way of setting the format of the Measure Selected to either be 1 or 4 decimal places.
I’m not sure if what I am trying to do is even possible….
Thanks for your help.
Hi there,
Currently this is not possible, because as soon as you try to change the measure to change the formatting options it will then change it from a measure value to text, which means it will not aggregate.
There is an option coming soon, where you will be able to do this at a later time.
Hi Gilbert – Was there ever a solution developed for this? Having the same issue.
Hi there, if this is only going to be in a table then you could format each of the measures in the FORMAT([My measure],”0,0″) for a single digit and FORMAT([My Measure],”0,00″) for a double digit.
The thing to be aware of is that it will change the data type of the measure from Whole Number or Decimal Number to Text because of the formatting.
Hi
Thanks for this post.
Is it possible to create a slicer on the output of the measure, so that it would look something like this:
Sales amount:
150
So that if i chose <100 it would only show me the ones with a sales amount under 100
Is there anyway to do this?
Hi there
Yes this can be done, where you could create a measure and it could filter based on what is selected in the Slicer
You could look at this post where I use the TopN, and modify this pattern for what you are looking to do?
TopN made Easy
Thx For the reply.
Yes this seems to be what im looking for, but i cant seem to figure out how to filter on the actual numbers and not by ranking.
How would you write the DAX if you wanted to show Cities based on an interval and not by RANK? Ex:
0-50.000
50.000-100.000
>100.000
Thanks in advance.
Hi there
I have a blog post explaining how to achieve this here:
https://www.fourmoo.com/2017/05/23/power-bi-dynamic-banding-across-all-fields/
Hi Gilbert,
Great post! The measure works very good.
Can we expand this measure with two slicers?
1. sales vs costs
2. EUR vs USD
And if so, how would you tackle this?
Hi Pascal, that is indeed a great question and a great idea for a blog post.
This most certainly can be done, by almost replicating what I did in this blog post, with another set, where they can interact with each other.
A very helpful trick learned !! Thanks a ton
One question can measure name ( one created in disconnected table ) change column heading in the table as per change in slicer selection .
Like if i select sales or quantity or margin in the slicer, my column heading should also change accordingly in the table
Thanks for the kind words.
Yes this can possibly be done with a measure that could then be used as label.
Label - Name = VAR MySelectedValue = SELECTEDVALUE('Measure Table'[ColumnName]) RETURN "Measure shown " & MySelectedValue
Hi Gilbert,
I was directed to your blog by a Power BI user to find similar solution. I am trying to replicate your code, but getting syntax error ‘The following syntax error occurred during parsing: Invalid token, Line 7, Offset 15, “:
Mean_diff_ini_final =
VAR MySelection =
SELECTEDVALUE (Module_selection[Module])
RETURN
SWITCH (
TRUE(),
MySelection = “Middle”,’answers_view'[Mean_difference_Initial and middle],
MySelection = “Final”, ‘answers_view'[Mean_difference_Initial and Final],
“0”)
Please advise, thanks, Meena
Hi there, thanks for the comment.
It appears from your example that you are looking to use a column in the result instead of a measure.
Also the final value should not be text, where you have put the “0” it should rather be 0
I would first make sure that you have your measures already created and then it would look like the following:
Mean_diff_ini_final =
VAR MySelection =
SELECTEDVALUE ( Module_selection[Module] )
RETURN
SWITCH (
TRUE (),
MySelection = "Middle", '[Mean_difference_Initial and middle],
MySelection = "Final", '[Mean_difference_Initial and Final],
"0"
)
Thanks Gilbert for your reply. It works, but my requirement is that the slicer allows multiple selections. So I used VALUES function instead of SELECTEDVALUE. However, this now results in an error saying more than one value stored in Myselection. Does the Switch statement work with multiple selections as well?
[…] Power BI – Using a Slicer to show different measures […]
Hi
I am using the same. It works if I have to use dynamic measures once. But in my case I have one table but I have to use the same table twice on the same page. Say for example
My table data is like that
Type column has 2 values ( Measure and Selection)
Desc column for Measure it has 2 values ( Sales and Cost) and for Selection it has (CY and LY)
Alternative Desc is for storing full desc. ( Current year ( which is fill form of CY and Last Year for LY)
Now I have 2 slicers one for Measure and one for Selection. I am able to filter the data if I selects Sales or Cost. But nothing is happening If I change Current Year or Last Year Filter. Any ideas Hope I am clear.
Hi there, thanks for the comment.
Please see my blog post below which should solve your question
https://www.fourmoo.com/2019/02/19/do-you-know-how-to-use-multiple-disconnected-slicers-in-power-bi/
Thanks. Is it possible to use the single table for two disconnected slicers as I have mentioned in my example.
Hi there
Not as far as I can see, you need the 2 tables to be able to identify how to switch the measures.
Hi,
I am attempting to use this method to switch the column on which a donut chart is based. So let’s say we want the donut chart to show categories of sales and cost i.e <10,10-20,20-30 ect. The category can be held in a column in the fact table. I tried to have the measure return VALUES() of the categorical columns but that does not work when applied to the donut chart.
Any thoughts? Thanks.
Hi there
As it stands today we cannot dynamically switch column values on a visual. It can only apply to a measure.
What I am hoping in time is that with the conditional formatting this can be done on visuals.
Hi,
Any suggestions on doing this for a list of 30+ measures? It becomes still quite slow.
Thank you in advance!
Hi there
Could I ask why you would want to have 30 measures?
The reason for my question is that when users have too many options they get stuck like a deer in headlights.
It will potentially get slower due to it having to check which of the 30+ measures to find and use.
Thank you,
I have a question, How you change color item’ background selected?
Hi there
The Power BI team is updating more features for conditional formatting. Right now it is only the gauge that can change the colour
https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-september-2019-feature-summary/
[…] Dynamischer Slicer […]
How would you utilize this if you wanted to switch between certain text columns? I am having trouble creating a measure that will return the same text, similar to how the SUM() function works for numbers.
Hi there
You could use the VALUES function to achieve this?
Very Awesome!!
Thank you so much for your in depth explanation of how this works. I was able to implement a similar slicer thanks to your post!
Thanks for letting me know, great to hear it assisted you!
Hey, thanks for this great article! I downloaded the file and it seems to be a different example from the article. It seems to have some of the same ideas but the slicer works with multiple selections. I don’t see any SELECTEDVALUE or SWITCH functions in the measures however. Can you explain how it works?
Hello! Not sure if you are still replying to these…
I am using your slicer method to show 3 measurements with 3 different data types (percent, currency, whole number). When I display these values the data type is only able to be a decimal number. Is there a way to show each measurement in its native data type?
Hi there
If you want to do that I would suggest looking at using the new Calculation Groups feature.
Here is a blog post where I show how to use it How to create and use Calculation Groups in Power BI Pro & Premium / Azure Analysis Services / SQL Server Analysis Services 2019
Hi,
What if i want to select multiple KPI’s instead of a single KPI?
Generally both sales and cost (w.r.t to your example) at the same time.
Hi there
If you wanted to do this, you could create a measure table as a disconnected table and then select it from the measure table?
Does that make sense?
Hi there, Hi, when i download the disconnected slicers file, the tables do not match with your examples with sales and cost. In the file i download, the tables are below.
Country
Date
Working Hours
Working Hours Comparison
I would like to create a slicer to show the following measures and here is the disconnected table I created. I would also like the column name to display which measure is selected.
Measure Order
# of Customers 4
# of Sales Reps 3
ASP 1
Margin % 2
Quantity 5
Sales 6
Also, thank you so much for this post. It’s very helpful!
Thanks for the comment, it is appreciated.
Hi Kayla,
Thanks for the comment.
You are correct that the file was wrong, I have updated the blog post with the correct file. If you could have a look and hopefully this will resolve your error.
Great Post, Thanks for sharing
No worries, thanks for the great comment!