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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Celso
Advocate I
Advocate I

How to create a measure that returns the most recent value of a stock

Hello,

 

I have a table that looks similar to this. I want to create a measure that returns the most recent value and I want it to be responsive with my date selection. Thank you.

 

table.PNG

1 ACCEPTED SOLUTION

You should be able to get there from here:

 

CategoriesLatest = SUMMARIZE(Categories,Categories[Product Category],"Transacation Date",MAX(Categories[Transaction Date]),"Value",CALCULATE(SUM(Categories[Value ($)]),FILTER(Categories,Categories[Transaction Date]=MAX(Categories[Transaction Date]))))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

You would want to create a measure using MAX([Transaction Date]). Not entirely sure what you are going for here but you could you could use this in a CALCULATE for [Value ($)] for example.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

My goal is to create measure maybe for a card that displays the total value. The value would be the total of last value of the stock (in the example on 104 for Gold Mining A, 57 for Invest Co and 122 for Airline A). 

I also want to use the Transaction date column as a slicer that when I select July I'm only seeing the total of Gold Mining A and Invest Co. 

Create a measure that extracts the latest Date for your context:

MaxDate = CALCULATE(MAX(Stock[Date]),  ALLEXCEPT(Stock,Stock[Category]) )

and a measure that summarizes Value based on MaxDate:

SumStockValue = CALCULATE(SUM(Stock[Value]), FILTER(ALLSELECTED(Stock),Stock[Date] = [MaxDate]))

 

This assumes you have only one row per date and category. The measures will respect the context created by any selection (by slicer for example) based on [Date].

You should be able to get there from here:

 

CategoriesLatest = SUMMARIZE(Categories,Categories[Product Category],"Transacation Date",MAX(Categories[Transaction Date]),"Value",CALCULATE(SUM(Categories[Value ($)]),FILTER(Categories,Categories[Transaction Date]=MAX(Categories[Transaction Date]))))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.