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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Traceout
Frequent Visitor

Get rolling sum of customers based on start and end dates

I'm looking to get a rolling count of customers based on the start and end date so I can see where the peak of customers affected is. Any help with the formula would be greatly appreciated!

 

Table Data: 

IDStart_DateEnd_dateCustomers
112/11/22 4:58 AM12/11/22 4:31 PM97
212/11/22 5:43 AM12/11/22 6:30 AM12
312/11/22 6:19 AM12/11/22 12:12 PM71
412/11/22 6:31 AM12/11/22 6:52 AM20
512/11/22 6:43 AM12/11/22 7:55 AM3
612/11/22 7:07 AM12/11/22 8:32 AM1

 

Expected Data with new 'Rolling Customers impacted' column:

IDStart_DateEnd_dateCustomersRolling Customers Impacted
112/11/22 4:58 AM12/11/22 4:31 PM9797
212/11/22 5:43 AM12/11/22 6:30 AM12109
312/11/22 6:19 AM12/11/22 12:12 PM71180
412/11/22 6:31 AM12/11/22 6:52 AM20188
512/11/22 6:43 AM12/11/22 7:55 AM3191
612/11/22 7:07 AM12/11/22 8:32 AM1172
1 ACCEPTED SOLUTION

@Traceout - I did as a measure. If you wanted as a Column then you'd need to change to:

Column Rolling Customers Impacted = 
VAR currentStartDate = 'Table Data'[Start_Date]
RETURN
    CALCULATE(
        SUM('Table Data'[Customers]),
        ALL('Table Data'),
        'Table Data'[Start_Date] <= currentStartDate,
        'Table Data'[End_date] >= currentStartDate
    )

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

11 REPLIES 11
Traceout
Frequent Visitor

@ChrisMendoza I know I already marked this one as solved but I ran into an issue by adding on another layer. Lets say each ID is assigned a zone and I create a splicer based on zone. Is there a way to have the column and/or the measure to update based on the zone selection in the visual?

Traceout_1-1671125599842.png

 

 

@Traceout - to be honest I cannot see the logic to accomplish this.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



ChrisMendoza
Resident Rockstar
Resident Rockstar

@Traceout - Yes, please explain the logic as @Mikelytics noted. Otherwise the measure can be as:

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Mikelytics
Resident Rockstar
Resident Rockstar

@Traceout 

What is the business logic for these two values?

Mikelytics_0-1671054743519.png

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

@Mikelytics @ChrisMendoza 

It's a running total of the customers impacted. If the end time of customers affected is past they don't get included in the 'Rolling Customers Impacted' 

Traceout_0-1671054971279.png

So ID 4s Rolling Customers Impacted is 188 because y ou no longer include the 12 from ID 2 since ID 4's start date is after the end date of ID 2. 

 

 

 

Hi @Traceout 

 

It was tricky but I think I got it. 🙂

 

 

Mikelytics_11-1671057507314.png

 

 

Rolling Sum | Start Date End Date = 
    var __CurrentStartDate = MAX([Start_Date])
    var __CurrentEndDate = MAX([End_date])
    var __CurrentID = MAX([ID])

Return
CALCULATE(
    SUMX(
        'SampleData',
        var __IterationStartDate = [Start_Date]
        var __IterationEndDate = [End_date]
        Return
        IF(
            AND(__IterationStartDate >= __CurrentStartDate,__IterationStartDate <= __CurrentEndDate) ||
            AND(__IterationEndDate >= __CurrentStartDate,__IterationEndDate <= __CurrentEndDate) ||
            AND(__IterationStartDate <= __CurrentStartDate,__IterationEndDate >= __CurrentEndDate)
            ,[Customers],0
        )

    )
    ,ALL('SampleData'),
    'SampleData'[Start_Date]<=__CurrentStartDate
)

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

@Traceout 

 

while I was working on my complicated solution @ChrisMendoza got a much simpler one. I first thought it would not cover all cases but I think indeed his one is a complete one. So my solution works but I would go with the one of Chris 😄

 

Best regards

Michael

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

@Traceout -
looks like this works:

Rolling Customers Impacted = 
VAR currentStartDate = SELECTEDVALUE('Table Data'[Start_Date])
RETURN
    CALCULATE(
        SUM('Table Data'[Customers]),
        ALL('Table Data'),
        'Table Data'[Start_Date] <= currentStartDate,
        'Table Data'[End_date] >= currentStartDate
    )





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



@ChrisMendoza 

I may be doing something wrong here. I tried adding it in but all of the rows are blank. I selected 'new column' on the ribbon. 

 

Traceout_0-1671060050668.png

 

@Traceout - I did as a measure. If you wanted as a Column then you'd need to change to:

Column Rolling Customers Impacted = 
VAR currentStartDate = 'Table Data'[Start_Date]
RETURN
    CALCULATE(
        SUM('Table Data'[Customers]),
        ALL('Table Data'),
        'Table Data'[Start_Date] <= currentStartDate,
        'Table Data'[End_date] >= currentStartDate
    )

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Worked perfectly! Thank you! @ChrisMendoza and thank you as well @Mikelytics 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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