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
CaveOfWonders
Helper IV
Helper IV

SQL Lag to DAX measure

Hi All,

 

Could someone please help me recreate the below SQL into a DAX measure.

The SQL is returning the previous Actual Date from the previous ReportingDate Partitioned by the ProjectID and ProjectMilestoneID.

 

 

 

 

SELECT 
  P.ProjectID,
  P.Actual,
  P.ReportingDate,
  P.ProjectMilestoneID,
  LAG(P.Actual) OVER (
    PARTITION BY P.ProjectID, P.ProjectMilestoneID
    ORDER BY P.ReportingDate
  ) AS PreviousActual
FROM Project AS P

 

 

 

 

 Here is the Output in SQL. I've highlighted one example at the bottom where project ID = 181 and Project Milestone ID = 3 it pulls back the previous actual date based on the previous reporting date
SQL example.png

 

Sample Table:

ProjectID ActualDate ReportingDate Project Milestone ID
18219-May-2202-Mar-231
18108-Mar-2302-Mar-231
18101-Mar-2323-Feb-231
18219-May-2223-Feb-231
18101-Mar-2316-Feb-231
18219-May-2216-Feb-231
18219-May-2209-Feb-231
18116-Feb-2309-Feb-231
18116-Feb-2302-Feb-231
18219-May-2202-Feb-231
18109-Feb-2326-Jan-231
18219-May-2226-Jan-231
18103-May-2302-Mar-232
18202-Jun-2202-Mar-232
18228-Apr-2223-Feb-232
18106-Mar-2323-Feb-232
18228-Apr-2216-Feb-232
18106-Mar-2316-Feb-232
18121-Feb-2309-Feb-232
18228-Apr-2209-Feb-232
18121-Feb-2302-Feb-232
18228-Apr-2202-Feb-232
18228-Apr-2226-Jan-232
18114-Feb-2326-Jan-232
181 02-Mar-233
182 02-Mar-233
18202-Jun-2223-Feb-233
18129-Mar-2323-Feb-233
18202-Jun-2216-Feb-233
18129-Mar-2316-Feb-233
18202-Jun-2209-Feb-233
18116-Mar-2309-Feb-233
18202-Jun-2202-Feb-233
18116-Mar-2302-Feb-233
18109-Mar-2326-Jan-233
18202-Jun-2226-Jan-233
1 REPLY 1
Tahreem24
Super User
Super User

@CaveOfWonders Try to use OFFSET and INDEX dax.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

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.