Forum Discussion
Using historical dates to calculate system status at intervals in the past
- 5 years ago
"Perhaps the dates used to created the matrix columns need to be related to the other tables used in the DAX formula?"
Exactly. If you see the same number over and over you know you picked the wrong field, from a dangling table or from the wrong end of a search direction.
I did come up with a solution, but more complex than I hoped (though still wonder if there is a simpler solution).
I had this table called DateHalfYear to start with - a simplified date-type table with dates each six months for a few years:
I then created a new table called PagesWithDates in Power Query, that included a row for each date in the above table for each page record (total rows in new table = number dates from above table x total page records):
let
Source = DateHalfYearDim,
RemoveCols = Table.SelectColumns(Source,{"DateKey"}),
AddPagesFactAsColumn = Table.AddColumn(RemoveCols, "Pages", each Pages),
ExpandPages = Table.ExpandTableColumn(AddPagesAsColumn, "Pages", {"PageKey", "SiteKey"}, {"PageKey", "SiteKey"}),
ChangeTypes = Table.TransformColumnTypes(ExpandPages,{{"PageKey", Int64.Type}, {"SiteKey", Int64.Type}})
in
ChangeTypes
I then hooked up the new PagesWithDates fact table to the relevant dimension tables:
And added a calculated column to PagesWithDates table to work out the months since last review for each page record at each historical date:
Months since last review =
VAR dateToWorkFrom = RELATED(DateHalfYear[Date])
VAR pageKey = PagesWithDates[PageKey]
VAR lastReviewedDate =
CALCULATE(
MAX(Reviews[DateReviewCompleted]),
FILTER(Reviews,
Reviews[PageKey] = pageKey &&
Reviews[DateReviewCompleted] < dateToWorkFrom
)
)
VAR monthsSinceLastReview = IF(NOT ISBLANK(lastReviewedDate), DATEDIFF(lastReviewedDate, dateToWorkFrom, MONTH))
RETURN
monthsSinceLastReview
Then created a measure to count the number of pages more than 3 years since last reviewed
Number pages greater than 3 years since reviewed =
COUNTROWS(
FILTER(
PagesWithDates,
PagesWithDates[Months since last review] > 36
)
)
(I guess a more complex measure could be used to eliminate the need for a calculated column, but I found it simpler to think of it this way)
Lastly, I created a matrix from:
- Rows: Site[Site name]
- Columns: DateHalfYear[Year] and DateHalfYear[Month name short]
- Values: [Number pages greater than 3 years since reviewed]
This has produced a result that is sufficiently accurate for my purposes and that shows the trends over time with respect to the number of pages that were 'overdue' for review (i.e. more than 3 years since last review) at each historical date, with dates at intervals of six months.
Any comments on whether such a complex solution was needed, or refinements to the above solution are appreciated.