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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
JimJim
Responsive Resident
Responsive Resident

Trying to SUM a rolling month measure

Hi Guys,

 

I have attached a test report with details of my problem. Please note that the problem on my test report is nonsense but it is a very simplified version of my actual problem. Please only be concerned with the rolling months page on the report.

 

I have 2 measures:

 

Invoice Amount USD R6M: Rolling 6 months of invoice amount.

Invoice Amount Average: Takes a SUM of the previous 3 months of the R6M measure and divides it by 3 (to smooth out any irregularities with the data)

 

Problem: When I try to SUM the previous 3 months of the R6M measure it does not return the desired results, in fact, it returns the same value as R6M.

 

Link to pbix: https://1drv.ms/u/s!ArazqhFmvkSJlmVxJRRpSR1dAG4m?e=m0jo3l

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can use

Invoice Amount Average = 
VAR __lastVisibleDate =
    LASTDATE ( 'Time'[Date] )
VAR __financialPeriod =
    MIN ( 'Time'[YearMonth] ) - 2
VAR __fromDate =
    CALCULATE (
        FIRSTDATE ( 'Time'[Date] ),
        FILTER ( ALL ( 'Time' ), 'Time'[YearMonth] = __financialPeriod )
    )
VAR summaryTable = CALCULATETABLE(
    ADDCOLUMNS( SUMMARIZE( 'time', 'time'[financial_year], 'time'[financial_period] ),
        "@total", [Invoice Amount USD R6M] ), 
    DATESBETWEEN('Time'[Date], __fromDate, __lastVisibleDate)
)
VAR __result = AVERAGEX( summaryTable, [@total] )
RETURN
     __result

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You can use

Invoice Amount Average = 
VAR __lastVisibleDate =
    LASTDATE ( 'Time'[Date] )
VAR __financialPeriod =
    MIN ( 'Time'[YearMonth] ) - 2
VAR __fromDate =
    CALCULATE (
        FIRSTDATE ( 'Time'[Date] ),
        FILTER ( ALL ( 'Time' ), 'Time'[YearMonth] = __financialPeriod )
    )
VAR summaryTable = CALCULATETABLE(
    ADDCOLUMNS( SUMMARIZE( 'time', 'time'[financial_year], 'time'[financial_period] ),
        "@total", [Invoice Amount USD R6M] ), 
    DATESBETWEEN('Time'[Date], __fromDate, __lastVisibleDate)
)
VAR __result = AVERAGEX( summaryTable, [@total] )
RETURN
     __result
JimJim
Responsive Resident
Responsive Resident

Amazing. Thank you 🙂

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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