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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
shivkonar
Frequent Visitor

Related Value from Slicer

Hi,

 

I have a table called 'Date Selection'. It has 2 columns, Week Number and Week Commencing

 

Screen Shot 2018-08-28 at 16.43.07.png

 

Now, in my report, I have a slicer which is based on 'Date Selection'[Week Commencing]. The use can only select 1 value.

 

When the user selects a value on the slicer, I want a measure which can store the related Week Number

 

Eg. User selects 'January 29, 2018', [MyMeasure] should be equal to 5

 

How would I do this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @shivkonar

 

You can create the desired measure with the following code:

 

Measure = MAX('Date Selection'[Week Number])

When the user selects a Week Commencing, the measure will return the specific Week Number associated with that selection. If you wanted to set a default value when no Week Commencing selection is made, that would just take a little more code.

 

Hope this helps,

Parker

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @shivkonar

 

You can create the desired measure with the following code:

 

Measure = MAX('Date Selection'[Week Number])

When the user selects a Week Commencing, the measure will return the specific Week Number associated with that selection. If you wanted to set a default value when no Week Commencing selection is made, that would just take a little more code.

 

Hope this helps,

Parker

Thank you, @Anonymous .

That's a good point you raised about default value. I guess I can use TODAY() to get the today's date and then calculate the week commencing and then with IF and COUNTROWS I can set the default week selected to current week?
Anonymous
Not applicable

@shivkonar Yep you're definitely on the right track. Whenever I am setting a default value I use this code:

 

IF(
   COUNTROWS(DISTINCT(ALLSELECTED('Table'[Column])))
   = COUNTROWS(DISTINCT(ALL('Table'[Column]))),
   [Default Value],
   [Non-Default Value]
)

There may be an easier way to do this but you are basically seeing if the number of rows in your selection is the same as the number of rows of the full table. If yes, then either no selection has been made or all of the options have been selected in which case you can use a default value. 

 

Hope that makes sense,

Parker

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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