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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Percentage calculation

Hi everyone!

 

I would love some help with calculating the change in percentage.

 

In short, my dataset consists of Nike's stock closing price during 2020, the relevant attributes are "Date" and "Close price". In my dashboard, I have tried create a card in combination with a slicer displaying "between" dates. 

 

CJL8_0-1607901682422.png

 

What I want to display is basically the change in Nike's stock price from the chosen start date to the end date in the slicer, for example between 3/1-3/7 as seen in the picture. I have tried out different measures but dosen't seem to get it right. How is this done in the easiest way? 

 

Thanks on forehand!

 

 

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Not clear if you have a Date table or not, but the approach is similar.  Basically, you need to harvest the min/max dates selected in your slicer, calculate two variables (one for each), and then do the math.  Here is an example that assumes you have a single table with all your data.

 

Pct Change =
VAR vStartDate =
    MIN ( Table[Date] )
VAR vEndDate =
    MAX ( Table[Date] )
VAR vStartPrice =
    CALCULATE (
        MIN ( Table[Close] ),
        Table[Date] = vStartDate
    )
VAR vEndPrice =
    CALCULATE (
        MIN ( Table[Close] ),
        Table[Date] = vEndDate
    )
RETURN
    DIVIDE (
        vEndPrice - vStartPrice,
        vStartPrice
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

amitchandak
Super User
Super User

@Anonymous , prefer to use a date table

 


diff between selected range =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])
return
divide(calculate(max(table[close price]), filter('Date', 'Date'[Date] =_max)),calculate(max(table[close price]), filter('Date', 'Date'[Date] =_min)))-1

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

thank you both @mahoneypat and @amitchandak, it is working now!

 

 

amitchandak
Super User
Super User

@Anonymous , prefer to use a date table

 


diff between selected range =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])
return
divide(calculate(max(table[close price]), filter('Date', 'Date'[Date] =_max)),calculate(max(table[close price]), filter('Date', 'Date'[Date] =_min)))-1

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
mahoneypat
Microsoft Employee
Microsoft Employee

Not clear if you have a Date table or not, but the approach is similar.  Basically, you need to harvest the min/max dates selected in your slicer, calculate two variables (one for each), and then do the math.  Here is an example that assumes you have a single table with all your data.

 

Pct Change =
VAR vStartDate =
    MIN ( Table[Date] )
VAR vEndDate =
    MAX ( Table[Date] )
VAR vStartPrice =
    CALCULATE (
        MIN ( Table[Close] ),
        Table[Date] = vStartDate
    )
VAR vEndPrice =
    CALCULATE (
        MIN ( Table[Close] ),
        Table[Date] = vEndDate
    )
RETURN
    DIVIDE (
        vEndPrice - vStartPrice,
        vStartPrice
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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