Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi All,
The current formula is relatively simple and works to return the latest Office for the Project based on the Period, but it involves using both LOOKUPVALUE and MAX. I'm wondering if there is a cleaner way that is considered best (or better) practice:
Solved! Go to Solution.
Hi @genaussie
Try this:
CalcColumn =
VAR MaxPeriodByProject =
CALCULATE ( MAX ( 'List'[Period] ), ALLEXCEPT ( 'List', 'List'[Project] ) )
RETURN
CALCULATE (
MAX ( 'List'[Office] ),
FILTER (
ALL ( 'List' ),
'List'[Period] = MaxPeriodByProject
&& 'List'[Project] = EARLIER ( 'List'[Project] )
)
)
Hi @genaussie
Try this:
CalcColumn =
VAR MaxPeriodByProject =
CALCULATE ( MAX ( 'List'[Period] ), ALLEXCEPT ( 'List', 'List'[Project] ) )
RETURN
CALCULATE (
MAX ( 'List'[Office] ),
FILTER (
ALL ( 'List' ),
'List'[Period] = MaxPeriodByProject
&& 'List'[Project] = EARLIER ( 'List'[Project] )
)
)
Hi @danextian confirming this works. It is useful to have alternative solutions 🙂
Another option is to utilise 2x VAR:
VAR MaxPeriodByProject = CALCULATE ( MAX ( 'List'[Period] ), ALLEXCEPT ( 'List', 'List'[Project] ) )
VAR CurrentProject = 'List'[Project]
RETURN
CALCULATE (
MAX ( 'List'[Office] ),
FILTER (
ALL ( 'List' ),
'List'[Period] = MaxPeriodByProject
&& 'List'[Project] = CurrentProject )
)
Try this
LatestOfficeByPeriod =
VAR CurrentProject = SELECTEDVALUE('List'[Project]) -- Get the currently selected project
RETURN
LOOKUPVALUE(
'List'[Office],
'List'[Project], CurrentProject,
'List'[Period], EARLIER('List'[Period])
)
Hi, I don't think this works as I get the error message, "EARLER/EARLIEST refers to an earlier row context which doesn't exist."
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
79 | |
73 | |
57 | |
36 | |
31 |
User | Count |
---|---|
91 | |
60 | |
59 | |
49 | |
45 |