Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I am attempting to build a gains and losses report for my company that can be filtered by month. It needs to list each site that we have, their status at the beginning or end of the month, and whether or not that changed during the month. Sites are either commissioned or decomissioned, but a site that is decomissioned can be recomissioned, because of this our database has a seperate log for these changes. I'm currently stuck trying to make the measure I need for the sites Brought Forward.
I need to see the number of sites that were commissioned at the start of the selected month (currently selected through a slicer on the Month table, linked only through the measure itself), so I need to pull the most recent commissioning time before the start of the month. To do this I've written the following:
Solved! Go to Solution.
Hi @jbranch - very close, can you try the below logic:
Sites Brought Forward =
VAR st = MAX('Month'[Start]) -- selected month's start
-- Step 1: filter events BEFORE selected month
VAR EventsBeforeMonth =
FILTER (
Commissioning,
Commissioning[evtime] < st
)
-- Step 2: get the latest event per Site before the month
VAR LatestPerSite =
ADDCOLUMNS (
SUMMARIZE (EventsBeforeMonth, Commissioning[SiteID]),
"LatestTime", CALCULATE (
MAX (Commissioning[evtime]),
FILTER (
EventsBeforeMonth,
Commissioning[SiteID] = EARLIER (Commissioning[SiteID])
)
)
)
-- Step 3: bring in the corresponding status for that event
VAR WithStatus =
ADDCOLUMNS (
LatestPerSite,
"Status", CALCULATE (
MAX (Commissioning[evqual]),
FILTER (
Commissioning,
Commissioning[SiteID] = EARLIER (Commissioning[SiteID]) &&
Commissioning[evtime] = [LatestTime]
)
)
)
-- Step 4: count how many had "Commissioned" as latest status
RETURN
COUNTROWS (
FILTER (WithStatus, [Status] = "Commissioned")
)
Hope this measure will return the number of sites that were last set to “Commissioned” before the selected month, i.e. the correct "Brought Forward" value.
Proud to be a Super User! | |
Hi @jbranch - very close, can you try the below logic:
Sites Brought Forward =
VAR st = MAX('Month'[Start]) -- selected month's start
-- Step 1: filter events BEFORE selected month
VAR EventsBeforeMonth =
FILTER (
Commissioning,
Commissioning[evtime] < st
)
-- Step 2: get the latest event per Site before the month
VAR LatestPerSite =
ADDCOLUMNS (
SUMMARIZE (EventsBeforeMonth, Commissioning[SiteID]),
"LatestTime", CALCULATE (
MAX (Commissioning[evtime]),
FILTER (
EventsBeforeMonth,
Commissioning[SiteID] = EARLIER (Commissioning[SiteID])
)
)
)
-- Step 3: bring in the corresponding status for that event
VAR WithStatus =
ADDCOLUMNS (
LatestPerSite,
"Status", CALCULATE (
MAX (Commissioning[evqual]),
FILTER (
Commissioning,
Commissioning[SiteID] = EARLIER (Commissioning[SiteID]) &&
Commissioning[evtime] = [LatestTime]
)
)
)
-- Step 4: count how many had "Commissioned" as latest status
RETURN
COUNTROWS (
FILTER (WithStatus, [Status] = "Commissioned")
)
Hope this measure will return the number of sites that were last set to “Commissioned” before the selected month, i.e. the correct "Brought Forward" value.
Proud to be a Super User! | |
User | Count |
---|---|
85 | |
79 | |
64 | |
52 | |
46 |
User | Count |
---|---|
101 | |
43 | |
41 | |
39 | |
36 |