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
Jphillips
Regular Visitor

How can I get the values from a measure for previous date to do math on the next date?

While I understand measures don't actually exist like columns, my need here is to get the value of a measure from the date/row before current, and get the absolute delta between the two. This is for a moving range of a z score.

Jphillips_0-1637169067105.png

 

Above is my current measure DAX. I attempted to create a virtual table. [Z] is a measure using a couple of other measures and columns.

[Z] is calculated as:

 

IF([r3_den_total] < 1,BLANK(),
DIVIDE( ([r3%] - [Average R3%] ),SQRT(([Average R3%] * (1-[Average R3%]))/[r3_den_total]) )
)

 

 

As you can see in the table visual, [Prev Day Z] is returning blank.

 

My desired output would look like:

DateR3%ZPrev Day Z
2021-07-2060.71%1.034 
2021-07-2155.56%0.7821.034
2021-07-2251.18%0.0530.782

 

I've been hung up on this for a couple of weeks now, and any help or guidance would be immmeasurable!

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Jphillips 

 

It is difficult to write DAX measure without enough context, just based on your sample and your not working [Prev Day Z], your dates are consecutive, right? You may try this, please modify the Table name and Column name accordingly, AND pls provide some sample data in a format which people can copy in the future

test = 
VAR PreDate=SELECTEDVALUE('yourTable'[Date])-1
VAR T1=ADDCOLUMNS(
       ALLSELECTED('yourTable'[Date]),"z1",[Z])
RETURN
MAXX(FILTER(T1,[Date]=PreDate),[z1])

 

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Jphillips 

 

It is difficult to write DAX measure without enough context, just based on your sample and your not working [Prev Day Z], your dates are consecutive, right? You may try this, please modify the Table name and Column name accordingly, AND pls provide some sample data in a format which people can copy in the future

test = 
VAR PreDate=SELECTEDVALUE('yourTable'[Date])-1
VAR T1=ADDCOLUMNS(
       ALLSELECTED('yourTable'[Date]),"z1",[Z])
RETURN
MAXX(FILTER(T1,[Date]=PreDate),[z1])

 

@Vera_33  This worked beautifully. I'd actually come up with the below yesterday, but it doesnt seem to calculate correctly, but your query is much cleaner and easy to read. Thank you so much!

Perf R3 MR = 
VAR __prevR3 =
    CALCULATE ('Performance Measures'[r3%], PREVIOUSDAY('Calendar'[Date]) 
    ) 
var __prevR3den =
    CALCULATE('Performance Measures'[r30_den_total], PREVIOUSDAY('Calendar'[Date])
    ) 
var __avgR3 = 
    CALCULATE( Performance[Average R3%], ALLSELECTED(Performance)
    )

RETURN ABS(  IF( __prevR3den < 1 ,BLANK(),
    DIVIDE( (__prevR3 - __avgR3 ),SQRT((__avgR3 * (1- __avgR3 ))/ __prevR3den) )
    ) - [R3 Z] )

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.

Top Solution Authors