Forum Discussion

RettT's avatar
RettT
Regular Visitor
1 year ago
Solved

Faster measure to sum the total inventory for the minimum chosen date from a slicer

I'm just trying to have the user be able to select two dates with a slicer and show the sum of the inventory on the starting date and another measure to show the ending date. This can be accomplished...
  • Greg_Deckler's avatar
    Greg_Deckler
    1 year ago

    RettT You can try this:

    Starting inv date = 
      VAR __Date = MIN( 'Daily Inventory'[Date] )
      VAR __Table = FILTER( 'Daily Inventory', 'Daily Inventory'[Date] = __Date )
      VAR __Result = SUMX( __Table, [Qty OH] * [Average Cost (TS)] )
    RETURN
      __Result
    
    Ending inv date = 
      VAR __Date = MAX( 'Daily Inventory'[Date] )
      VAR __Table = FILTER( 'Daily Inventory', 'Daily Inventory'[Date] = __Date )
      VAR __Result = SUMX( __Table, [Qty OH] * [Average Cost (TS)] )
    RETURN
      __Result

    I've seen CALCULATE get jammed up with single table data models and create inefficient query plans. I have also seen where having all of the code in the same measure speeds things up. No guarantees though.