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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Justiy
Regular Visitor

Getting previous row value - Problem Blanks

Hello,

I am trying to retrive the previous value of a row, using the knowledge I read from other posts about this topic.

But, the data I get is incorrect. I dont understand why. 

 

My table name is Data, and it has the following columns:

- I for Index. Running number (1,2,3,...)

- Number of sales

I want to calculate: Number of sales [I] - Number of sales [I-1], for each row

 

This is the dax I am using:

 

Sales Gr=
var Cur_Index = MAX(Data[I])
var Pre_Index = Cur_Index-1
var Pre_Value = CALCULATE( MAX(Data[Sales]),FILTER(Data, Data[I] = Pre_Index))
var Cur_Value = CALCULATE( MAX(Data[Sales]),FILTER(Data, Data[I] = Cur_Index))
Return
Cur_Value-Pre_Value
 
I Noticed that the Pre_Value returns blanks , while Cur_Value  returnes correct values. This is the cause of the problem.
Why is that ?
 
Thanks for your help
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Justiy ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

 

Sales Gr =
VAR Cur_Index =
    MAX ( Data[data] )
VAR Pre_Index = Cur_Index - 1
VAR Pre_Value =
    CALCULATE (
        MAX ( Data[Sales] ),
        FILTER ( ALL ( Data ), Data[data] = Pre_Index )
    )
VAR Cur_Value =
    CALCULATE (
        MAX ( Data[Sales] ),
        FILTER ( ALL ( Data ), Data[data] = Cur_Index )
    )
RETURN
    Cur_Value - Pre_Value

 

vpollymsft_0-1665626920320.png

If I have misunderstood your meaning, please provide more details with your desired output and pbix file without  priavcy information.

 

Best Regards

Community Support Team _ Polly

 

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
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with.  Do you have a Date column in your dataset?  Do you want a calculated column or a mesure solution?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Justiy ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

 

Sales Gr =
VAR Cur_Index =
    MAX ( Data[data] )
VAR Pre_Index = Cur_Index - 1
VAR Pre_Value =
    CALCULATE (
        MAX ( Data[Sales] ),
        FILTER ( ALL ( Data ), Data[data] = Pre_Index )
    )
VAR Cur_Value =
    CALCULATE (
        MAX ( Data[Sales] ),
        FILTER ( ALL ( Data ), Data[data] = Cur_Index )
    )
RETURN
    Cur_Value - Pre_Value

 

vpollymsft_0-1665626920320.png

If I have misunderstood your meaning, please provide more details with your desired output and pbix file without  priavcy information.

 

Best Regards

Community Support Team _ Polly

 

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

Yes it works. Thanks.

My problem was that I needed to add to my filter - ALL() as you did.

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.