Skip to main content
cancel
Showing results for 
Search instead 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

Reply
BIUser1998
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

 

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
Solution Specialist
Solution Specialist

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

 

 

 

 

 

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
Fabcon_Europe_Social_Bogo

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 Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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