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
mgcchkn
Frequent Visitor

Percent deviation from previous value

IndexNameTest DateTest StatusTest DurationCurrent TestPrevious Test
331891John8/10/2022APPROVED24200 
331892John5/4/2022APPROVED2471 
331893John7/6/2022APPROVED241066 
331894John6/17/2022APPROVED24228 
331895John9/17/2020APPROVED24113 

 

Above is my sample data.

 

I'm trying to figure out percentage of deviation from previous test.  I can't even figure out how to get the previous test to show up in the Previous Test column.  Ultimately, there would be a 8th column that had the percentage of deviation.

 

As you can see, the index column is missing some numbers because of filtering.  So these tests are for a particular "student" which is filtered via a drill through with a measure called "selected_student."  (selected_student = var selected_student = SELECTEDVALUE(student[name]) return "Test History for Student: " & UNICHAR(10) & selected_student)

 

Thanks in advance! I've been working on this and googling it for 2 days and can't figure it out.

1 ACCEPTED SOLUTION

Hi, @mgcchkn 

Take a try formula like below:

Previous Test = 
VAR _PreviousTestDate =
    CALCULATE (
        MAX ( Student[Test Date] ),
        FILTER (
            ALL ( Student ),
            Student[Name] = MAX ( Student[Name] )
                && Student[Test Date] < MAX ( Student[Test Date] )
        )
    )
RETURN
    CALCULATE (
        MAX ( Student[Current Test] ),
        FILTER (
            ALL ( Student ),
            Student[Name] = MAX ( Student[Name] )
                && Student[Test Date] = _PreviousTestDate
        )
    )
Percenatge = DIVIDE(MAX(Student[Current Test])-[Previous Test],[Previous Test])

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
mgcchkn
Frequent Visitor

I figured it out, but it takes forever for it to load now.  It takes between 60-90 seconds.

Hi, @mgcchkn 

Take a try formula like below:

Previous Test = 
VAR _PreviousTestDate =
    CALCULATE (
        MAX ( Student[Test Date] ),
        FILTER (
            ALL ( Student ),
            Student[Name] = MAX ( Student[Name] )
                && Student[Test Date] < MAX ( Student[Test Date] )
        )
    )
RETURN
    CALCULATE (
        MAX ( Student[Current Test] ),
        FILTER (
            ALL ( Student ),
            Student[Name] = MAX ( Student[Name] )
                && Student[Test Date] = _PreviousTestDate
        )
    )
Percenatge = DIVIDE(MAX(Student[Current Test])-[Previous Test],[Previous Test])

Best Regards,
Community Support Team _ Eason

That worked great!  Thank you!!!

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.