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.
I have a table as follows
State | Constituency | Party | Votes |
UP | Noida | SP | 1000 |
UP | Noida | BJP | 500 |
UP | Noida | INC | 300 |
Gujarat | Dholera | SP | 300 |
Gujarat | Dholera | BJP | 2000 |
Gujarat | Dholera | INC | 400 |
I need to create a calculatedtable which should show the 'Party' with maximum 'Votes' in each 'State' and 'Constituency' combination.
If I use Summarize() I am only able to get a table like
State | Constituency | Max Votes |
UP | Noida | 1000 |
Gujarat | Dholera | 2000 |
What I need is like this:
State | Constituency | Party |
UP | Noida | SP |
Gujarat | Dholera | BJP |
I even tried GroupBy() function using CurrentGroup() using the below formula:
WinnerParty =
Solved! Go to Solution.
Hi @PranjalSaxena - Can you try the below calculated table in your model.
WinnerParty =
ADDCOLUMNS(
SUMMARIZE(
VotingResults,
VotingResults[State],
VotingResults[Constituency],
"Max Votes", MAX(VotingResults[Votes])
),
"Party",
SELECTCOLUMNS(
TOPN(
1,
FILTER(
VotingResults,
VotingResults[State] = EARLIER(VotingResults[State]) &&
VotingResults[Constituency] = EARLIER(VotingResults[Constituency]) &&
VotingResults[Votes] = EARLIER([Max Votes])
),
VotingResults[Votes],
DESC
),
"Party", VotingResults[Party]
)
)
It works please check.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Proud to be a Super User! | |
though one solution is accepted, i am giving one other solution,
first count the constituency numbers,
Then use the topn
Hi @PranjalSaxena - Can you try the below calculated table in your model.
WinnerParty =
ADDCOLUMNS(
SUMMARIZE(
VotingResults,
VotingResults[State],
VotingResults[Constituency],
"Max Votes", MAX(VotingResults[Votes])
),
"Party",
SELECTCOLUMNS(
TOPN(
1,
FILTER(
VotingResults,
VotingResults[State] = EARLIER(VotingResults[State]) &&
VotingResults[Constituency] = EARLIER(VotingResults[Constituency]) &&
VotingResults[Votes] = EARLIER([Max Votes])
),
VotingResults[Votes],
DESC
),
"Party", VotingResults[Party]
)
)
It works please check.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Proud to be a Super User! | |
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 |
---|---|
11 | |
10 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
13 | |
12 | |
11 | |
8 |