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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
yforti
Helper II
Helper II

Help with calculated dates

Hi guys!

I am having a calculation problem for the difference in dates between the steps of my data model.

 

Here's the model:

 

testete.JPG

 

I need to calculate the difference in dates between each step, for that I made a measure that didn't work entirely. 

 

Measure created: 

ac.JPG

This measure works when I don't use the step in the vision:

acaca.JPG

We can see above that the calculation is done correctly between the dates.

When I use the step in the table the calculation stops happening:

adasdasdas.JPG

 

Can someone help me solve this problem?

 

1 ACCEPTED SOLUTION

@yforti 

you can try to create a column

Column = 
VAR last=maxx(FILTER('Table','Table'[DT_atualizacao]<EARLIER('Table'[DT_atualizacao])&&'Table'[personalizar]=EARLIER('Table'[personalizar])),'Table'[DT_atualizacao])
return if(ISBLANK(last),0,'Table'[DT_atualizacao]-last)

1.PNG





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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
ryan_mayu
Super User
Super User

@yforti 

please  try this

Measure = 
var last=maxx(FILTER(all('Table'),'Table'[DT_atualizacao]<SELECTEDVALUE('Table'[DT_atualizacao])),'Table'[DT_atualizacao])
return if(ISFILTERED('Table'[DT_atualizacao]),if(ISBLANK(last),0,SELECTEDVALUE('Table'[DT_atualizacao])-MAXX(FILTER(all('Table'),'Table'[DT_atualizacao]=last),'Table'[DT_atualizacao])),CALCULATE(max('Table'[DT_atualizacao]),all('Table'))-CALCULATE(MIN('Table'[DT_atualizacao]),ALL('Table')))

1.PNG





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

Proud to be a Super User!




@ryan_mayu 
Almost!

Now, the only thing that is still wrong is that we are calculating a difference in days for the start date of the process.

See below:

 
 

fff.JPGSince day 23/07/2019 is the first day of the process, we should not calculate the previous day. 
I think it would be zero.

 

@yforti 

 

Measure =
var last=maxx(FILTER(all('Table'),'Table'[DT_atualizacao]<SELECTEDVALUE('Table'[DT_atualizacao])),'Table'[DT_atualizacao])
return if(ISFILTERED('Table'[DT_atualizacao]),if(ISBLANK(last),0,SELECTEDVALUE('Table'[DT_atualizacao])-MAXX(FILTER(all('Table'),'Table'[DT_atualizacao]=last),'Table'[DT_atualizacao])),CALCULATE(max('Table'[DT_atualizacao]),all('Table'))-CALCULATE(MIN('Table'[DT_atualizacao]),ALL('Table')))

 

In the DAX, iI checked if it is the earliest date, if it is , then display 0. please have a try.

 





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

Proud to be a Super User!




@ryan_mayu

I used your mesure, see below:

ddd.JPGIs this because there is more data in the model? See below: (this is my full model)

ggg.JPG
aaaaa.JPG

@yforti 

you can try to create a column

Column = 
VAR last=maxx(FILTER('Table','Table'[DT_atualizacao]<EARLIER('Table'[DT_atualizacao])&&'Table'[personalizar]=EARLIER('Table'[personalizar])),'Table'[DT_atualizacao])
return if(ISBLANK(last),0,'Table'[DT_atualizacao]-last)

1.PNG





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

Proud to be a Super User!




@yforti 

 

Measure =
var last=maxx(FILTER(all('Table'),'Table'[DT_atualizacao]<SELECTEDVALUE('Table'[DT_atualizacao])),'Table'[DT_atualizacao])
return if(ISFILTERED('Table'[DT_atualizacao]),if(ISBLANK(last),0,SELECTEDVALUE('Table'[DT_atualizacao])-MAXX(FILTER(all('Table'),'Table'[DT_atualizacao]=last),'Table'[DT_atualizacao])),CALCULATE(max('Table'[DT_atualizacao]),all('Table'))-CALCULATE(MIN('Table'[DT_atualizacao]),ALL('Table')))

 

In the DAX, iI checked if it is the earliest date, if it is , then display 0. please have a try.

 





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

Proud to be a Super User!




Helpful resources

Announcements
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.