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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
PranjalSaxena
New Member

Summarize on one column but select another column

I have a table as follows

StateConstituencyPartyVotes
UPNoidaSP1000
UPNoidaBJP500
UPNoidaINC300
GujaratDholeraSP300
GujaratDholeraBJP2000
GujaratDholeraINC400


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

StateConstituencyMax Votes
UPNoida1000
GujaratDholera2000


What I need is like this:

StateConstituencyParty
UPNoidaSP
GujaratDholeraBJP


I even tried GroupBy() function using CurrentGroup() using the below formula:
WinnerParty =

GROUPBY(VotingResults, VotingResults[State], VotingResults[PC Name], "WinnerParty", SELECTCOLUMNS(FILTER(CurrentGroup(), VotingResults[Total Votes] = MAXX(CURRENTGROUP(), [Total Votes])),[Party]))

Here, I am trying to FILTER() the row in currentgroup() having maximum votes and then SelectColumn() the 'Party' Column.
But I am getting error:
Function 'GROUPBY' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup().




1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

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

 

rajendraongole1_0-1719935641247.png

 

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!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
Anonymous
Not applicable

though one solution is accepted, i am giving one other solution,

first count the constituency numbers,

Rakesh1705_0-1720018041201.png

Then use the topn

Rakesh1705_1-1720018072211.png

 



rajendraongole1
Super User
Super User

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

 

rajendraongole1_0-1719935641247.png

 

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!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.