cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

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

Accepted Solutions
Phil_Seamark Super Contributor
Super Contributor

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

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!

3 REPLIES 3
Phil_Seamark Super Contributor
Super Contributor

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

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!

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

Hi @Phil_Seamark

 

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

 

Wes

bennettbroussar Frequent Visitor
Frequent Visitor

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

@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?

Helpful resources

Announcements
Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

Top Ideas
Users Online
Currently online: 248 members 3,060 guests
Please welcome our newest community members: