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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Create Table that Counts Items According to Calendar Dates

My situation is the following:

 

I have a main data table that looks like this:

Appended Table
Work Item IDCreated DateClosed Date
11/1/20214/1/2021
23/1/2021 
35/1/20216/1/2021
46/1/20217/1/2021
512/1/2021 

 

I also created a calendar table using this code:

 

Calendar =
GENERATE ( CALENDAR(
DATE ( YEAR ( MIN ( 'Appended Table'[Created Date]) ), 1, 1 ),
DATE ( YEAR ( TODAY() ), 12, 1 )),
VAR currentDay = [Date]
VAR month = MONTH ( currentDay )
VAR year = YEAR ( currentDay )
RETURN ROW (
"First of Month", DATE(year,month,01) )
)
 
Lastly I have a third table, "ADO Metrics" that was created using the following code:
 
ADO Metrics = values('Calendar'[First of Month])
 
What I am trying to do is create two more columns on this table that will count how many unique 'Work Item ID' from the "Appended Table" were open and closed during each one month period. The expected result would look something like this:
 
ADO Metrics
First of MonthOpenMonthly ClosedMonthly
1/1/202110
2/1/202110
3/1/202120
4/1/202101
5/1/202120
6/1/202121
7/1/202111
8/1/202110
9/1/202110
10/1/202110
11/1/202110
12/1/202120

 

The goal is to be able to create simple charts showing how many projects are opened a closed monthly. Could someone help with what code I need to write to reach the result in the table above?

4 REPLIES 4
bcdobbs
Community Champion
Community Champion

Normally I'd lean towards just a measure but does this do what you want for the open monthly:

 

Open Monthly = 
VAR tblOpen = 
    FILTER (
        'Appended Table',
        'Appended Table'[Created Date] <= EOMONTH('ADO Metrics'[First of Month], 0 )
        && 'Appended Table'[Created Date] >=  'ADO Metrics'[First of Month]
    )
RETURN COUNTROWS ( tblOpen )


If it's what you're looking for I can write a similar expression for closed but it's the same logic.

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

While that did work to count the number of 'Work Item ID's that were created and closed each month, what I am trying to do is understand how many are opened and remain open each month.

 

For example, when the system was launched our first 'Work Item ID' was recorded on 9/17/2017 so the data is showing "1" for the month of 9/17. However, when you look at the next month on the table (10/17) there is no data. It should still be counting that the 'Work Item ID' as open, because it does not yet have a "Closed Date". 

 

For example let's say I have four projects with following open/closed dates:

#1 Opened 9/1/2017 - Closed 11/1/2017

#2 Opened 10/1/2017 - Closed 11/1/2017

#3 Opened 10/1/2017 - NOT CLOSED

#4 Opened 12/1/2017 - NOT CLOSED

 

I'd expect to see

First of MonthOpenMonthly 
1/1/20170
2/1/20170
3/1/20170
4/1/20170
5/1/20170
6/1/20170
7/1/20170
8/1/20170
9/1/20171
10/1/20173
11/1/20171
12/1/20172

 

I hope that makes sense!


Thanks!

No worries what about this:

Open Monthly = 
VAR tblOpen = 
    FILTER (
        'Appended Table',
        'Appended Table'[Created Date] <=  'ADO Metrics'[First of Month]
        && (
            'Appended Table'[Closed Date] > EOMONTH ( 'ADO Metrics'[First of Month], 0 ) 
            || ISBLANK ( 'Appended Table'[Closed Date] ) 
            )
    )
RETURN COUNTROWS ( tblOpen ) + 0


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

It still isn't counting how I would expect it to. I uploaded a file to my Google Drive that shows three things:

 

https://docs.google.com/spreadsheets/d/1UU1zocRw21igRtju83O5o-BSE1XqvLvR/edit?usp=sharing&ouid=10595...

 

1. An actual sample of the data from 1/1/17 - 12/31/19 (no sensitive or identifying data is present)

2. A recreation of the table/column that the code you provided is creating based on my sample data

3. A manual creation of what I would expect to see.

 

You will see highlights in the sample data, I simply did this to easily identify and count the Work Item IDs that had closed dates in November and December of 2019, as the system had really taken off during that time period. 

 

The overall goal is to be able to trend how many remain open and unresolved monthly. For example:

 

If project 1 was opened on 1/1/22 and closed that same month, it wouldn't be reflected in the table.

 

If project 2 was opened 1/1/22 and closed on 2/1/22, it would be reflected in the table as "1" in January, but nothing in February. 

 

Building on the above, if project 3 was opened 1/1/22 and had not yet been as of the end of February, I would expect the table to reflect "2" in January and "1" in February and then drop to zero in the month project 3 is finally completed.

 

Perhaps there is a much easier way to do this and keep a historical record, but I am super new to all this.

 

Thanks!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors