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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
newtopbitoo
Frequent Visitor

visual calculation Previous in wrong column

Please have a look at my matrix.
Columns previous year and diff previous year are made with "Visual calculations"
The value previous year

previous year = PREVIOUS([count],columns,[YEAR]) is in the correct column.
The value diff prev year 
diff prev year = [Marketshare] - PREVIOUS([Marketshare],COLUMNS,[YEAR])
shows it's value under 2023 while it should be under 2024.
What is wrong in my formula
 
newtopbitoo_0-1731920769758.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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:

vfenlingmsft_0-1731998299698.png

 

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:

vfenlingmsft_1-1731998434486.png

 

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.

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

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:

vfenlingmsft_0-1731998299698.png

 

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:

vfenlingmsft_1-1731998434486.png

 

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.

 

newtopbitoo
Frequent Visitor

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


iff prev year3 = VAR CurrentMarketShare = [Marketshare]
VAR PreviousMarketShare = PREVIOUS ( [Marketshare], COLUMNS, [YEAR] ) RETURN
 
 IF ( NOT ( ISBLANK (PreviousMarketShare) ), CurrentMarketShare - PreviousMarketShare, BLANK () )
Unfortunately no values showed up at all.
newtopbitoo_0-1731923180640.png

 

Instead of ISBLANK (PreviousMarketShare) I tried ISBLANK (Previous year) too but that did not help.
 
Kedar_Pande
Super User
Super User

@newtopbitoo 

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

newtopbitoo_0-1731921983963.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors