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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.