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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
NaiduNaidu
New Member

Get % between current and prev rows

Hi All,

 

I have below data and I need to get % diff for current row and previous row and also show first row as 0 if there is no previous row.

Here my year column is in string datatype.

NaiduNaidu_0-1737343010572.png

 

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @NaiduNaidu ,

Ypu can achieve your goal following these steps:
1- Create a new calculated column for sortYear using this DAX:

SortYear = VALUE(SUBSTITUTE('Table'[Year], "F", ""))

2- Now create a new measure for % Diff by this DAX:

% Diff = 
VAR CurrentSales = MAX('Table'[Sales])
VAR CurrentYear = MAX('Table'[SortYear])
VAR PreviousSales = 
    CALCULATE(
        MAX('Table'[Sales]),
        FILTER(
            ALL('Table'),
            'Table'[SortYear] = CurrentYear - 1
        )
    )
RETURN
IF(
    ISBLANK(PreviousSales),
    0,
    DIVIDE(CurrentSales - PreviousSales, PreviousSales)
)

3- Now drag and drop the % Diff measure for your Matrix, your result will look like this:

Bibiano_Geraldo_0-1737367686058.png

 

 

Is this post help you? Please consider to:

Accept as Solution!
Give a Kudo
Follow me on Linkedin

View solution in original post

3 REPLIES 3
Bibiano_Geraldo
Super User
Super User

Hi @NaiduNaidu ,

Ypu can achieve your goal following these steps:
1- Create a new calculated column for sortYear using this DAX:

SortYear = VALUE(SUBSTITUTE('Table'[Year], "F", ""))

2- Now create a new measure for % Diff by this DAX:

% Diff = 
VAR CurrentSales = MAX('Table'[Sales])
VAR CurrentYear = MAX('Table'[SortYear])
VAR PreviousSales = 
    CALCULATE(
        MAX('Table'[Sales]),
        FILTER(
            ALL('Table'),
            'Table'[SortYear] = CurrentYear - 1
        )
    )
RETURN
IF(
    ISBLANK(PreviousSales),
    0,
    DIVIDE(CurrentSales - PreviousSales, PreviousSales)
)

3- Now drag and drop the % Diff measure for your Matrix, your result will look like this:

Bibiano_Geraldo_0-1737367686058.png

 

 

Is this post help you? Please consider to:

Accept as Solution!
Give a Kudo
Follow me on Linkedin

Ilya_K
Frequent Visitor

You can try "Visual calculations".

For that select "..." on the table right top corner, select "Visual calculations" and "Versus Previous".
In popped up formula, indicate "Sales" column.

Ilya_K_0-1737366577776.png

 

Ritaf1983
Super User
Super User

Hi @NaiduNaidu 
You can use Offset function to get a desired result :

Previous row sales diff %=
var sales_= sum('Table'[Sales])
var prev = CALCULATE(sum('Table'[Sales]), OFFSET(-1, ALLSELECTED('Table'[Year]), ORDERBY ('Table'[Year], ASC)) )+0
RETURN
DIVIDE((sales_-prev),prev)
Ritaf1983_0-1737365727417.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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