Forum Discussion

powerbiusernew's avatar
powerbiusernew
Regular Visitor
6 years ago
Solved

How do I calculate the duration between dates based on "items" and "operations"?

Hi all   I have a table as shown below, which has users and the items they loan or returns as well as the dates. How do I calculate the durations between say User A which loan Item 1 and return Ite...
  • v-diye-msft's avatar
    v-diye-msft
    6 years ago

    Hi powerbiusernew 

     

    It seems I have nailed it! please kindly check this one:

    Every duration appeared in the return date.

    Measure 2 = var loandate = CALCULATE(MAX('Table (3)'[Date]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Users],'Table (3)'[Item]),[Operations]="Loan"&&[Date]<=MAX('Table (3)'[Date])))
    var returndate = MAX('Table (3)'[Date])
    Return
    CALCULATE(DATEDIFF(loandate,returndate,DAY),ALLEXCEPT('Table (3)','Table (3)'[Item],'Table (3)'[Users]))

    Or you'd like to get this one:

     

    Measure 2 = var loandate = CALCULATE(MAX('Table (3)'[Date]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Users],'Table (3)'[Item]),[Operations]="Loan"&&[Date]<=MAX('Table (3)'[Date])))
    var returndate = MAX('Table (3)'[Date])
    Return
    CALCULATE(DATEDIFF(loandate,returndate,DAY),ALLEXCEPT('Table (3)','Table (3)'[Item],'Table (3)'[Users]))
    Measure 3 = var  returndate = CALCULATE(min('Table (3)'[Date]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Users],'Table (3)'[Item]),[Operations]="return"&&[Date]>=MAX('Table (3)'[Date])))
    var loandate = MAX('Table (3)'[Date])
    Return
    CALCULATE(DATEDIFF(loandate,returndate,DAY),ALLEXCEPT('Table (3)','Table (3)'[Item],'Table (3)'[Users]))
    Measure 4 = [Measure 2]+[Measure 3]