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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
PhilippeGR
Frequent Visitor

How do you dynamically calculate value based on slicer

Please bear in mind that I am fairly new at DAX.

 

I have a table called BaseTable as follows

PhilippeGR_1-1737734342816.png

and a slicer

PhilippeGR_7-1737734867043.png

I have defined 4 measures:

[MaxYr] = CALCULATE(max('BaseTable'[UWYear]), ALLSELECTED('BaseTable'))

[Value MaxYR] = CALCULATE([Value], FILTER(ALL('BaseTable'), 'BaseTable'[UWYear] = [MaxYr]))

[MaxYr-1] = [MaxYr] - 1

[Value MaxYR-1] = CALCULATE([Value], FILTER(ALL('BaseTable'), 'BaseTable'[UWYear] = [MaxYr-1]))

[MaxYR] gives me the max UWYear from the Slicer.

 

When I choose a UWYear value of 2025, I get the following

PhilippeGR_5-1737734650203.png

Which is correct

 

However, I change a UWYear value to 2024, I get the following

PhilippeGR_6-1737734708106.png

Which is not correct.

I was expecting [Value MaxYR] to be $1,177 and [Value MaxYR-1] to be BLANK.

 

Can you please help?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

The issue is the ALL('BaseTable') in the FILTER arguments. That makes every year visible, and so when you call ALLSELECTED that will also return all the years.

Also, it is bad practice to filter entire tables, you should only filter the columns you need to. It is more accurate and more efficient.

Change your [Value MaxYr] function to

Value MaxYR =
VAR MaxYear = [MaxYr]
VAR Result =
    CALCULATE ( [Value], 'BaseTable'[UWYear] = MaxYear )
RETURN
    Result

and make the corresponding changes in [Value MaxYR-1] as well.

 

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

The issue is the ALL('BaseTable') in the FILTER arguments. That makes every year visible, and so when you call ALLSELECTED that will also return all the years.

Also, it is bad practice to filter entire tables, you should only filter the columns you need to. It is more accurate and more efficient.

Change your [Value MaxYr] function to

Value MaxYR =
VAR MaxYear = [MaxYr]
VAR Result =
    CALCULATE ( [Value], 'BaseTable'[UWYear] = MaxYear )
RETURN
    Result

and make the corresponding changes in [Value MaxYR-1] as well.

 

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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