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
lawada4
Frequent Visitor

return value based on the last date in the date slicer filter

im trying to calculate return on investement for a stock . the formula is : (initial price-currentprice)/initial price

 the user wants to know how his return on investment is changing over time. i created a measure to show the 

last price for the stock based on the last date in the date slicer filter but it's not working properly

last date close =
var last_date=MAX('stocks data'[Date])
return
CALCULATE(SUM('stocks data'[Close]),'stocks data'[Date]=last_date)
 
result:
lawada4_0-1671017859200.png

 

i want the measure to only return the value 144.49 for the maximum selected date in the filter :12-12-2022

another example :

 i changed date period to 5-1-2022 ->7-25-2022

lawada4_1-1671018066908.png

 the measure in this case should return price 140.82 for last date in the selected range 7-25-2022

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @lawada4 ,

Please update the formula of measure [last date close] as below and you can get the correct result... You can find the details in the attachment.

last date close = 
var last_date=CALCULATE(MAX('stocks data'[Date]),ALLSELECTED('stocks data'))
return
CALCULATE(SUM('stocks data'[Close]),'stocks data'[Date]=last_date)

yingyinr_0-1671072568006.png

Best Regards

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

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @lawada4 ,

Please update the formula of measure [last date close] as below and you can get the correct result... You can find the details in the attachment.

last date close = 
var last_date=CALCULATE(MAX('stocks data'[Date]),ALLSELECTED('stocks data'))
return
CALCULATE(SUM('stocks data'[Close]),'stocks data'[Date]=last_date)

yingyinr_0-1671072568006.png

Best Regards

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

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.