Forum Discussion
Previous Day Value
- 1 year ago
Hi Anonymous ,
Yes, if you already have a DAX measure that calculates the stock price, you can incorporate it into other DAX calculations. For example, if you have a measure named Stock Price defined as SUM('StockData'[Price]), you can reference it in other formulas seamlessly.
To calculate the cumulative stock price over time, you could use a formula like:
Cumulative Stock Price = CALCULATE( [Stock Price], FILTER( ALL('DateTable'), 'DateTable'[Date] <= MAX('DateTable'[Date]) ) )This measure calculates the total stock price up to the current date within the visual's context. Similarly, if you want to rank stocks based on their price, you can create a measure such as:
Rank by Stock Price = RANKX( ALL('StockData'[StockName]), [Stock Price], , DESC, Dense )Here, the Stock Price measure is used to determine each stock's rank in descending order of price. For more advanced calculations, like finding the percentile rank of the stock price, you could write:
Percentile Rank Stock Price = DIVIDE( RANKX( ALL('StockData'[StockName]), [Stock Price], , ASC, Dense ) - 1, COUNTROWS(ALL('StockData'[StockName])), 0 )In this case, the Stock Price measure integrates into a formula to calculate how a stock's price compares to others. This approach allows your existing measure to be dynamically used within more complex calculations. Let me know if you need assistance with tailoring a specific scenario!
Best regards,
Hi Anonymous
My solution is a little different. I added another calculated column in the Date table that can be very useful. (I'm not sure how your working day indicator so it might need a small change.)
Working Day =
IF(
NOT WEEKDAY( 'Date'[Date], 2 ) IN { 6, 7 },
TRUE(),
FALSE()
)
Working Day Number =
RANKX(
FILTER(
'Date',
'Date'[Working Day]
),
'Date'[Date],
,
ASC
) - NOT 'Date'[Working Day]
Then the measure is pretty straight-forward.
PrevWorkingDayValue =
VAR _PrevDayNo = MAX( 'Date'[Working Day Number] ) - 1
RETURN
CALCULATE(
SUM( 'Table'[Amt] ),
ALL( 'Date' ),
'Date'[Working Day Number] = _PrevDayNo
)
Let me know if you have any questions.