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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
NorwoodFrog
Regular Visitor

Counting objects/month based on Start and End Date

Hi,

 

I have a list of work orders (WO) and for each of them their start date, end date and $value. 

We would like to count the number of WOs which are active for every month. Some WOs start and finish within the month, but some spread over several months - and these are the ones causing the problem, we do not physically have a table listing the WO for each month. 

 

Below is an example of the dataset (let's call it Transactions):

 

WO_NoStartDateEndDate$_Value
WO0114/08/202127/08/2021100
WO0214/08/202124/08/2021100
WO0315/08/202112/12/2021100
WO0415/08/202120/12/2021100
WO053/09/20217/09/2021100
WO065/09/202114/09/2021100
WO0712/09/202118/09/2021100
WO0820/09/202115/11/2021100
WO093/10/202115/10/2021100
WO105/10/202112/11/2021100
WO116/10/20216/12/2021100
WO121/11/20215/11/2021100
WO132/11/202115/11/2021100
WO143/11/20215/12/2021100
WO152/12/202115/12/2021100
WO165/12/20215/01/2022100

 

As an example, WO03 covers the period Aug-21 to Dec-21 and should therefore be accounted for each month. 

 

The expected result would look something like that - note, the last column wouldn't be included in the result, it is a reference to the WOs that should be included in the COUNT. 

 

MONTHCOUNT OF ACTIVE WosWO Numbers
Aug-214WO01, WO02, WO03, WO04
Sep-216WO03, WO04, WO05, WO06, WO07, WO08
Oct-216WO03, WO04, WO08, WO09, WO10, WO11
Nov-218WO03, WO04, WO08, WO10, WO11, WO12, WO13, WO14
Dec-216WO03, WO04, WO11, WO14, WO15, WO16

 

Any help here would be greatly appreciated. I don't know how to tackle this one. 

 

Cheers

Christine 

 

2 ACCEPTED SOLUTIONS
Vera_33
Resident Rockstar
Resident Rockstar

Hi @NorwoodFrog 

 

Here is one way, I have a disconnected Date Table called MonthTable with Date, MonthYear columns

 

Vera_33_0-1637550671938.png

Count of Wos = 
VAR T1 =
    GENERATE (
        Transactions,
        DATESBETWEEN (MonthTable[Date],[StartDate],[EndDate])
    )
RETURN
   CALCULATE(COUNTROWS(VALUES(Transactions[WO_No])), ( FILTER ( T1, [Date] IN VALUES ( MonthTable[Date] ) ) ))


WO Numbers = 
VAR T1 =
    GENERATE (
        Transactions,
        DATESBETWEEN (MonthTable[Date],[StartDate],[EndDate])
    )
RETURN
   CONCATENATEX( DISTINCT(SELECTCOLUMNS(FILTER ( T1, [Date] IN VALUES ( MonthTable[Date] ) ) ,"Wo",Transactions[WO_No])),[Wo],",")

 

View solution in original post

CNENFRNL
Community Champion
Community Champion

Screenshot 2021-11-22 144743.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

6 REPLIES 6
NorwoodFrog
Regular Visitor

Both solutions work and on my dataset returned a very similar performance. I can't accept both as solution, so will go with the first one. 

CNENFRNL
Community Champion
Community Champion

Screenshot 2021-11-22 144743.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank You CNENFRNL, this works well. Rather advanced nesting of functions, no wonder I struggled 😉

 

I am wondering about performance when looking at both solutions, yours and Vera's. My dataset is really large. I understand Vera's solution better than yours tbh, but if I get it right, your CALCULATETABLE only looks at the date range for each WO, correct?

Cheers

Vera_33
Resident Rockstar
Resident Rockstar

Hi @NorwoodFrog 

 

Here is one way, I have a disconnected Date Table called MonthTable with Date, MonthYear columns

 

Vera_33_0-1637550671938.png

Count of Wos = 
VAR T1 =
    GENERATE (
        Transactions,
        DATESBETWEEN (MonthTable[Date],[StartDate],[EndDate])
    )
RETURN
   CALCULATE(COUNTROWS(VALUES(Transactions[WO_No])), ( FILTER ( T1, [Date] IN VALUES ( MonthTable[Date] ) ) ))


WO Numbers = 
VAR T1 =
    GENERATE (
        Transactions,
        DATESBETWEEN (MonthTable[Date],[StartDate],[EndDate])
    )
RETURN
   CONCATENATEX( DISTINCT(SELECTCOLUMNS(FILTER ( T1, [Date] IN VALUES ( MonthTable[Date] ) ) ,"Wo",Transactions[WO_No])),[Wo],",")

 

Hi Vera,

This works well too and is perhaps more in line with what I was trying to achieve, which is creating that virtual table of date values. I wonder though if, with a much bigger dataset like the one I'm dealing with, there would be performance issues? 

Cheers

Hi @NorwoodFrog 

 

It could, if you have large table. Last time it took 1300 ms to scan 350k rows in Date table when I used DAX Studio to check which was still acceptable. Go test it:) If you can use Power Query and are willing to expand the orginal table to month level, you can do that as well.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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