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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
g_js
Regular Visitor

Comparing different times Data in same table

Hi,
I was looking into a problem where i need to find the when one column in the data was changed in the table.


Example-
Date                           Column1                          column2               

1/1/2021                       123                                      A                      

2/2/2021                       123                                      A

3/2/2021                       123                                      B

4/2/2021                       123                                      B

1/2/2021                       456                                      A

2/2/2021                       456                                      B
3/2/2021                       456                                      B


So for the above example i am looking for a way to find the date the column2 data was changed.
Like create new column3 filled with 1 at  row 3 and 6

Thanks for the help.



1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a column expression that gets that result.  I called the table "Change" so replace that with your actual table name.

 

Change From Previous =
VAR vThisDate = Change[Date]
VAR vPrevDate =
    CALCULATE (
        MAX ( Change[Date] ),
        ALLEXCEPT (
            Change,
            Change[ Column1]
        ),
        Change[Date] < vThisDate
    )
VAR vCurrent = Change[Column2]
VAR vPrevValue =
    CALCULATE (
        MIN ( Change[Column2] ),
        ALLEXCEPT (
            Change,
            Change[ Column1]
        ),
        Change[Date] = vPrevDate
    )
RETURN
    IF (
        OR (
            ISBLANK ( vPrevDate ),
            vCurrent = vPrevValue
        ),
        0,
        1
    )

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
g_js
Regular Visitor

Thanks for the help Pat

 

mahoneypat
Microsoft Employee
Microsoft Employee

Here is a column expression that gets that result.  I called the table "Change" so replace that with your actual table name.

 

Change From Previous =
VAR vThisDate = Change[Date]
VAR vPrevDate =
    CALCULATE (
        MAX ( Change[Date] ),
        ALLEXCEPT (
            Change,
            Change[ Column1]
        ),
        Change[Date] < vThisDate
    )
VAR vCurrent = Change[Column2]
VAR vPrevValue =
    CALCULATE (
        MIN ( Change[Column2] ),
        ALLEXCEPT (
            Change,
            Change[ Column1]
        ),
        Change[Date] = vPrevDate
    )
RETURN
    IF (
        OR (
            ISBLANK ( vPrevDate ),
            vCurrent = vPrevValue
        ),
        0,
        1
    )

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.