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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Joe_100
Helper I
Helper I

Select multiple values from slicer for DAX formula

Hi all,

 

At the moment i have a what if parameter so the users can select a month in a slicer, that parameter will be used in another dax formula.

 

I generate 12 month numbers and select the value from the slicer with the following DAX

 

MonthParValue = SELECTEDVALUE(MonthParameter[MonthPar])

 

After that i use that value in the following dax to select on a month basis.

 

EstimateCurrentMonth = calculate(sum('Sales'[Estimate]);FILTER(ALL('Sales'[MonthNumber]);[MonthNumber] = 'MonthParameter'[MonthParValue]))

 

this is working fine, but only if i select one month. I see that the selectedvalue returns only one value.

 

How can i change this so i can select multiple values from the slicer?

 

Thanks!

2 ACCEPTED SOLUTIONS
TomMartens
Super User
Super User

Hey,

 

I guess if you replace your estimation measure

EstimateCurrentMonth = calculate(sum('Sales'[Estimate]);FILTER(ALL('Sales'[MonthNumber]);[MonthNumber] = 'MonthParameter'[MonthParValue]))

with this

EstimateCurrentMonth = 
var selectedMonths = Values('MonthParameter'[MonthParValue])
return
calculate(
	sum('Sales'[Estimate])
	;FILTER(
		ALL('Sales'[MonthNumber])
		;[MonthNumber] IN selectedMonths
	)
)

You are good to go.

 

Please be aware that the variable selectedMonths contains a table and no loger a scalar value. You also have to make sure that the slicer with the Month numbers has to be enabled for multi selection

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

Hi @TomMartens

 

Thanks, but i think i fixed it fairly easily.

 

I created a measure 

 

IsFiltered = ISCROSSFILTERED(MonthParameter[MonthPar])

 

In the other DAX a simple IF check seems to work fine..

 

IF(MonthNamesNumbersAsVar[IsFiltered] = TRUE;
calculate(..................

View solution in original post

7 REPLIES 7
TomMartens
Super User
Super User

Hey,

 

I guess if you replace your estimation measure

EstimateCurrentMonth = calculate(sum('Sales'[Estimate]);FILTER(ALL('Sales'[MonthNumber]);[MonthNumber] = 'MonthParameter'[MonthParValue]))

with this

EstimateCurrentMonth = 
var selectedMonths = Values('MonthParameter'[MonthParValue])
return
calculate(
	sum('Sales'[Estimate])
	;FILTER(
		ALL('Sales'[MonthNumber])
		;[MonthNumber] IN selectedMonths
	)
)

You are good to go.

 

Please be aware that the variable selectedMonths contains a table and no loger a scalar value. You also have to make sure that the slicer with the Month numbers has to be enabled for multi selection

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartens

 

Thanks, this works like a charm 🙂

@TomMartens

One other question, i see that the slicer returns all values as default, how can i set it so the slicer returns "nothing"  as default?

Unfortunately you can't. Nothing selected means all is selected. That's how slicer work.

Regards
Tom


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens

 

Thanks, but i think i fixed it fairly easily.

 

I created a measure 

 

IsFiltered = ISCROSSFILTERED(MonthParameter[MonthPar])

 

In the other DAX a simple IF check seems to work fine..

 

IF(MonthNamesNumbersAsVar[IsFiltered] = TRUE;
calculate(..................

Perfect!



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Zubair_Muhammad
Community Champion
Community Champion

@Joe_100

 

Try with following

 

EstimateCurrentMonth =
CALCULATE (
    SUM ( 'Sales'[Estimate] ),
    FILTER (
        ALL ( 'Sales'[MonthNumber] ),
        [MonthNumber] IN VALUES ( 'MonthParameter'[MonthParValue] )
    )
)

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.