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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

DATEDIFF Difference (in a Row context iterator)

Hello,

 

I have a table like this:

NAME 			COURSE				COMPONENT	     DATE_COMPLETED
==========		=========			===========	     ===============
John Doe 1		Course	1			Component 1			Date 1
John Doe 1		Course	1			Component 2     		Date 2
John Doe 1		Course	1			Component 3     		Date 3
John Doe 1		Course	1			Component 4     		Date 4
John Doe 2  		Course  2			Component 1     		Date 5
John Doe 2  		Course  2			Component 2     		Date 6
John Doe 2  		Course  2			Component 3     		Date 7
John Doe 2  		Course  2			Component 4     		Date 8
John Doe 3  		Course  1			Component 1     		Date 9
John Doe 3  		Course  1			Component 2     		Date 10
John Doe 3  		Course  1			Component 3     		Date 11
John Doe 3  		Course  1			Component 4     		Date 12

 

 and my desired output needs to 

Name				COMPLETION_DAYS
=====				===========================
John Doe 1			DATEDIFF(Date 4,Date 1,DAYS)
John Doe 2			DATEDIFF(Date 5,Date 8,DAYS)
John Doe 2			DATEDIFF(Date 9,Date 12,DAYS)

Basically, what I need to do is to use an iterator in a row context that checks a specific critera (e.g name, course). Once matched it would calculate the difference between the component 1 and 4 dates.

 

I think the other apprach would be to extract to tables (One for component 1 and the other for component 4) and just subtract the difference there, but any other suggestions are welcome.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous try this measure, drop table visual, put name and MyDate (following measure) in values and you are good to go.

 

MyDate = 
VAR startDate = 
CALCULATE( MIN( Table[Date_Completed] ),
ALLEXCEPT( Table, Table[Name] )
)
VAR endDate = 
CALCULATE( MAX( Table[Date_Completed] ),
ALLEXCEPT( Table, Table[Name] )
)
RETURN
DATEDIFF(endDate, startDate, DAY)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
d_gosbell
Super User
Super User

You could do this in a calculated column with something like the following:

 

Total Course Days = 
var _currentName = Table1[Name]
var _currentCourse = Table1[Course] 
var _comp1Date = LOOKUPVALUE(Table1[Date_Completed], Table1[Name], _currentName, Table1[Course], _currentCourse,Table1[Component], "Component 1")
var _comp4Date = LOOKUPVALUE(Table1[Date_Completed], Table1[Name], _currentName, Table1[Course], _currentCourse,Table1[Component], "Component 4")
var _days = DATEDIFF(_comp1Date,_comp4Date, DAY)
return _days

This will repeat the total course days for every component within the one course and name. Or if you wanted you could wrap the DATEDIFF in an IF to only return a value for the first or last component.

 

You could probably also write this logic in a measure, but then you would have to aggregate the days across multiple courses somehow with something like a Sum or Average and you would not get the 2 "John Doe 2" lines.

 

 

parry2k
Super User
Super User

@Anonymous try this measure, drop table visual, put name and MyDate (following measure) in values and you are good to go.

 

MyDate = 
VAR startDate = 
CALCULATE( MIN( Table[Date_Completed] ),
ALLEXCEPT( Table, Table[Name] )
)
VAR endDate = 
CALCULATE( MAX( Table[Date_Completed] ),
ALLEXCEPT( Table, Table[Name] )
)
RETURN
DATEDIFF(endDate, startDate, DAY)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.