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
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
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.