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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
archerjayden
Helper I
Helper I

DAX Row minus Previous Row

Hi,

I am looking for help on achieving moving range from data.

How do I get DAX to subtract row by previous row?

I am working on SQL Server direct query mode and unable to crack this for my report.

Please advise and kindly refer to excel sample data and formula below I’ve tried.

 

 

[TotalQty] =
                 Divide(SUM([delivered_quantity]),SUM([req_quantity]),0)

PreviousRowSubtract = 
                  ([TotalQty]) - CALCULATE ( 
        
      SUMX([delivered_quantity])/SUMX([req_quantity])*100,FILTER([Date]=dateadd([Date],-1,Day)))

 

 

Column D is what I am trying to achieve this would have other filter contexts like Year, MonthNum, WeekNum and Weekday in the form of Slicers

 

Many thanks

Archer

Sample DataSample Data

4 REPLIES 4
Fowmy
Super User
Super User

@archerjayden 

This could work:

Column = 
VAR _DATE = 'Table'[A]
VAR _LASTDATE = 
    CALCULATE(
        MAX('Table'[A]),
        FILTER('Table','Table'[A] < _DATE)
    )
RETURN
[B]
-
CALCULATE(
    MAX([C]),FILTER('Table','Table'[A] = _LASTDATE))

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

amitchandak
Super User
Super User

@archerjayden , try as new column

 

new colum =
var _date = maxx( filter(Table,[date] <earlier([date])),[Date])
return
[total qty] - maxx( filter(Table,[date] = _date)),[total qty])

 

//prefer this if you have continuous date

new colum =
[total qty] - maxx( filter(Table,[date] = earlier([date])-1),[total qty])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak  thanks for your approach! I am using Direct query and function Earlier doesnt work no matter how I tried? would you happen to know an alternative approach for the same please? 

 

PS : I can't even add an Index column from PQ

@archerjayden , You have to day on day time intelligence using date table (or prefer date table)

 

You can use previousday function

sum(Table[Total Qty]) - calculate(Table[Total Qty]) ,previousday ('Date'[Date] ) )

 

Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

 

 

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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