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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
renanpinheiro
Helper I
Helper I

I calculate with the previous line

Hello,
I have the following table:

Capturar.PNG

 

I need to do a calculation, decreasing the date of one line by the date of another line (from the second by the first, the third by the second, and so on ...).

Can someone help me?

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @renanpinheiro,

 

You can try to use dax formula to achieve your requirement:

 

Measure:

Date Diff =
var currDate=max(DIM_SOLICITANTE[DATA_ALTERACAO])
var temp=MAXX(FILTER(ALL(DIM_SOLICITANTE),[DATA_ALTERACAO]<currDate),[DATA_ALTERACAO])
var prevDate=ifif(prevDate=Blank(),currDate,prevDate)
Return
DATEDIFF(prevDate,currDate,Minute)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @renanpinheiro,

 

You can try to use dax formula to achieve your requirement:

 

Measure:

Date Diff =
var currDate=max(DIM_SOLICITANTE[DATA_ALTERACAO])
var temp=MAXX(FILTER(ALL(DIM_SOLICITANTE),[DATA_ALTERACAO]<currDate),[DATA_ALTERACAO])
var prevDate=ifif(prevDate=Blank(),currDate,prevDate)
Return
DATEDIFF(prevDate,currDate,Minute)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft,
The third variable you created "prevDate" is wrong. I can not do the IF you said.
I can not play the same variable inside the IF.

Hi @renanpinheiro,


The formula should be like this: (sorry for dupliated "if" typing)

 

Date Diff =
var currDate=max(DIM_SOLICITANTE[DATA_ALTERACAO])
var temp=MAXX(FILTER(ALL(DIM_SOLICITANTE),[DATA_ALTERACAO]<currDate),[DATA_ALTERACAO])
var prevDate=if(prevDate=Blank(),currDate,prevDate)
Return
DATEDIFF(prevDate,currDate,Minute)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
MFelix
Super User
Super User

hI @renanpinheiro,

 

First of all add an index column to you data, this will help with further calculations thenadd a custom column with the formula below:

 

 

if 
[Index] = 0 then 0 else 
if Index{[Index]-1}[WORKORDERID] = [WORKORDERID] then 
[DATA_ALTERACAO]- Index{[Index]-1}[DATA_ALTERACAO]
else 0

 

Then format the resulting column as duration.

 

Making the breakdown:

 

Index

Name of the step you want to get the numbers from (I named the Index column step with this name)

[Index]-1}

[Index] - Field index that allow to do a subtation to get the number we want so [Index]-1  gives us previous row

if [Index]= 0 then 0

Return 0 in first row instead of error

 

if Index{[Index]-1}[WORKORDERID] = [WORKORDERID] then

 This allows you to have this calculation made for several workorders so once the workorder changes it goes back to 0.

 

To be aware you need to have the table sorted by WorkorderId and then by Data_alteracao

 

Regards,

 

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.