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
Anmol
Frequent Visitor

Using Earlier() command for lag

I am having a hard time to get a expected output on a calculated column, i know how to get it through sql though using window function(lag). Here is the sql command:

 

select 

 (select lag(input_priority) over (partition by task_id order by task_id, request_datetime) as prv_input_priority

, input_priority

, convert(date, request_datetime) as dateField 

from task_log 

 

This will sort the data first on 'Task id' and then on 'request_datetime', after which will print the previous value of 'input_priority'.

 

On DAX i'm trying Earlier(), but having a very hard time to get the expected output.

 

 

 

1 ACCEPTED SOLUTION

HI @Anmol ,

 

Let me know  if this works for you.

 

 

1.jpg

 

Create Calculated Columns

 

Previous_Value = CALCULATE(
MAX('Table'[Input_Priority]),
FILTER('Table','Table'[Task_Id] = EARLIER('Table'[Task_Id]) && 'Table'[Request_DateTime] < EARLIER('Table'[Request_DateTime] )))
 
 
RANK_ = RANKX(
FILTER('Table',
'Table'[Task_Id] = EARLIER('Table'[Task_Id])
),
'Table'[Request_DateTime] 
,,ASC,Dense)
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

View solution in original post

3 REPLIES 3
AlB
Community Champion
Community Champion

Hi @Anmol 

Can you show a sample of the table you are using and explain with an example based on that data/table what you would need?

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Anmol
Frequent Visitor

log.PNG

That's how the data looks like, im just looking for a calculated column that gives previous 'input_priority' only after sorting the data on 'task_id' and 'request_datetime'.

HI @Anmol ,

 

Let me know  if this works for you.

 

 

1.jpg

 

Create Calculated Columns

 

Previous_Value = CALCULATE(
MAX('Table'[Input_Priority]),
FILTER('Table','Table'[Task_Id] = EARLIER('Table'[Task_Id]) && 'Table'[Request_DateTime] < EARLIER('Table'[Request_DateTime] )))
 
 
RANK_ = RANKX(
FILTER('Table',
'Table'[Task_Id] = EARLIER('Table'[Task_Id])
),
'Table'[Request_DateTime] 
,,ASC,Dense)
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

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.