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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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