cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Calculate difference between values of two years in the same column

I have a data table consisting of two columns: Year and Value as follows

 Year Value 2023 30 2023 20 2024 10 2024 60

I want to calculate the difference between the two years over here. The problem is that I cannot user a slicer and cannot hard code the years either

I tried doing something like

SumofVal = SUM(Table[Value])

Diff = [SumofVal] - [SumofVal] and dragging the Year filter twice into the Filters Pane (doesn't make any sense I know) but I was wondering if there's a way of achieving this without slicers. Also if it helps, we will always be comparing the current year with the previous year.

Any help with the same would be appreciated. Thank you.

1 ACCEPTED SOLUTION
Community Support

Your solutions are great. Here I have another similar idea in mind, and I would like to share it for reference.

The Dax function is shown below:

If your goal is to subtract the sum of each year's values from the sum of the previous year's values, you can try this measure:

``````M_1 =
VAR SumCurrentYear =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] = MAX ( 'Table'[Year] ) )
)
VAR SumlastYear =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] = MAX ( 'Table'[Year] ) - 1 )
)
RETURN
SumCurrentYear - SumlastYear``````

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 REPLIES 3
Community Support

Your solutions are great. Here I have another similar idea in mind, and I would like to share it for reference.

The Dax function is shown below:

If your goal is to subtract the sum of each year's values from the sum of the previous year's values, you can try this measure:

``````M_1 =
VAR SumCurrentYear =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] = MAX ( 'Table'[Year] ) )
)
VAR SumlastYear =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] = MAX ( 'Table'[Year] ) - 1 )
)
RETURN
SumCurrentYear - SumlastYear``````

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Solution Specialist

What type of comparison do you want to do?

There are many ways of comparing if the Data Model is constructed correctly, using Time Intelligence, you should look into this when you have time.

These will get you on your way

Create a base measure

``````Total Value =
SUM('Table1'[Value])``````

PY

``````PY = CALCULATE([Total Value],
KEEPFILTERS(MAX(Table1[Year]) - 1 = Table1[Year]))``````

Then this measure to show the difference to last year

`` PY Diff = [PY]- [Total Value]``

This will show the % deviation

``````% Deviation =
DIVIDE( [Diff PY], [PY], 0)``````

Hope this helps

Joe

Super User

Hi, @BIUser1998

try below measure

``````Measure =
var a = SUMX(FILTER(ALL('Table'[Year],'Table'[Value]),'Table'[Year]=MAX('Table'[Year])),'Table'[Value])
var b = MAXX(FILTER(ALL('Table'[Year],'Table'[Value]),'Table'[Year]<MAX('Table'[Year])), 'Table'[Year])
var c= SUMX(FILTER(ALL('Table'[Year],'Table'[Value]),'Table'[Year]=b),'Table'[Value])
RETURN
a-c``````

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors