Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate DOH based on rolling month

Hi All,

 

I have following table:

 
Report MonthV_Rolling_SumAttributeTdateValue
1/1/202050A31/12/2019140
1/1/2020150A31/12/201977
1/1/202075A30/11/2019117
1/1/202050A30/11/201994
1/1/2020300A30/10/2019237
1/1/2020375A30/10/201993
1/2/2020525A10/23/201948
1/2/2020650A10/29/201991
1/2/2020150A31/12/2019188
1/2/2020600A31/12/2019197
1/2/2020550A30/11/201950
1/2/2020100A30/10/2019126

 

V_Rolling_Sum is rolling months sum for last 3 months. I need to create a new column- DH as below logic:-

for month - 1/1/2020 ->

=if(value<=Dec19, value/dec19 *31,if(Value<=(dec19+nov19),(Value-dec19)/nov19*(30+31)),if(Value<=(dec19+nov19+oct19),(Value-dec19-nov19)/oct19*(31+30+31)

 

Where 30 & 31 are numbers of days in that particular month.

 

ex 2:- > for month - 2/1/2020 -

=if(value<=jan20, value/jan20 *31,if(value<=(dec19+jan20),(value-jan20)/dec19*(31+31)),if(value<=(jan20+dec19+nov19),(value-jan20-dec19-nov19)/nov19*(31+30+31)

 

for reporting months the last 3 months taken into formula will change.

 

Urgent Help Required.!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Anonymous,

What the 'value' you mean? The 'rolling total' or 'value' field?
I use the value field to calculate the previous total results, you can take a look at the following calculated column formulas if it meets your requirement.

 

DOH = 
VAR currDate = 'Table'[Report Month]
VAR prev1Month =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1, DAY ( currDate ) )
VAR prev2Month =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 2, DAY ( currDate ) )
VAR prev3Month =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 3, DAY ( currDate ) )
VAR currTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] = EARLIER ( 'Table'[Report Month] ) )
    )
VAR P1MTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] = prev1Month )
    )
VAR P2MTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] IN CALENDAR ( prev2Month, prev1Month ) )
    )
VAR P3MTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] IN CALENDAR ( prev3Month, prev1Month ) )
    )
RETURN
    IF (
        currTotal <= P1MTotal,
        currTotal / P1MTotal
            * DAY ( EOMONTH(prev1Month,0)),
        IF (
            currTotal <= P2MTotal,
            ( currTotal - P1MTotal ) / ( P2MTotal - P1MTotal )
                *  DAY ( EOMONTH(prev2Month,0)),
            IF (
                currTotal <= P3MTotal,
                ( currTotal - P2MTotal ) / ( P3MTotal - P2MTotal )
                  * DAY ( EOMONTH(prev3Month,0))
            )
        )
    )

 

Regards,

Xiaoxin Sheng

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous,

I'd like to suggest you extract the current value and use date function to find the range of the last three months, it not need to consider the transfer about the end day of the month.

ROlling 3M Total =
VAR currDate = TABLE[Tdate]
RETURN
    CALCULATE (
        SUM ( TABLE[Value] ),
        FILTER (
            TABLE,
            [Tdate]
                >= DATE ( YEAR ( currDate ), MONTH ( currDate ) - 3, DAY ( currDate ) )
                && [Tdate] <= EARLIER ( TABLE[Tdate] )
        )
    )

Time Intelligence "The Hard Way" (TITHW) 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi @Anonymous , 

Thankyou.

But i need the formula to calculate DH. 

Can you help me with the calculation for DH

Anonymous
Not applicable

If I use the above formula, it is also including the sum from later than 3 months. 

 

If anyone can please help.

Anonymous
Not applicable

HI @Anonymous,

What the 'value' you mean? The 'rolling total' or 'value' field?
I use the value field to calculate the previous total results, you can take a look at the following calculated column formulas if it meets your requirement.

 

DOH = 
VAR currDate = 'Table'[Report Month]
VAR prev1Month =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1, DAY ( currDate ) )
VAR prev2Month =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 2, DAY ( currDate ) )
VAR prev3Month =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 3, DAY ( currDate ) )
VAR currTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] = EARLIER ( 'Table'[Report Month] ) )
    )
VAR P1MTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] = prev1Month )
    )
VAR P2MTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] IN CALENDAR ( prev2Month, prev1Month ) )
    )
VAR P3MTotal =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', [Report Month] IN CALENDAR ( prev3Month, prev1Month ) )
    )
RETURN
    IF (
        currTotal <= P1MTotal,
        currTotal / P1MTotal
            * DAY ( EOMONTH(prev1Month,0)),
        IF (
            currTotal <= P2MTotal,
            ( currTotal - P1MTotal ) / ( P2MTotal - P1MTotal )
                *  DAY ( EOMONTH(prev2Month,0)),
            IF (
                currTotal <= P3MTotal,
                ( currTotal - P2MTotal ) / ( P3MTotal - P2MTotal )
                  * DAY ( EOMONTH(prev3Month,0))
            )
        )
    )

 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.