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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
pablopablo
Frequent Visitor

Help with running cumulative count

Hi,

 

I have the following code which correctly gives me a running total based on a week number of total jobs opened per week. However, i need to amend so it does not count those jobs which have already closed before or during the current week.

 

I also need to filter out only those records where a status does not equal "Cancelled"

 

So if my data looks like this

 

Job NoWeek OpenedWeek Closed
00114
00227
00325
00449
00556

 

I expect my measure to return "Total Records per week"

 

Week 1 - 1

Week 2 - 3

Week 3 - 3

Week 4 - 3 (as the first record closed in week 4)

Week 5 - 4 (as the third record closed in week 5)

Week 5 - 4

Week 6 - 2

 

 

 

Measure = 
CALCULATE (
    COUNT ( 'Live_Roles_Feed'[Job no.] ),
    FILTER (
        ALLSELECTED ( 'Live_Roles_Feed' ),
        'Live_Roles_Feed'[Week_Opened] <= MAX ( 'Calendar'[Week] )
    )
)

 

 

 

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @pablopablo ,

 

Try this.

Measure = 
VAR x = 
CALCULATE(
    COUNT(Sheet10[Job No]),
    FILTER(
       Sheet10,
        [Week Opened] <= MAX('Calendar'[Week]) && [Week Closed] > MAX('Calendar'[Week])
    )
)
RETURN
x

v-lionel-msft_0-1604654160520.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
v-lionel-msft
Community Support
Community Support

Hi @pablopablo ,

 

Try this.

Measure = 
VAR x = 
CALCULATE(
    COUNT(Sheet10[Job No]),
    FILTER(
       Sheet10,
        [Week Opened] <= MAX('Calendar'[Week]) && [Week Closed] > MAX('Calendar'[Week])
    )
)
RETURN
x

v-lionel-msft_0-1604654160520.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@pablopablo , Create a Week Table, You can do using generate series and analyze week data using that.

 

Try the formula like

Current Jobs = CALCULATE(COUNTx(FILTER(Table,Table[Week Opened]<=max('Week'[Week]) && (ISBLANK(Table[Week Opened]) || Table[Week Opened]>max('Week'[Week]))),(Table[Job No])))

 

Do no join week with any of the columns

 

Very similar to the approch in https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi. thanks for your reply.

 

We already have a calendar table setup which has 'week' column in it

 

My roles table (where this data is already coming from, is already linked to this calendar table via date opened in the roles table and date in the calendar table. there is another join which joins on the date closed in the roles table and date field in the calendar table.

 

Would your example still work?

@pablopablo , You have use crossfilter to remove any active join. refer to my blog for that https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi,

 

I used your article and have the following code:

 

Weekly Cummulative = CALCULATE(COUNTx(FILTER('Live_Roles_Feed',Live_Roles_Feed[Date opened]<=max('Calendar_New'[Date]) && (ISBLANK('Live_Roles_Feed'[Date job closed]) || 'Live_Roles_Feed'[Date job closed]>max('Calendar_New'[Date]))),('Live_Roles_Feed'[Job no.] )),CROSSFILTER(Live_Roles_Feed[Date opened],'Calendar_New'[Date],None))

 

 

However, it displays like this. I have even created a calendar table using your guide and linked accordingly

 

Capture.PNG

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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