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

Measure calculating change as of "x" date

I have date column, a value column (stock), and I want to calculate the change in Stock as of a certain date.
For example, if the certain date is 21 Jan 2020, I would like to have a measure that allows me to see how much "stock" changes each day, relative to 21 Jan 2020.

 

I tried using the formula:

Change as of = 
VAR PriceAsOf = CALCULATE(SUM(Query1[stock]), YEAR(Query1[value_date]) = 2020 && MONTH(Query1[value_date]) = 1 && DAY(Query1[value_date]) = 21)

Return
SUM(Query1[stock]) - PriceAsOf

However, there seems to be an issue. It seems that it only manages to get the value for 21 Jan 2020 correct, which is 0. But it didnt work for the other dates after 21 Jan 2020.

mathiasljy_0-1601623881603.png

Essentially, I would like the measure to perform (SUM(stock) @ whichever date) - (SUM(stock) @ 21 Jan 2020)

Thanks for your help guys!

1 ACCEPTED SOLUTION

@Anonymous , your formula should work as a measure

 

Change as of =
VAR PriceAsOf = CALCULATE(SUM(Query1[stock]), Query1[value_date] = date(2020,01,02))
Return
SUM(Query1[stock]) - PriceAsOf

 

or with date slicer

Change as of =
var _min = maxx(allselcted(date), date[date])
VAR PriceAsOf1 = CALCULATE(SUM(Query1[stock]), Query1[value_date] = _min)
Return
SUM(Query1[stock]) - PriceAsOf

 

Can you share a  sample pbix after removing sensitive data.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Not very clear

 

You  can try like for two dates

Change as of =
VAR PriceAsOf = CALCULATE(SUM(Query1[stock]), Query1[value_date] = date(2020,01,21))
VAR PriceAsOf1 = CALCULATE(SUM(Query1[stock]), Query1[value_date] = date(2020,01,22))
Return
PriceAsOf1 - PriceAsOf

 

You can try like for two dates from slicer . I assumed indepedent date slicer and taking start and end date of range
Change as of =
var _min = maxx(allselcted(date), date[date])
var _max = maxx(allselcted(date), date[date])
VAR PriceAsOf = CALCULATE(SUM(Query1[stock]), Query1[value_date] = _min)
VAR PriceAsOf1 = CALCULATE(SUM(Query1[stock]), Query1[value_date] = _max)
Return
PriceAsOf1 - PriceAsOf

Anonymous
Not applicable

Hi @amitchandak 

Ok to put it simply for example:

mathiasljy_0-1601625428609.png

I essentially would like a measure that is able to perform what the column "Stock Change as of 2 Jan 2020" does.
Take Stock at whichever date, minus, stock at a certain date (e.g. 2 Jan 2020).

Is that clearer?

Thank you!

@Anonymous , your formula should work as a measure

 

Change as of =
VAR PriceAsOf = CALCULATE(SUM(Query1[stock]), Query1[value_date] = date(2020,01,02))
Return
SUM(Query1[stock]) - PriceAsOf

 

or with date slicer

Change as of =
var _min = maxx(allselcted(date), date[date])
VAR PriceAsOf1 = CALCULATE(SUM(Query1[stock]), Query1[value_date] = _min)
Return
SUM(Query1[stock]) - PriceAsOf

 

Can you share a  sample pbix after removing sensitive data.

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.