Forum Discussion

Wonter's avatar
Wonter
Frequent Visitor
2 years ago
Solved

Inventory Level for every day, also dates with no row entry

Hi all,   I have a question about the inventory levels. I've tried so many different options, but nothing worked yet. I'm looking for a way to visualise every day in a table with for every day the ...
  • DataInsights's avatar
    2 years ago

    Wonter,

     

    Try this measure. It requires a date table with a 1:* relationship with the fact table HistoricalInventory. In the visual, use Dates[Date].

     

    Minimum Stock = 
    VAR vCurrentDate =
        MIN ( Dates[Date] )
    VAR vPreviousDate =
        CALCULATE (
            MAX ( HistoricalInventory[history_date] ),
            Dates[Date] < vCurrentDate
        )
    VAR vFilterPreviousDate =
        TREATAS ( { vPreviousDate }, Dates[Date] )
    VAR vStockPreviousDate =
        CALCULATE ( MAX ( HistoricalInventory[stock] ), vFilterPreviousDate )
    VAR vResult =
        IF (
            // if Dates[Date] does not exist in HistoricalInventory, use the last value
            ISEMPTY ( HistoricalInventory ),
            vStockPreviousDate,
            MAX ( HistoricalInventory[stock] )
        )
    RETURN
        vResult

     

     

  • DataInsights's avatar
    DataInsights
    2 years ago

    Wonter,

     

    Thanks for the link. I found the issue. The variable vPreviousDate in the measure needs to use date, not historical_date (the relationship with DateTable is based on date, not historical_date.

     

    VAR vPreviousDate =
        CALCULATE (
            MAX ( kiosks_historicalkioskarticle[date] ),
            DateTable[Date] < vCurrentDate
        )