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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Paldren
New Member

Finding the change of a column value since last non-unique date

I have a table that looks a lot like this:

[TimeStamp][ProjectID][Score]
01/15/2022PRJ01

10

01/15/2022PRJ021000
01/15/2022PRJ031
01/14/2022PRJ0114
01/14/2022PRJ02999
01/14/2022PRJ032
01/13/2022PRJ018
01/13/2022PRJ02989
01/13/2022PRJ031

 

I want to calculate the change in [Score] of [ProjectID] from previous [TimeStamp] and put it into a custom column like this:

[Change Since Previous Entry]
4
1
-1
6
10
1
<blank>
<blank>
<blank>

 

But I am at a complete loss on where to start.

1 ACCEPTED SOLUTION
Jos_Woolley
Solution Sage
Solution Sage

Hi,

Assuming your table is named 'MyTable', this Calculated Column:

Column =
VAR TimeStamp = MyTable[TimeStamp]
VAR ProjectID = MyTable[ProjectID]
VAR PreviousTimeStamp =
    CALCULATE(
        MAX( MyTable[TimeStamp] ),
        FILTER(
            MyTable,
            MyTable[ProjectID] = ProjectID
                && MyTable[TimeStamp] < TimeStamp
        )
    )
RETURN
    IF(
        ISBLANK( PreviousTimeStamp ),
        BLANK(),
        MyTable[Score]
            - CALCULATE(
                MIN( MyTable[Score] ),
                FILTER(
                    MyTable,
                    MyTable[ProjectID] = ProjectID
                        && MyTable[TimeStamp] = PreviousTimeStamp
                )
            )
    )

Regards

View solution in original post

2 REPLIES 2
Jos_Woolley
Solution Sage
Solution Sage

Hi,

Assuming your table is named 'MyTable', this Calculated Column:

Column =
VAR TimeStamp = MyTable[TimeStamp]
VAR ProjectID = MyTable[ProjectID]
VAR PreviousTimeStamp =
    CALCULATE(
        MAX( MyTable[TimeStamp] ),
        FILTER(
            MyTable,
            MyTable[ProjectID] = ProjectID
                && MyTable[TimeStamp] < TimeStamp
        )
    )
RETURN
    IF(
        ISBLANK( PreviousTimeStamp ),
        BLANK(),
        MyTable[Score]
            - CALCULATE(
                MIN( MyTable[Score] ),
                FILTER(
                    MyTable,
                    MyTable[ProjectID] = ProjectID
                        && MyTable[TimeStamp] = PreviousTimeStamp
                )
            )
    )

Regards

Thank you. I was lost with the calculation of the PreviousTimestamp. Was trying to find a way to do it by index of a DISCRETE([TimeStamp]) and that obviously doesn't work.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.