cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User I
Super User I

Dynamic calculation based on filter selection (DAX not M)

Hello experts,


My sample data is as following

BUYearGLAmount
12016511200100
12017511200200
12018511200300
12019511200400



All I want is the DAX to calculate based on a filter selection on year the last 2 year's corresponding value.
e.g. if the reader selects 2019 from the filter, I want the following view to be returned in the matrix viz

BUGLSelected Year AmountSelected Year-1 AmountSelected Year-2 Amount
1511200400300200


e.g. if the reader selects 2018 from the filter, I want the following tview to be returned in the matrix viz

BUGLSelected Year AmountSelected Year-1 AmountSelected Year-2 Amount
1511200300200100


Thank you in advance,

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User I
Super User I

Re: Dynamic calculation based on filter selection (DAX not M)

Figured out as below

Selected Year-1 Total = 
VAR f=FILTERS('Table 1'[Year])
VAR f_1=f-1
VAR x=CALCULATE(SUM('Table 1'[Amount]),FILTER(ALL('Table 1'),'Table 1'[Year]=f_1))
RETURN
x

View solution in original post

1 REPLY 1
Highlighted
Super User I
Super User I

Re: Dynamic calculation based on filter selection (DAX not M)

Figured out as below

Selected Year-1 Total = 
VAR f=FILTERS('Table 1'[Year])
VAR f_1=f-1
VAR x=CALCULATE(SUM('Table 1'[Amount]),FILTER(ALL('Table 1'),'Table 1'[Year]=f_1))
RETURN
x

View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.

Top Solution Authors
Top Kudoed Authors