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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.