Xid Xid
Xid Xid

Reputation: 15

Same column Date difference based on other field DAX POWER BI

I want to calculate the date difference for all values in Field1 based on Field2 for example datediff(3/1/2020-2/1/2020) based on Field2 (c-b).

I have tried several ways but no luck so far.

Input Table

Upvotes: 1

Views: 2247

Answers (2)

Umut K
Umut K

Reputation: 1388

there is no minimum mentioned in the question, so i assume that you are looking for the difference of the previous stages.

Date Difference =
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] < EARLIER ( 'Table'[Date] )
                && EARLIER ( 'Table'[Field1] ) = 'Table'[Field1]
        )
    ),
    'Table'[Date],
    DAY
)

Upvotes: 1

Ozan Sen
Ozan Sen

Reputation: 2615

You can obtain a solution by adding 2 calculated columns:

First Calculated Column:

MinDate =
CALCULATE (
    MIN ( YourTable[Date] ),
    ALLEXCEPT ( YourTable, YourTable[Field1] )
)

2nd Calculated Column:

Date_Difference =
DATEDIFF ( [MinDate], [Date], DAY )

End Result:

2_Calculated_Column

Upvotes: 0

Related Questions