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

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

Reply
Anonymous
Not applicable

Calculate Days Between Two Rows Based on Conditions from Other Columns

Table.JPG

I have a table called "Productivity".  In this table, I am attempting to calculate the number of days between "TRIAG" and "DIAGNOSIS", when the serial numbers match.  Any ideas?

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

can you try this code:

days diff = 
var _dia = 'Table data'[dated]
var _triag = CALCULATE( MIN('Table data'[dated]) , FILTER('Table data','Table data'[Serial.no] = EARLIER('Table data'[Serial.no])&& 'Table data'[wc-description] = "TRIAG"))
var _DIAG = CALCULATE( _dia , FILTER('Table data','Table data'[Serial.no] = EARLIER('Table data'[Serial.no])&& 'Table data'[wc-description] = "DIAGNOSIS"))
return 
DATEDIFF(_triag,_DIAG,DAY)
 

View solution in original post

4 REPLIES 4
AnthonyJoseph
Resolver III
Resolver III

Hi @Anonymous 

 

can you please try the calculated column:

days diff = 
var _st = 'Table data'[start_date]
var _traig = CALCULATE( _st , FILTER('Table data','Table data'[Serial.no] = EARLIER('Table data'[Serial.no])&& 'Table data'[wc-description] = "TRIAG"))
var _DIAG = CALCULATE( _st , FILTER('Table data','Table data'[Serial.no] = EARLIER('Table data'[Serial.no])&& 'Table data'[wc-description] = "DIAGNOSIS"))
return 
DATEDIFF(_traig,_DIAG,DAY)

 

 

AnthonyJoseph_0-1663789683314.png

 

Thanks,

AnthonyJoseph

Anonymous
Not applicable

 
days diff =
var _st = 'PRODUCTIVITY'[DATED]
var _TRIAG = CALCULATE( _st , FILTER('PRODUCTIVITY','PRODUCTIVITY'[SERIAL_NO] = EARLIER('PRODUCTIVITY'[SERIAL_NO])&& 'PRODUCTIVITY'[WC_DESCRIPTION] = "TRIAG"))
var _DIAG = CALCULATE( _st , FILTER('PRODUCTIVITY','PRODUCTIVITY'[SERIAL_NO] = EARLIER('PRODUCTIVITY'[SERIAL_NO])&& 'PRODUCTIVITY'[WC_DESCRIPTION]= "DIAGNOSIS"))
return
DATEDIFF(_TRIAG,_DIAG,DAY)

 

 

I modified the formula slightly to the parameters suggested, but it did not work.  In the attached example, it is showing the days elapsed having been 0, when a day has passed between the two actions.

 

Table2.JPG

Hi @Anonymous 

 

can you try this code:

days diff = 
var _dia = 'Table data'[dated]
var _triag = CALCULATE( MIN('Table data'[dated]) , FILTER('Table data','Table data'[Serial.no] = EARLIER('Table data'[Serial.no])&& 'Table data'[wc-description] = "TRIAG"))
var _DIAG = CALCULATE( _dia , FILTER('Table data','Table data'[Serial.no] = EARLIER('Table data'[Serial.no])&& 'Table data'[wc-description] = "DIAGNOSIS"))
return 
DATEDIFF(_triag,_DIAG,DAY)
 

Hi @Anonymous  screenshot below:

AnthonyJoseph_0-1663792627186.png

 

if this output is incorrect, can you share the expected output in table format so me to help better...

 

Thanks,

AnthonyJoseph

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.