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
Anonymous
Not applicable

Using selections in slicers as variables in a DAX measuer.

Hi,

 

I have quite a lot of measures aggregating sales data (Value, Volum, Unit++++)

As my sales data comes in sums of 4 weeks I'm calculating my Running Yearly Totals as a sum of last 13 periods (4x13). But I also need all my measures in the latest quarter (last 3 periods), Last 4 weeks (last 1 period) ect.

 

My Running Yearly total measure looks like: 

 

MAT VALUE = CALCULATE(
   'a VALUE'[4W VALUE];
      FILTER(ALL('Calender');
      'Calender'[index]>MAX('Data'[Per_Index])-13
      &&'Calender'[index]<=MAX('Data'[Per_Index])
   )
)

 

My Idea then is that it must be possible to change the "13" to a variable that is selected in a slicer instead of building hundreds of measures... But I don't find any solutions when I google for it...

 

Is it possible at all?

 

Thanks a lot for helping out!

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

That's called a "What If Parameter". What you would want to do would be to create an Enter Data query and put in 13, 3 and 4 as your row data and call the column maybe NumPeriods and the table Periods. Then you could create a measure that would be:

 

MyPeriod = SELECTEDVALUE(Periods[NumPeriods])

You could then use [MyPeriod] in place of your 13 in your formula.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

That's called a "What If Parameter". What you would want to do would be to create an Enter Data query and put in 13, 3 and 4 as your row data and call the column maybe NumPeriods and the table Periods. Then you could create a measure that would be:

 

MyPeriod = SELECTEDVALUE(Periods[NumPeriods])

You could then use [MyPeriod] in place of your 13 in your formula.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler , What if we have a slicer with multiple selections, can we do it same way? 

Anonymous
Not applicable

You rock

Anonymous
Not applicable

Thanks a lot - Exactly what I needed!

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.