Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculating totals without row context limiting data

I've been attempting to find a solution for this for a while now and haven't been able to.

 

I'm trying to get the values for the Equipment_Days2 column to read:

14    associated with equipment_qty of 4                 (Only including days with qty 4)

17    associated with equipment_qty of 1                 (Including days with qty 4, 2 or 1)

15    associated with equipment_qty of 2                 (Including days with qty 2 or 4)

 

 

 

Underlying Data

 

The ALL filter functionality below does not appear to be stripping away the qty row filter in the calculation so that all of the rows associated with the equipment are included in the sum for DaysValue.  How can this be done?

 

Equipment_Days2 = Calculate(SUM(CalculatedDaysTable[DaysValue]),FILTER( ALL(CalculatedDaysTable), CalculatedDaysTable[job_no] == earlier(CalculatedDaysTable[job_no]) && CalculatedDaysTable[Equipment No and Description] == Earlier(CalculatedDaysTable[Equipment No and Description]) && CalculatedDaysTable[date_ASCII] == Earlier(CalculatedDaysTable[date_ASCII]) && CalculatedDaysTable[equipment_uom] == "Daily" && CalculatedDaysTable[equipment_qty] <= Earlier(CalculatedDaysTable[equipment_qty])))
  • This might get you a bit closer.

    Equipment_Days2 =
    VAR CurrQty = CalculatedDaysTable[equipment_qty]
    RETURN
        CALCULATE (
            SUM ( CalculatedDaysTable[DaysValue] ),
            CalculatedDaysTable[equipment_qty] <= CurrQty,
            CalculatedDaysTable[equipment_uom] = "Daily"
        )

     

    You used ALL on the entire table, which removes the context from all columns. I'd recommend only using it for specific columns unless you really do want to get rid of all the filtering.

4 Replies

  • This might get you a bit closer.

    Equipment_Days2 =
    VAR CurrQty = CalculatedDaysTable[equipment_qty]
    RETURN
        CALCULATE (
            SUM ( CalculatedDaysTable[DaysValue] ),
            CalculatedDaysTable[equipment_qty] <= CurrQty,
            CalculatedDaysTable[equipment_uom] = "Daily"
        )

     

    You used ALL on the entire table, which removes the context from all columns. I'd recommend only using it for specific columns unless you really do want to get rid of all the filtering.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Unfortunately this results in the exact same output as I've been continuously getting, with the additions not being cumulative.

     

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      If you're trying to do this as a calculated column, then you have to get the context exactly right. Either remove filters on all the columns you don't want or remove all filters except for a specific set of columns you do want.

       

      I can't tell what all columns you have in your table, so I can't do much more than an educated stab in the dark and you'll have to adjust it to fit your particular table.

    • Anonymous's avatar
      Anonymous
      Not applicable

      This formulation did work once it was converted to a measure.

       

      Equipment_Days = VAR CurrQty = max(CalculatedDaysTable[equipment_qty])
      RETURN
      CALCULATE (
      SUM (CalculatedDaysTable[DaysValue]),
      CalculatedDaysTable[equipment_qty] >= CurrQty &&
      CalculatedDaysTable[equipment_uom] = "Daily"
      )
       
      Thank you for pointing me in the right direction.