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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ajinkya1907
Helper II
Helper II

Problem in selecting Max date

 

I have a table "matches" with below shown columns

 

1.PNG

 

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
Zubair_Muhammad
Community Champion
Community Champion

@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] ) )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

9 REPLIES 9
Zubair_Muhammad
Community Champion
Community Champion

@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] ) )
)

Regards
Zubair

Please try my custom visuals

Thanks Zubair, It works perfectly fine !!

@ajinkya1907

 

Welcome. Which team Kohli plays for Smiley Tongue?


Regards
Zubair

Please try my custom visuals

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.

@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] ) ) )
)

Regards
Zubair

Please try my custom visuals

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

Error_1.PNG

Add it as a calculated column.
Not as a measure

Regards
Zubair

Please try my custom visuals

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.

 

 

@ajinkya1907

 

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

 

runnerup.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.