Forum Discussion

Mich_J's avatar
Mich_J
Frequent Visitor
6 years ago
Solved

Cumulative total between two dates in monthly allocation

Hello, I m trying to figure out formula to display monthly total between two dates for one record. Data sample:

CUSTOMERSTART DATEEND DATEMONTHLY GP
9955527/01/202027/04/202010
9977809/01/202027/08/202020
9981601/04/202027/10/202015
711115/04/202027/10/202010
714710/04/202031/12/202015
71501/04/202027/08/202030

 

Result should be

CUSTOMERSTART DATEEND DATEMONTHLY GP2020-012020-022020-032020-042020-052020-062020-072020-082020-092020-102020-112020-12
9955527/01/202027/04/20201010101010        
9977809/01/202027/08/2020202020202020202020    
9981601/04/202027/10/202015   15151515151515  
711115/04/202027/10/202010   10101010101010  
714710/04/202031/12/202015   151515151515151515
71501/04/202027/08/202030   3030303030    

 

Ideally it would be 

CumulativeBetweenDates:=TOTALYTD(SUM(Opportunity[BaseYear_MonthAGP]),
'Calendar'[Day],USERELATIONSHIP([START DATE],'Calendar'[Day]),[END DATE]])

Unfortunatelly last parameter is a string and can't be used in this manner. 

This would be run on SSAS threfore some limitations are in place(Direct Query, VAR not available)

Pointing to right direction would be appriciated

 

Thanks in advance 

Michal

 

  • Mich_J's avatar
    Mich_J
    6 years ago

    Hello v-alq-msft  and amitchandak ,

    Thanks for your support on this. Unfortunately both of the solutions did not solve calculation in SSAS environment but taking under consideration both comments and advice from local guru I came to above which did allocate GP across months.   

     

    CumulativeBetweenDates:=CALCULATE(
    	SUM(Customer[DAY_AGP]),
    	FILTER(CALCULATETABLE(Customer,ALL('Calendar')),
    		Customer[START_DATE] <=MAX('Calendar'[Day])&&
    		Customer[END_DATE]>MIN('Calendar'[Day])
    				))

     

7 Replies

  • Mich_J , I did not get what you want to give the last parameter. You need to tell where year is going to end. In case it end at 12/31 no need for that. It is optional.

    like

    TOTALYTD(SUM(Opportunity[BaseYear_MonthAGP]),
    'Calendar'[Day],USERELATIONSHIP([START DATE],'Calendar'[Day]),"12/31")

     

    TOTALYTD(SUM(Opportunity[BaseYear_MonthAGP]),
    'Calendar'[Day],USERELATIONSHIP([START DATE],'Calendar'[Day]),"3/31") // Year ending March

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, Mich_J 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    Calendar(a calculated table):

    Calendar = CALENDARAUTO()

     

    There is no relationship between two tables. You may create three calculated columns and a measure as below.

    Calculated column:
    Year-Month = VALUE(FORMAT('Calendar'[Date],"yyyymm"))
    StartYearMonth = VALUE(FORMAT('Table'[START DATE],"yyyymm"))
    EndYearMonth = VALUE(FORMAT('Table'[END DATE],"yyyymm"))
    
    Measure:
    Result = 
    var _cYearMonth = SELECTEDVALUE('Calendar'[Year-Month])
    var _startYearMonth = SELECTEDVALUE('Table'[StartYearMonth])
    var _endYearMonth = SELECTEDVALUE('Table'[EndYearMonth])
    return 
    IF(
        _cYearMonth>=_startYearMonth&&_cYearMonth<=_endYearMonth,
        SUM('Table'[MONTHLY GP])
    )

     

    Result:

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Mich_J's avatar
      Mich_J
      Frequent Visitor

      Hello v-alq-msft  and amitchandak ,

      Thanks for your support on this. Unfortunately both of the solutions did not solve calculation in SSAS environment but taking under consideration both comments and advice from local guru I came to above which did allocate GP across months.   

       

      CumulativeBetweenDates:=CALCULATE(
      	SUM(Customer[DAY_AGP]),
      	FILTER(CALCULATETABLE(Customer,ALL('Calendar')),
      		Customer[START_DATE] <=MAX('Calendar'[Day])&&
      		Customer[END_DATE]>MIN('Calendar'[Day])
      				))