cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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

1 ACCEPTED SOLUTION
Employee

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))```

Proud to be a Datanaut!

3 REPLIES 3
Employee

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))```

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?

Helper III

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

Wes

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors