In this Power BI Tutorial, we will discuss how to get selected value from slicer in Power BI and the below topics with examples:
- Power BI get selected value from slicer
- Power BI get selected value from date slicer
- Power BI get multiple selected value from slicer
- Power BI get first selected value from slicer
- Power BI get max selected value from slicer
- Power BI get selected value from between slicer
- Power BI get number of selected values from slicer
To execute these above topics, we are going to use this sample excel data. Not only Excel files, but also we can import data from SharePoint list, txt file, My SQL database, CSV file, etc.
If you are new to Power BI, check out how to create a report in Power BI.
Power BI get selected value from slicer
Here, we will see how to visualize a randomly selected value from a slicer on Power BI Report.
For example, here we have created a slicer using only the month’s names from the sample data like this:
Now we will create a measure that will show the selected value from a slicer.
Selected_Month = SELECTEDVALUE('financials'[Date].[Month])
Then we will use this measure on a card chart to visualize the selected value.
This is how to get the selected value from a slicer in Power BI.
Power bi get multiple selected value from slicer
Similarly, we can show multiple selected values from a slicer by using this Power BI measure.
Multi_Selected_Months = CONCATENATEX ( VALUES ( financials[Month Name] ) , [Month Name] , ",")
For example, we will select 2-3 values at a time(Ctrl + select item). Here, we are going to use a card chart to show all the selected values.
This is how to get multi-selected values from a slicer in Power BI.
Read How to create a Measure based on Slicer in Power BI
Power BI get selected value from date slicer
Now we will see how to get a selected value from a slicer using dates in Power BI. Here we are going to create a slicer using the date column from the sample data.
Now we will create a measure, that will show the selected date from the slicer in Power BI.
Date_Selected = CALCULATE(MIN(financials[Date]), ALLSELECTED(financials))
The above screenshot, showing us the selected date that we select from the slicer. If we don’t select any dates from the slicer, then it will show the MIN date from the slicer (i.e. 9/1/2013).
This is how to get a selected value or date from a date slicer in Power BI.
Power BI get Max selected value from slicer
Now we will see how to get a Max selected date or value from a slicer in Power BI using a Measure.
Here, we will create a measure to show the Max value from the slicer.
Date_Selected = CALCULATE(MAX(financials[Date]), ALLSELECTED(financials))
This is how to get a MAX value from the slicer in Power BI.
Power BI get first selected value from slicer
Here we will see how to get the first select value from the slicer in Power BI. For this, we have created a year table having some random years like below:
Now we will create a measure that will show the first value from the slicer(i.e. 2002).
First__ Selected__ Year =
CALCULATE (
MIN ( 'Year'[Year] ),
ALLSELECTED ()
)
Also, if there is no value get select then we can set a default year as our first selected value.
First__ Selected__ Year =
IF(
ISFILTERED('Year'[Year]),
CALCULATE (
MIN ( 'Year'[Year] ),
ALLSELECTED ()
),
YEAR( TODAY() )
)
It will by default showing us the current year as our first selected value.
As the current year is 2021, it is showing the current year by default. If we select any value from the slicer, then it will show the value according to our selected value.
Read Power bi slicer contains with examples
Power BI get selected value from between Slicer
Now we will see how to get the selected value from between Slicer using the Switch statement. Here we are going to use our provided sample data based on financial.
Step-1:
First, we will create a table in Power BI. For this, on the Home tab > Enter data.
Step-2:
Now, we will create two measures for these selections options (i.e. Domestic and International) using profit data from the Sample report.
For Domestic:
Domestic = CALCULATE(SUM('financials'[Profit]),'financials'[Country]= "Canada")
For International:
International = CALCULATE(SUM('financials'[Profit]),'financials'[Country]<>"Canada")
Again, we will create another measure to get the selected value from the slicer.
SlicerSelection =
VAR Selection =
SELECTEDVALUE ( 'SelectedValue'[Selections] )
RETURN
SWITCH (
TRUE (),
Selection = "Domestic", [Domestic],
Selection = "International", [International],
CALCULATE (SUM('financials'[Profit]))
)
Instead of using the SELECTEDVALUE formula multiple times, we are using a variable as “Selection” which makes it easier to look at. To get the true value, which in this case will be a calculated value of the selective slicer value, we used the SWITCH(TRUE(),) function.
Step-3:
Now we will use the selections (the table, we have created) in a slicer, and will create an Area chart to show the slicerselections by month.
According to the slicer’s selection, the chart will change its value. Let’s have a look at the below chart.
This is how we can get the selected value from between slicer in Power BI.
Power bi get number of selected value from slicer
In Power BI, we can show the total number of a selected value from a slicer easily. For example, here we have created two tables. One table based on country’s name only. Another is based on ID and country’s name.
Table-1:
Table-2:
Now we will create a relationship between two tables from Country name to ID.
We can show the total count or number of each country by using a card chart. When we will select any value from the slicer, then it will show its total count on the card.
For example, if we will select Canada, then it will show its count as 3 like this:
This is how to do Power bi get a number of selected value from the slicer.
You may like the following Power BI tutorials:
- Power bi slicer checkbox
- How to set default value in Power BI Slicer
- Power Bi slicer multiple selections
- Power bi slicer multiple columns with examples
- Power bi slicer panel – How to use
- Power bi slicer filter another slicer – How to do
- Power BI Slicer Dropdown
- Power BI Measure multiply with examples
Conclusion
From this Power BI Tutorial, we discussed these below examples such as:
- How to get selected value from slicer in power BI?
- How to get selected value from date slicer in Power BI?
- How to get multiple selected value from slicer in Power BI?
- How to get first selected value from slicer in Power BI?
- How to get max selected value from slicer in Power BI?
- How to get selected value from between slicer in Power BI?
- How to get number of selected values from slicer in Power BI?
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com
Hi team,
For the date slicer, if I unselect all the dates, it should show a default value, any way to do that?
very good …helped me a lot..thank you
How do you set the selected values?
Hi, Thanks for this. How did you get the name of the slice in this: Selected_Month = SELECTEDVALUE(‘financials'[Date].[Month])