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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Pete37
Frequent Visitor

Dynamic % return calculation based on selected date

Dear PBI users,

I've recently started using Power BI Desktop and after a few more or less successful simple visualizations I've stucked with something more complex. My inputs are closing share prices for several companies (the same date range for each). Capture.JPG

 

Capture 2.JPG

What I need to do right now is to present % return for every day in a date range (I mean (Closing price at Day X,Y,Z divided by the first Closing price in a selected date range)-1). For example if the first day is 12 January 2017 (share price is 10) and days X and Y are let's say 20 January 2017 (share price is 12) and 29 January (share price is 13) I would like to get simple arithmetic return of 20% and 30% respectively.

It would be fantastic if I could adjust first date using a slicer (e.g. change from 12 January 2017 to other date) and arithmetic return would recalculate (for each date in a date range) using new "first date".

At the end of the day I would like to present the line chart with returns for all companies for a selected date range.

Please find below the snapshot of something that I would like to achieve.

Capture3.JPG

I would be really grateful for any suggestion.

12 REPLIES 12
Anonymous
Not applicable

@Pete37,

Create a calendar table using DAX below.

date = CALENDAR(DATE(2017;1;1);DATE(2018;12;31))

Create the following measures in your sheet1 table.

selectedvalue = MAX('date'[Date])

BASELINE_VALUE =
CALCULATE(
SUM('sheet1'[Closing Price]);
FILTER(ALL('sheet1'[Date]);'sheet1'[Date]=[selectedvalue]
))

MEASURE_VALUE = SUM('sheet1'[Closing Price])

Closing price % difference = DIVIDE([MEASURE_VALUE] -[BASELINE_VALUE];[BASELINE_VALUE])


And please note that use date field in the calendar table to create slicer.

Regards,

Lydia

@Anonymous

Thanks for your response. I am afraid that I did something wrong because it doesn't work. Please look at the screenshot below.

Pete37
Frequent Visitor

screen 1.JPG

Anonymous
Not applicable

@Pete37

Do you need to select data range or single date value in the date slicer? And do you use Date field of calendar table to create the slicer?

Regards,
Lydia

@Anonymous

I need a range to present it on the line chart. Yes I use Calendar Table to create the slicer.

Anonymous
Not applicable

@Pete37,


Change BASELINE_VALUE to the following:

BASELINE_VALUE = 
CALCULATE(
SUM('sheet1'[Closing price]);
FILTER(ALL('sheet1'[Date]);'sheet1'[DATE]<=MAX('date'[Date]) && 'sheet1'[Date]>=MIN('date'[Date])
))



Regards,
Lydia

@Anonymous

The new function has too few arguments. I am not sure how to fix it.

Formula.JPG

Anonymous
Not applicable

@Pete37,

I miss ")" after ALL() function, please check DAX below.

BASELINE_VALUE = CALCULATE( SUM('sheet1'[Closing price]); FILTER(ALL('sheet1'[Date]);'sheet1'[DATE]<=MAX('date'[Date]) && 'sheet1'[Date]>=MIN('date'[Date]) ))

Regards,

Lydia

@Anonymous

 

Unfortunately it still doesn't work 😞 All lines on the chart should start from 0 as at 2017-01-12

Capture.JPG

Anonymous
Not applicable

@Pete37,

Could you please share your PBIX file to me? I will check it in my environment. And you can share your PBIX file via Private Message.

Regards,
Lydia

Is there anyone else who could help me with this issue?

Pete37
Frequent Visitor

Dear All,

I found a quick measure that is pretty close to what I am looking for:

 

Closing price % difference from 2017-01-12 =
VAR __BASELINE_VALUE =
CALCULATE(
SUM('sheet1'[Closing price]);
'sheet1'[Date] IN { DATE(2017; 1; 12) }
)
VAR __MEASURE_VALUE = SUM('sheet1'[Closing price])
RETURN
IF(
NOT ISBLANK(__MEASURE_VALUE);
DIVIDE(__MEASURE_VALUE - __BASELINE_VALUE; __BASELINE_VALUE)

)

As you may see the major drawback of this solution is that I can't change the date of reference (2017-01-12 in this case). Could you help me to make this formula date-flexible?

return.JPG

Thanks in advance!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors