Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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.
Solved! Go to Solution.
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] ) ) )
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] ) ) )
Thanks Zubair, It works perfectly fine !!
Welcome. Which team Kohli plays for ?
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.
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] ) ) ) )
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
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.
So if you have three Columns already for Teams 1 and 2 and winner. This will give you the Runner Up Name
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
64 |
User | Count |
---|---|
135 | |
120 | |
101 | |
71 | |
61 |