Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Previous Day Value

I have a date dimension table that has indicator column for working and non working days. The date dimension table has an active relationship with a report fact table. The report fact table consists ...
  • DataNinja777's avatar
    DataNinja777
    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,