For context,
I have two tables, Project and Draft.
Project has a list of Project #s and Draft #s. Note that the Draft numbers are unique.
The Draft table has a list of Draft #s and their status date when they enter statuses Submitted, Approved and Closed:
The model has a physical relationship from Table (1) to Draft (many) on the Draft # field.
You can also see the model here: dummy data 01302024 1651.pbix (68.7 KB)
User request:
The user would like to see the following:
- The user is only interested in Status Dates between 1/1/2019 – 12/31/2021
- The user would like to see a table like below, with the project number, the project date (from the project table), the most recent approval status date, the most recent closure status date, the most recent submitted status date, and the number of days from the most recent approval status date to the project date:
Project; 671
Most Recent Approval: 12/1/2021
Most Recent Closure: 11/8/2021
Most Recent Submission: 9/12/2021
Project Date: 5/15/2021
Days from Most Recent Approval to Project Date: -200
- Also, in order for a project to be included on the table, the most recent closure date associated with any project must be BEFORE that project’s most recent approval date (within the above date filters)
- Finally, in order for a project to be included on the table, the most recent submission date associated with any project must be BEFORE that project’s most recent closure date (within the above date filters)
For my date filter, I have a slicer with the Draft table’s Status Date, since the user may wish to change the range of dates they wish to view. The user potentially wanting to change filter date range is also why I’m hesitant to build a calculated column for “Most Recent Approval Date,” “Most Recent Submission Date,” etc.
In Power BI, I created a table visual and dropped in Project #. I then dropped in measures for highest approval date, highest closure date, and highest submission date.
I am struggling to filter the table to the final two bullet points (where the project should only appear on the table if the Most Recent Approval Date must be more recent than the Most Recent Closure date, AND if the Most Recent Closure Date is more recent than the most recent Submission Date).
I’ve tried building a measure similar to this. My thought is that I would drop this measure into the filter pane and filter to project numbers that return an amount on the measure. However, it takes quite a long time to load on Power BI desktop with the actual data tables. It also doesn’t seem to be returning correct results on my current table.
Measure to Filter Table Visual =
VAR Project_Num = SELECTEDVALUE(‘PROJECT’[Project])
VAR Approve_date =
CALCULATE(
MAX(‘Draft Table’[Status Date])
, ‘Draft Table’[STATUS] in {“Approved”}
, Project[Project] IN {Project_Num}
)
VAR Close_date =
CALCULATE(
MAX(‘Draft Table’[Status Date])
, ‘Draft Table’[STATUS] in {“Closed”}
, Project[Project] IN {Project_Num}
)
VAR Submit_Date =
CALCULATE(
MAX(‘Draft Table’[Status Date])
, ‘Draft Table’[STATUS] in {“Submitted”}
, Project[Project] IN {Project_Num}
)
VAR ApproveGreaterThanClose =
CALCULATE(
DISTINCTCOUNT(‘Draft Table’[Draft #])
, ‘Project’[Project] IN {Project_Num}
, FILTER(
VALUES(‘Draft Table’)
, ‘Draft Table’ [Status] IN {“Approved”} && ‘Draft Table’[Status Date] > Close_date
)
)
VAR CloseGreaterThanSub =
CALCULATE(
DISTINCTCOUNT(‘Draft Table’[Draft #])
, ‘Project’[Project] IN {Project_Num}
, FILTER(
VALUES(‘Draft Table’)
, Submit_date < Close_date
)
)
RETURN CloseGreaterThanSub + ApproveGreaterThanClose
What are your thoughts?
Dummy data here: dummy data 01302024 1651.pbix (68.7 KB)