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
mtrevisiol
Helper V
Helper V

Days between two dates in different rows

Hi everyone,

I've got a table that contains the price list of some products that my company buys from a certain supplier:

mtrevisiol_0-1646139912233.png

For each item there are the start date and the end date of the price shown in the line (31/12/2099 means the the price is currently valid).

My goal is to find out if there are any gaps between dates, so I need to calculate, for each item, the difference between the ValidityEndingDate and the next ValidityStartingDate:

 

mtrevisiol_2-1646140392672.png

 

Here is the PBIX file: https://www.dropbox.com/s/3q2rldzekcbjsh3/Days%20between%20dates.pbix?dl=0

I hope it's all clear. Thank you.

 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

A calculated column in DAX:

ColumnZ = var _item = 'Table'[Item]
var _endDate = 'Table'[ValidityEndingDate]
RETURN
CALCULATE(MIN('Table'[ValidityStartingDate]), FILTER('Table', 'Table'[Item] = _item && 'Table'[ValidityStartingDate] > _endDate))

You can then use DATEDIFF in another column to get the days between the column and the ending date.

I haven't really tested it so please do that.

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

A calculated column in DAX:

ColumnZ = var _item = 'Table'[Item]
var _endDate = 'Table'[ValidityEndingDate]
RETURN
CALCULATE(MIN('Table'[ValidityStartingDate]), FILTER('Table', 'Table'[Item] = _item && 'Table'[ValidityStartingDate] > _endDate))

You can then use DATEDIFF in another column to get the days between the column and the ending date.

I haven't really tested it so please do that.

That's great @HotChilli ! I've created this column:

 

Days between pricelists =
var _item = 'Table'[Item]
var _endDate = 'Table'[ValidityEndingDate]
var _next_date = CALCULATE(MIN('Table'[ValidityStartingDate]), FILTER('Table', 'Table'[Item] = _item && 'Table'[ValidityStartingDate] >= _endDate))
RETURN DATEDIFF('Table'[ValidityEndingDate], _next_date, DAY)

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.