cancel
Showing results for
Did you mean:
Highlighted
Regular Visitor

Problem in selecting Max date

I have a table "matches" with below shown columns

I have created calculated field

Max_date = MAX(matches[date])

I have created a filter based on year. I want team1 value to be displayed for the max date of that year. The simle formula which I can think is

winning_Team = Measure = IF(matches[date] = matches[Max_date], matches[team1])

Problem is such comparison is invalid in power BI. It is not giving me fields matches[date] & matches[team1] in the if statement at all. I tried using some aggregation function like MAX(matches[date]) but it gives invalid results.

Please let me know if there is any better solution or if any turn around.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

Re: Problem in selecting Max date

@ajinkya1907

Try this MEASURE to get the TEAM1 on maximum date

Team1 On MaxDate =
CALCULATE (
FIRSTNONBLANK ( Matches[Team1], 1 ),
FILTER ( ALL ( Matches[Date] ), Matches[Date] = MAX ( Matches[Date] ) )
)
9 REPLIES 9
Super User

Re: Problem in selecting Max date

@ajinkya1907

Try this MEASURE to get the TEAM1 on maximum date

Team1 On MaxDate =
CALCULATE (
FIRSTNONBLANK ( Matches[Team1], 1 ),
FILTER ( ALL ( Matches[Date] ), Matches[Date] = MAX ( Matches[Date] ) )
)
Regular Visitor

Re: Problem in selecting Max date

Thanks Zubair, It works perfectly fine !!

Super User

Re: Problem in selecting Max date

@ajinkya1907

Welcome. Which team Kohli plays for ?

Regular Visitor

Re: Problem in selecting Max date

It's RCB :-)

I have another query for you.. I have 3 columns name team1 & team 2 playing against each other. Finally winner column to indicate which team won the match. Using max date we identified the winning team. Any suggestions on how to calculate the runner up?

One solution which I can think is to add column in the data model where team <> winner team. But If I do not prefer to make any data model changes then what could be the solution?

I am new to power BI. whenever I try to use IF statement, It doesn't show the columns like team 1 or team 2, do you know how to make those columns available in if statement? e.g. I was thinking to concatenate both the columns like if (winner team = team1, team2, team 1)  for max date by the formula you gave.

Super User

Re: Problem in selecting Max date

@ajinkya1907

Try this calculated column to get the Runner Up Name

RunnerUp =
EXCEPT (
UNION (
ROW ( "Myteams", CALCULATE ( VALUES ( Matches[Team1] ) ) ),
ROW ( "Myteams", CALCULATE ( VALUES ( Matches[Team2] ) ) )
),
ROW ( "Myteams", CALCULATE ( VALUES ( Matches[Winner] ) ) )
)
Super User

Re: Problem in selecting Max date

@ajinkya1907

So if you have three Columns already for Teams 1 and 2 and winner. This will give you the Runner Up Name

Regular Visitor

Re: Problem in selecting Max date

Thanks for your quick response. Appreciate it !!

The solution which you provided gives attached error. Also we need to find out runner up as per last match in every year :-)

Data set is available at - https://www.kaggle.com/manasgarg/ipl/data

Super User

Re: Problem in selecting Max date

Add it as a calculated column.
Not as a measure
Regular Visitor

Re: Problem in selecting Max date

Thanks Zubair for your quick response.

I was looking for to achieve it with calculated measure. As no solution I can think about, I created new column as below

IPL_RunnerUp2 = IF(matches[team2]<>matches[winner],matches[team2],matches[team1])

and on that I applied max date logic as per your earlier suggestion for winner team. It worked fine for Runner up team. Thanks for your help.

Announcements

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Get your latest community news and announcements.

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 52 members 1,385 guests
Recent signins: