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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
wes-shen-poal
Helper III
Helper III

days between previous date in a column based on condition of another column

Hi there,

 

I would like to create a new column, called Days_between_visits which calculates the number of days between a date in the ATA (Actual Time of Arrival) column and a previous date also in the ATA column, for each vessel in the VesselName column

 

For the first date of each vessel, Days_between_visits would be null as there is not previous date to calculate the difference with.

 

Is this possible? If so, please kindly assist with the DAX formula required the calculated column

 

Thanks,
Wes

 

Capture.JPG

1 ACCEPTED SOLUTION
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @wes-shen-poal

 

I think this calculated column might be close

 

New Column = 
VAR LastVisit = MAXX(
            FILTER(
                'Table',
                'Table'[VesselName] = EARLIER('Table'[VesselName]) && 
                'Table'[ATA] < EARLIER('Table'[ATA])),'Table'[ATA])
RETURN IF(LastVisit <> BLANK(),INT('Table'[ATA] - LastVisit))

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @wes-shen-poal

 

I think this calculated column might be close

 

New Column = 
VAR LastVisit = MAXX(
            FILTER(
                'Table',
                'Table'[VesselName] = EARLIER('Table'[VesselName]) && 
                'Table'[ATA] < EARLIER('Table'[ATA])),'Table'[ATA])
RETURN IF(LastVisit <> BLANK(),INT('Table'[ATA] - LastVisit))

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

@Phil_Seamark I found this solution very helpful, but I had 2 rows that did not return a value that should have. Do you know why this might of happened?

Hi @Phil_Seamark

 

This is perfect. Thank you so much for your help.

 

Wes

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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