SOLVED

Excel count changes based on criteria and date

Copper Contributor

Hi all,

 

Could anyone help me with the following?

 

I am looking for a formula to be able to count changes based on a criteria and date.

For example: ID is A01 and this person is located at Loc1 since 28/04/2022, but on 03/05/2022 it was moved to Loc6 and the calculation needs to show 1.

 

I would really appreciate it if anyone could help me solve this puzzle in Excel and in Power BI using DAX.

 

IDLocationDateCalculation
A01Loc128/04/2022 
A01Loc129/04/2022 
A01Loc130/04/2022 
A01Loc101/05/2022 
A01Loc102/05/2022 
A01Loc603/05/20221
A01Loc604/05/2022 
B02Loc428/04/2022 
B02Loc429/04/2022 
B02Loc430/04/2022 
B02Loc201/05/20221
B02Loc202/05/2022 
B02Loc203/05/2022 
B02Loc204/05/2022 

 

Thank you!

5 Replies

@sabirguiri 

Here is a simple Excel formula solution.

Assuming that ID is in cell A1, enter the following formula in D2:

 

=IF(AND(A2=A1,B2<>B1),1,"")

 

Fill or copy down.

@Hans Vogelaar 

Hi Hans, this works perfectly... thank you so much for solving this so quickly. I appreciate it!
Any suggestions on how to do in Power BI DAX?

@sabirguiri 

I'll have to leave that for someone else, sorry.

best response confirmed by sabirguiri (Copper Contributor)
Solution

@sabirguiri 

That could be

=
VAR currentID = Table1[ID]
VAR currentLocation = Table1[Location]
VAR currDate = Table1[Date]
VAR previousDate =
    CALCULATE (
        MAX ( Table1[Date] ),
        ALLSELECTED ( Table1 ),
        Table1[ID] = currentID,
        Table1[Date] < currDate
    )
VAR previousLocation =
    CALCULATE (
        VALUES ( Table1[Location] ),
        ALLSELECTED ( Table1 ),
        Table1[ID] = currentID,
        Table1[Date] = previousDate
    )
RETURN
    IF (
        ISBLANK ( previousLocation ),
        BLANK (),
        IF (
            previousLocation <> currentLocation,
            1,
            BLANK ()
        )
    )

here

image.png

This is absolutely awesome! Thank you so much for your work!
Instead of 1 in row 6 and 11 is it possible to move one prior to be in row 5 and row 10?
1 best response

Accepted Solutions
best response confirmed by sabirguiri (Copper Contributor)
Solution

@sabirguiri 

That could be

=
VAR currentID = Table1[ID]
VAR currentLocation = Table1[Location]
VAR currDate = Table1[Date]
VAR previousDate =
    CALCULATE (
        MAX ( Table1[Date] ),
        ALLSELECTED ( Table1 ),
        Table1[ID] = currentID,
        Table1[Date] < currDate
    )
VAR previousLocation =
    CALCULATE (
        VALUES ( Table1[Location] ),
        ALLSELECTED ( Table1 ),
        Table1[ID] = currentID,
        Table1[Date] = previousDate
    )
RETURN
    IF (
        ISBLANK ( previousLocation ),
        BLANK (),
        IF (
            previousLocation <> currentLocation,
            1,
            BLANK ()
        )
    )

here

image.png

View solution in original post