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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BI_Samurai
Frequent Visitor

Rolling cumulative TOTAL with 2 calendars

Hello,

 

I would like to calculate correctly a total of a sales measure to show a rolling cumulative total for the last 12 months.

 

This measure is intented to work with 2 calendars - first main calendar is used to select data in the slicer and second calendar is used to display data on the visual only until the selected month from the first calendar and slicer.

 

The goal is to display the data only until the time period selected in the year/month slicers meaning that if I select April 2024 I should see the total result calculating May 2023 up to April 2024. For a single month I get correct values, however the totals at the moment return only data relevant to 2024.

 

This is the measure:

 

Sales Rolling test =

var var_end =
MAX('📆Calendar 2'[Date])

var var_start = EOMONTH(var_end,-12)

var var_result =

IF(SELECTEDVALUE('📆Calendar 2'[Month #])>SELECTEDVALUE('📆Calendar'[Month #]),
blank(),
CALCULATE(SUM(Sales[Total Sales]),
    REMOVEFILTERS('📆Calendar'),
   
 KEEPFILTERS('📆Calendar'[Date] > var_start &&'📆Calendar'[Date]<=var_end)))


RETURN
var_result
 
BI_Samurai_0-1712205785307.png

Do you know what needs to be added to my measure in order to solve this?

Any other ideas how to fix this?

 

Thank you.

1 ACCEPTED SOLUTION

It's a rolling 12 Month Measure. 

 

Sales - Last 12 Months = 
CALCULATE (
    [Sales],
    DATESINPERIOD ( Calendar[Date], MAX ( Calendar[Date] ), -12, MONTH )
)

Sales is a simple Sum

SUM(Sales[Amount])



View solution in original post

4 REPLIES 4
Joe_Barry
Responsive Resident
Responsive Resident

Hi @BI_Samurai 

 

Create an Inactive relationship between Calendar 2 and Calendar on the Date columns. Create a measure similar to below. Add the Date columns in the visual from Calendar2 and the Slicer data should come from Calendar.

Sales P12M = 
VAR RefDate =
    MAX ( Calendar[Date] )
VAR PrevDate =
    DATESINPERIOD ( Calendar2[Date], RefDate, -12, MONTH )
RETURN
    CALCULATE (
        [Sales - Last 12 Months],
        REMOVEFILTERS ( Calendar ),
        KEEPFILTERS ( PrevDate ),
        USERELATIONSHIP ( Calendar[Date], Calendar2[Date] )
    )

 

 

Hope this helps

Joe

 

If you found my answer helpful and it solved your issue, please accept as solution

Awesome, thank you !

Hello,

 

thanks for a quick reply and the tip. What is the exact measure that you use here [Sales - Last 12 Months] ?

thank you

It's a rolling 12 Month Measure. 

 

Sales - Last 12 Months = 
CALCULATE (
    [Sales],
    DATESINPERIOD ( Calendar[Date], MAX ( Calendar[Date] ), -12, MONTH )
)

Sales is a simple Sum

SUM(Sales[Amount])



Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.