Forum Discussion

PatrickLamoste's avatar
6 years ago
Solved

Calculate - Sum with Multiple Criteria

Hello,

 

I am working on a rather tricky SQL table (see below) and now I am in a pickle.

 

I am trying to get the total hours without adding the values before the latest CARRYFORWARD action (11/25/2019).  The formula goes: Row 10 plus Row 11 to 14 minus Row 15. The result should be 277.63. It would be great if the measure can work with a slicer.

 

Thank you so much!

 

 

 

 

 

 

 

 

 

 

 

 

Data Source:

 

Row NumberAccrual TypeEffective DateActionHours
1Banked Time11/11/2019CARRYFORWARD181.88
2Banked Time15/11/2019GRANT6.75
3Banked Time17/11/2019GRANT21.00
4Banked Time18/11/2019GRANT10.50
5Banked Time19/11/2019GRANT6.00
6Banked Time20/11/2019GRANT11.25
7Banked Time21/11/2019GRANT6.00
8Banked Time22/11/2019GRANT12.00
9Banked Time24/11/2019GRANT17.25
10Banked Time25/11/2019CARRYFORWARD272.63
11Banked Time25/11/2019GRANT3.00
12Banked Time26/11/2019GRANT4.50
13Banked Time27/11/2019GRANT3.00
14Banked Time28/11/2019GRANT1.50
15Banked Time29/11/2019TAKEN-7.00

 

  • Perhaps something along the lines of:

     

    Measure = 
      VAR __Max = MAXX(FILTER('Table',[Action] = "CARRYFORWARD"),[Row Number])
    RETURN
      SUMX(FILTER('Table',[Row Number] >= __Max),[Hours])
    

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Perhaps something along the lines of:

     

    Measure = 
      VAR __Max = MAXX(FILTER('Table',[Action] = "CARRYFORWARD"),[Row Number])
    RETURN
      SUMX(FILTER('Table',[Row Number] >= __Max),[Hours])
    
    • PatrickLamoste's avatar
      PatrickLamoste
      Icon for Helper I rankHelper I

      Thank you for this!

       

      I ended up splitting the table and changed the formula a little bit and added a USERELATIONSHIP so I can limit the max date according to my slicer.

       

       

      Measure = 
        VAR __Max = MAXX(FILTER('Table',[Action] = "CARRYFORWARD"),[Effective Date])
      RETURN
        CALCULATE(SUMX(FILTER('Table',[Effective Date] >= __Max),[Hours]), USERELATIONSHIP([Effective Date],DateDim[Date]))      

       

       

      Thanks again!