Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Oodi
Frequent Visitor

Replacing EARLIER functionality to work in a measure

Hello, 
There was already existing topics about this subject but so far had no success with them.

I would like to rank teams with selected season and gamedate with the following way:

 

VAR _HomeGameNumber =
// Game number based on gamedate only with no season condition
RANKX(FILTER(TeamSchedule_, TeamSchedule_[HomeTeam] = EARLIER(TeamSchedule_[HomeTeam])), TeamSchedule_[gameDate], , ASC, Dense)

VAR _HomeGameNumberPerSeason =
// Game number based on gamedate and season 
RANKX(FILTER(TeamSchedule_, TeamSchedule_[HomeTeam] = EARLIER(TeamSchedule_[HomeTeam]) && TeamSchedule_[season] = EARLIER(TeamSchedule_[season])), TeamSchedule_[gameDate], , ASC, Dense)

RETURN
//The Measure should be able to switch between the two whether season is filtered 
//or not which is not possible with calculated column like below:
IF(ISFILTERED(AuxSeason[Season]),
_HomeGameNumberPerSeason,
_HomeGameNumber)

 

 
The goal here would be to replace the EARLIER() function to use in a measure. Would this work somehow with MAX() in a measure?

2 REPLIES 2
bhanu_gautam
Super User
Super User

@Oodi , Try using below measure

HomeGameNumber =
VAR CurrentHomeTeam = MAX(TeamSchedule_[HomeTeam])
VAR CurrentGameDate = MAX(TeamSchedule_[gameDate])
RETURN
RANKX(
FILTER(
TeamSchedule_,
TeamSchedule_[HomeTeam] = CurrentHomeTeam
),
TeamSchedule_[gameDate],
,
ASC,
DENSE
)

 

HomeGameNumberPerSeason =
VAR CurrentHomeTeam = MAX(TeamSchedule_[HomeTeam])
VAR CurrentGameDate = MAX(TeamSchedule_[gameDate])
VAR CurrentSeason = MAX(TeamSchedule_[season])
RETURN
RANKX(
FILTER(
TeamSchedule_,
TeamSchedule_[HomeTeam] = CurrentHomeTeam &&
TeamSchedule_[season] = CurrentSeason
),
TeamSchedule_[gameDate],
,
ASC,
DENSE
)

 

FinalHomeGameNumber =
IF(
ISFILTERED(AuxSeason[Season]),
[HomeGameNumberPerSeason],
[HomeGameNumber]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for the suggestion. Tried it out and the measure returns error:

A single value for column 'gameDate' in table 'TeamSchedule_' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

The error is caused by the RANKX() Expression TeamSchedule_[GameDate] and goes away with  SELECTEDVALUE(TeamSchedule_[GameDate]) but this does not return the correct query i.e. the same the calculated column returns using EARLIER(). 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.