Forum Discussion
Help with Conditional formula to compare two rows from a third column
- 5 years ago
Hi, Anonymous
Please correct me if I wrongly understood your question.
please check the below, that is for the Calculated Column.
Battery START Column =
VAR currentID = Data[CustomerID]
VAR previousdatetime =
CALCULATE (
MAX ( Data[DateTime] ),
FILTER (
Data,
Data[DateTime] < EARLIER ( Data[DateTime] )
&& Data[CustomerID] = currentID
)
)
RETURN
COALESCE (
CALCULATE (
SUM ( Data[BatteryLVL] ),
FILTER (
Data,
Data[DateTime] = previousdatetime
&& Data[CustomerID] = currentID
)
),
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.
Hello Anonymous ,
First, create an Index column in Power Query using this link.
Create a calculated column using the below Dax.
Battery Start =
VAR Customer = Battery[CustomerID]
VAR CurrentIndex = Battery[Index]
VAR BatteryStart =
CALCULATE (
MAX ( Battery[Battery Level] ),
FILTER (
Battery,
Battery[CustomerID] = Customer
&& Battery[Index] = CurrentIndex - 1
)
)
RETURN
IF ( Customer = Customer && CurrentIndex = 1, 0, BatteryStart )