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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply

Date difference based on condition

Hello Community,

Can you please provide your suggestion?

I have two tables and they both have one to one relationship.My requirements is that I want to match ID on both table and if ID will match then I want to AVERAGE DAY DIFFERENCE.

I have tried below formula but I am not getting any result.

Calculated Column=

If (table a[id]=table b[id],average(datediff(table a[date],table b[date],day))

Here is my dataset.

Thanks

Table-A

ID

Date

A

15/06/2020

B

29/04/2020

 

Table-B

ID

Date

A

15/06/2020

C

21/04/2020

D

27/02/2020

 

 

1 ACCEPTED SOLUTION

Hi @tejapowerbi123 , 

You could try below measure and refer to my sample for details

Measure 2 = IF(MIN(TA[ID])=MIN(TB[ID]), DATEDIFF(MIN(TA[DATE]), MIN(TB[DATE]), DAY), BLANK())

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
parry2k
Super User
Super User

@tejapowerbi123 not very clear what would be the output, if there are dates in two tables and it is one row and what would be the average, isn't it is just a datediff? why you are using average?



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.

Hi Parry,

Thank you so much for your suggestion.

Please ignore AVERAGE,I am looking for day difference and it is not working.

Do you have any suggestion for me?

Thanks

 

@tejapowerbi123 try this, assuming you are adding a new column in Table A, if you are adding a new column in Table B then use RELATED function with Table A

 

Date Difference = If (table a[id]=RELATED(table b[id]),datediff(table a[date],RELATED(table b[date]),day))

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

 



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.

Hi Parry,

Formula is working fine but still i am not getting any result.

What i found in TABLE B date column has multiple blank (Date is not available).

Do you think because of that i am not getting right result.

Thanks

 

@tejapowerbi123 of course if it is a blank date, you will not get the result. I cannot speak about your data, you have to test the logic where a date is available, not sure what else to say.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



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.

Thank you so much Parry.I can not change date column.Do you think do i have any other option.

@tejapowerbi123 not sure what you mean? You have to tell what would be the business logic if there is no date.



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.

if id column match on table a and table then i want table a [date]-table b [date].That is the logic.

Hi @tejapowerbi123 , 

You could try below measure and refer to my sample for details

Measure 2 = IF(MIN(TA[ID])=MIN(TB[ID]), DATEDIFF(MIN(TA[DATE]), MIN(TB[DATE]), DAY), BLANK())

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.