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
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.
Solved! Go to Solution.
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.
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.
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.
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.
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)
Hope this helps
Joe
If you found my answer helpful and it solved your issue, please accept as solution
Proud to be a Super User! | |
Date tables help! Learn more
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
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
33 | |
16 | |
13 | |
10 | |
8 |
User | Count |
---|---|
59 | |
20 | |
12 | |
11 | |
10 |