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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mmace1
Impactful Individual
Impactful Individual

Have Rolling Total, but making a mistake with Previous 12 month Rolling Total.

Hi, 

 

So I wrote an expression that captures the rolling total for something - then it takes the filter context in my table, and calculates correctly.  The referenced measure {Distinct CustVen Paid] is just a DISTINTCOUNT on a column. 

 

Rolling Total Distinct Cust-Ven Paid =
CALCULATE (
    [Distinct CustVen Paid],
    FILTER (
        ALL ( Payment ),
        Payment[CreateDateUTC] <= MAX ( Payment[CreateDateUTC] )
    )
)

That works. 

 

But now...I also want to give the previous-12 month rolling total. I have some code, but checking my work - I'm doing something wrong!

 

Rolling Total Distinct Cust-Ven Paid Prev 12 Months =
CALCULATE (
    [Distinct CustVen Paid],
    FILTER (
        ALL ( Payment ),
        Payment[CreateDateUTC] <= MAX ( Payment[CreateDateUTC] )
            && Payment[CreateDateUTC]
                <= ( MAX ( Payment[CreateDateUTC] ) - 365 )
    )
)

Thoughts?  Thanks!

1 ACCEPTED SOLUTION
Seward12533
Solution Sage
Solution Sage

Few options - first for CUMULATIVE Functions your missing an ALL Term and you typically have have the ALL in the column as just  the column your filtering for your **bleep** and unless you have a date table  you will get inconstant results.

 

Rolling Total Distinct Cust-Ven Paid Prev 12 Months =
VAR MaxPayDate = MAX ( Payment[CreateDateUTC] RETURN
CALCULATE (
    [Distinct CustVen Paid],
    ALL(dates),
    FILTER (
        ALL ( date[Date] ),
        date[Date] <=  MaxPayDate)
            && date[Date] <= MaxPayDate - 365 )
    )
)

 

 

Also much easier with DATESINPERIOD function 🙂 Might work on your base table without dates but there can be issues if your missing dates etc...

 

Rolling Total Distinct Cust-Ven Paid Prev 12 Months =
VAR MaxPayDate = MAX ( Payment[CreateDateUTC] RETURN
CALCULATE (
    [Distinct CustVen Paid],
    DATESINPERIOD(Date Dates],MaxPayDAte-365  ,1 ,YEAR)
    )

View solution in original post

2 REPLIES 2
Seward12533
Solution Sage
Solution Sage

Few options - first for CUMULATIVE Functions your missing an ALL Term and you typically have have the ALL in the column as just  the column your filtering for your **bleep** and unless you have a date table  you will get inconstant results.

 

Rolling Total Distinct Cust-Ven Paid Prev 12 Months =
VAR MaxPayDate = MAX ( Payment[CreateDateUTC] RETURN
CALCULATE (
    [Distinct CustVen Paid],
    ALL(dates),
    FILTER (
        ALL ( date[Date] ),
        date[Date] <=  MaxPayDate)
            && date[Date] <= MaxPayDate - 365 )
    )
)

 

 

Also much easier with DATESINPERIOD function 🙂 Might work on your base table without dates but there can be issues if your missing dates etc...

 

Rolling Total Distinct Cust-Ven Paid Prev 12 Months =
VAR MaxPayDate = MAX ( Payment[CreateDateUTC] RETURN
CALCULATE (
    [Distinct CustVen Paid],
    DATESINPERIOD(Date Dates],MaxPayDAte-365  ,1 ,YEAR)
    )
mmace1
Impactful Individual
Impactful Individual

Hey...got the 2nd one working - that is much easier, thanks!

 

Rolling Total Distinct Cust-Ven Paid Prev 12 Months =
CALCULATE (
    [Distinct CustVen Paid],
    DATESINPERIOD (
        'Calendar Table'[Date],
        MAX ( Payment[CreateDateUTC] ) - 365,
        365,
        DAY
    )
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.