Forum Discussion

jusTodd's avatar
jusTodd
Icon for Advocate IV rankAdvocate IV
3 years ago

Combined Count Based on Different Dates in Different Tables

I am looking to get a count of items in TableA based on the date in TableA and a total count of items in TableA and TableB, based a different date in TableB.

 

Looking for a little feedback, since I work in silo and am only about 6 months in with PowerBI.  I would like to know if this can be achieved in DAX, or if the Append Query I created is really for the best.  It certainly seems the easiest solution.

 

(EDIT - The biggest problem with the current solution is filtering based on another column that identifies Scheduled Maintenance.  At this time, I have to add the column to the filter 3x on one page ... am hoping a little proper DAX can solve that issue).

 

 

The two tables, 'OpenWOs' and 'ClosedWOs' of which I need a count of

1) Open work orders by the month in which they were created

2) Closed work orders by the month in which they were closed

3) Created work orders by the month in which they were created

 

The tables are joined to a calendar table to facilitate a rolling 12 months in the visualizations.

 

OpenWOs is joined by [Date Created] and ClosedWOs is joined by [Date Completed], which gives me a proper count of exactly when the Opens were created and Closed were completed.

 

The problem lies with getting the count for all  WOs created in the month they were created, since I have ClosedWOs joined by [Date Completed].  Obviously, it won't work if I join by [Date Created] either.

 

Consequently, I created an Append Query to pull the Created Dates and Closed Dates from their respective tables into one to overcome this challenge, and because I simply could not figure out proper DAX for the situation.  That table 'CreatedWOs' is also joined to the calendar table and everything gives me the exact numbers that I expect.

 

The following image shows the results I am after, which show Created WOs in the month they were created, Open WOs from they were created, and Closed WOs in the month they were closed.

 

 

The following are sample data and a snapshot of the model. 

 

Open WOs

WO IDStatusDate Created
1690Open7/19/2022
2002Open9/1/2022
2003Open9/1/2022
2068Open9/21/2022
2069Open9/21/2022
2070Open9/21/2022
2071Open9/21/2022
2072Open9/21/2022
2073Open9/21/2022

 

Closed WOs

WO IDStatusDate CreatedDate Complete
92Closed, Completed9/21/20211/5/2023
451Closed, Incomplete7/19/20221/24/2023
750Closed, Incomplete9/1/20221/25/2023
786Closed, Completed2/20/2022 1/6/2023
874Closed, Completed3/3/20221/19/2023
994Closed, Incomplete9/21/20221/24/2023
1276Closed, Completed5/18/20221/3/2023
1482Closed, Completed6/15/20221/25/2023

 

 

 

 

 

2 Replies