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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
mike87
Frequent Visitor

Calculating changes on daily data

Hi, 

 

I am trying to create a measure that calculates the daily change for a stock price. I have tried to use LASTDATE function, but for some wierd reason, it turns out December 31th 2017 instead of the date today.  The MAX function turns out the same result, but MAXX gives me the correct one (November 2nd 2017). However, MAXX is formatted as text, and I am not able to format it back to date. 

 

The data set does not contain any rows after november 2nd. I presume that LASTDATE for some reason interpret the year part of the date instead of day. 

 

I will add new data every day, and I want to create a measure that I can show in a card visualisation with daily changes. Either actual changes or percentage. Anyone any idea of how to sort out the lastdate?

 

The data is structured like this:

Column 1: Stock price
Column 2: Date

1 ACCEPTED SOLUTION

Hi @mike87

 

Try this MEASURE.
File attached here as well

PriceChange =
VAR LastPirce =
    CALCULATE (
        VALUES ( Table1[Stock Price] ),
        FILTER ( Table1, Table1[Date] = MAX ( Table1[Date] ) )
    )
VAR SecondLastDate =
    CALCULATE (
        MAX ( Table1[Date] ),
        FILTER ( Table1, Table1[Date] < MAX ( Table1[Date] ) )
    )
RETURN
    LastPirce
        - CALCULATE ( VALUES ( Table1[Stock Price] ), Table1[Date] = SecondLastDate )

 

 

View solution in original post

6 REPLIES 6
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @mike87,

 

How did you try it? They are working fine in my test. You'd better create a new date table to work with time intelligence functions.

calendar =
CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2017, 12, 31 ) )

The daily change formula could be like this:

DailyChange =
VAR yesterday =
    CALCULATE ( MIN ( 'table'[Stock Price] ), PREVIOUSDAY ( 'calendar'[date] ) )
RETURN
    DIVIDE ( yesterday, MIN ( 'table'[Stock Price] ), 0 )

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your reply Dale.

 

I haven't used variables that much yet. I do not get the correct numbers, but it seems as the time intelligence function actually work with your approach.

 

Do you get the correct change? 

 

Hi @mike87,

 

Yes, I usually use it in such scenario. That could depend on your data model and the visual you create. Can you share your pbix file?

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jiascu-msft

 

I have uploaded a couple of images from the data set and the dashboard.

 

It is simple stock data with closing price and dates. 

 

 

dashEX.PNGNorwegian numbers with comma as decimals separatorsNorwegian numbers with comma as decimals separators

Hi @mike87

 

Try this MEASURE.
File attached here as well

PriceChange =
VAR LastPirce =
    CALCULATE (
        VALUES ( Table1[Stock Price] ),
        FILTER ( Table1, Table1[Date] = MAX ( Table1[Date] ) )
    )
VAR SecondLastDate =
    CALCULATE (
        MAX ( Table1[Date] ),
        FILTER ( Table1, Table1[Date] < MAX ( Table1[Date] ) )
    )
RETURN
    LastPirce
        - CALCULATE ( VALUES ( Table1[Stock Price] ), Table1[Date] = SecondLastDate )

 

 

Thank you @Zubair_Muhammad.

That worked perfectly

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.