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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DaniBi92
New Member

DATEDIFF with values in different Rows and Fields

Hi,

is it possible to use a DATEDIFF formulas with values in different Rows and Fields(or another DAX formulas)?

For example, i 've the following Data:

ITEMSTATUSDATE1        DATE2
XXXReceipt  01/05/2021 
XXXDelivery          05/05/2021
YYYReceipt04/04/2021 
ZZZReceipt30/04/2021 
YYYDelivery         07/04/2021
ZZZDelivery         11/05/2021

The result that i need is the sum of the days difference by Item. In my exemple the result must be 18:

ITEMDATE1          DATE2RESULTS
XXX01/05/2021        05/05/20214
YYY04/04/2021        07/04/20213
ZZZ30/04/2021        11/05/202111
           RESULT:18

Is there a DAX formulas to achive this result?

Thanks in advance.

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @DaniBi92 

Please check the below picture and the sample pbix file's link down below.

All measures are in the sample b pbix file, and all steps are numbered in front of each measure.

 

Picture1.png

 

https://www.dropbox.com/s/4lwg972lhq9ki9q/danibi.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Fowmy
Super User
Super User

@DaniBi92 

You can create a DX table with the following code.  Click New Table under the Modeling tab and paste the code given below, rename the table name as per yours.

Result Table = 
ADDCOLUMNS(
    ADDCOLUMNS(
        VALUES(Table1[ITEM]),
        "DATE1", CALCULATE(MIN(Table1[DATE1])),
        "DATE2", CALCULATE(MIN(Table1[DATE2]))
    ),
    "RESULT", DATEDIFF([DATE1],[DATE2],DAY)
)

Fowmy_0-1621885943857.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Greg_Deckler
Community Champion
Community Champion

@DaniBi92 See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.