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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
BIUser1998
Helper I
Helper I

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

 

YearValue
202330
202320
2024

10

202460

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
v-jtian-msft
Community Support
Community Support

Hi,@BIUser1998 .I'd be happy to help you.
@Dangar332 ,@Joe_Barry , thanks for your concern about this case .

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

vjtianmsft_0-1713516695919.png

The Dax function is shown below:

vjtianmsft_1-1713516771938.png

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.



View solution in original post

3 REPLIES 3
v-jtian-msft
Community Support
Community Support

Hi,@BIUser1998 .I'd be happy to help you.
@Dangar332 ,@Joe_Barry , thanks for your concern about this case .

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

vjtianmsft_0-1713516695919.png

The Dax function is shown below:

vjtianmsft_1-1713516771938.png

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.



Joe_Barry
Super User
Super User

Hi  @BIUser1998 

 

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)

 

 

Joe_Barry_0-1713508403699.png

 

 

Hope this helps

Joe

 

 

If you found my answer helpful and it solved your issue, please accept as solution

 

 

 

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


Dangar332
Super User
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

 

Dangar332_0-1713507677506.png

 



Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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