The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Please have a look at my matrix.
Columns previous year and diff previous year are made with "Visual calculations"
The value previous year
Solved! Go to Solution.
Thanks for Kedar_Pande's concern about this issue.
Hi, @newtopbitoo
I am glad to help you.
Since you didn't give specific datasets for testing, I assumed some datasets myself:
I don't know if you have to use the Previous function, in my tests I didn't use that function and recreated two Measure:
previous year =
DIVIDE(
SUM('Table'[count]),
CALCULATE(
SUM('Table'[count]),
ALLEXCEPT('Table', 'Table'[Year])
),
0
)
diff prev year =
VAR _CurrentYear = 2024
VAR _PreviousYear = 2023
VAR _CurrentYearPercentage =
CALCULATE(
[previous year],
FILTER('Table', 'Table'[Year] = _CurrentYear)
)
VAR _PreviousYearPercentage =
CALCULATE(
[previous year],
FILTER('Table', 'Table'[Year] = _PreviousYear)
)
RETURN
IF(
MAX('Table'[Year]) = _PreviousYear,
0,
_CurrentYearPercentage - _PreviousYearPercentage
)
Finally I got the result you need:
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for Kedar_Pande's concern about this issue.
Hi, @newtopbitoo
I am glad to help you.
Since you didn't give specific datasets for testing, I assumed some datasets myself:
I don't know if you have to use the Previous function, in my tests I didn't use that function and recreated two Measure:
previous year =
DIVIDE(
SUM('Table'[count]),
CALCULATE(
SUM('Table'[count]),
ALLEXCEPT('Table', 'Table'[Year])
),
0
)
diff prev year =
VAR _CurrentYear = 2024
VAR _PreviousYear = 2023
VAR _CurrentYearPercentage =
CALCULATE(
[previous year],
FILTER('Table', 'Table'[Year] = _CurrentYear)
)
VAR _PreviousYearPercentage =
CALCULATE(
[previous year],
FILTER('Table', 'Table'[Year] = _PreviousYear)
)
RETURN
IF(
MAX('Table'[Year]) = _PreviousYear,
0,
_CurrentYearPercentage - _PreviousYearPercentage
)
Finally I got the result you need:
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
DataNinja777 answered to this topic but the answer does not show here, he said:
The issue with your formula for calculating diff prev year arises because the PREVIOUS function evaluates the value in the column corresponding to the previous year but does not inherently adjust where the result should be displayed. To correct this behavior, you need to adjust the calculation or approach to ensure the difference appears in the correct column
Instead of ISBLANK (PreviousMarketShare) I tried ISBLANK (Previous year) too but that did not help.
Updated DAX for diff prev year
diff prev year =
VAR CurrentMarketShare = [Marketshare]
VAR PreviousMarketShare =
PREVIOUS([Marketshare], COLUMNS, [YEAR])
RETURN
CurrentMarketShare - PreviousMarketShare
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
Difference with my formula is that you first make variables, but actually it's the same with my formula isn't it ?
The results are the same too