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
Anonymous
Not applicable

Get value of a year's first date available

Hi community,

 

I want to calculate YTD and QTD rate of returns of an index. The calculation should be as follows: (Current Price - Reference Price) / Reference Price

Reference Price should be the first price given for the current year. The problem is that this does not always equals the date 01/01/YYYY.

My table does not contain rows with dates when there was no price. The question is therefore how I can get the price value for the first date available. For instance, here this would be the price corresponding to 02.01.2020.

example1.png

 

Same question if I want to search for the current quarter's first price available.

Thanks for any support.

 Regards.

1 ACCEPTED SOLUTION
Nathaniel_C
Super User
Super User

Hi @Anonymous ,

 

Please try this measure:

 

 

 

Index Value =
VAR CurYear =
    YEAR ( MAX ( 'Table'[DATE] ) )
VAR CurValue =
    MAX ( 'Table'[VALUE] )
VAR EarliestDate =
    CALCULATE ( MIN ( 'Table'[DATE] ), YEAR ( 'Table'[DATE] ) = CurYear )
VAR _minValue =
    CALCULATE ( MIN ( 'Table'[VALUE] ), 'Table'[DATE] = EarliestDate )
VAR indexValue = CurValue - _minValue
RETURN
    indexValue

 

Please see my data table and result below.  This checks for the year, and subtracts the value from the first date visible for that year from the current value.

index1.PNGindex.PNG

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

See if this article helps - LASTNONBLANK Explained - Excelerator BI.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Nathaniel_C
Super User
Super User

Hi @Anonymous ,

 

Please try this measure:

 

 

 

Index Value =
VAR CurYear =
    YEAR ( MAX ( 'Table'[DATE] ) )
VAR CurValue =
    MAX ( 'Table'[VALUE] )
VAR EarliestDate =
    CALCULATE ( MIN ( 'Table'[DATE] ), YEAR ( 'Table'[DATE] ) = CurYear )
VAR _minValue =
    CALCULATE ( MIN ( 'Table'[VALUE] ), 'Table'[DATE] = EarliestDate )
VAR indexValue = CurValue - _minValue
RETURN
    indexValue

 

Please see my data table and result below.  This checks for the year, and subtracts the value from the first date visible for that year from the current value.

index1.PNGindex.PNG

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.