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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.