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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
dilbagsidhu
Frequent Visitor

find election winner

hello, im intermediate in power BI and im stuck at one problem,
where i have to calculate a winner candidate and party seprerately based on total votes in a constituency. i have data of 2 seperate year elections and need to do it for both year. im attaching data table screenshot, please guide me what ccould be best way, direct dax mesure or creating new table.. thankyou in anticipation of your help. counting on you all.table.png

3 REPLIES 3
dilbagsidhu
Frequent Visitor

2.png3.png

 

@v-jtian-msft hello, thankyou for you help,its what i needed, but it not getting candidate with maximum votes

Hi,@dilbagsidhu .
Thank you for your reply.
According to your description, the code I provided does not give the correct result in your computing environment.
From the screenshot you provided, it appears that you are using a matrix to display the results, could you please tell me if the screenshot you are displaying is the result of a direct calculation using the code I provided.
Unfortunately, the result can be affected by several external filters, for example, Total Votes in your matrix is affected by the current row. What I want to express is that the solution I provided is correct in my calculation environment, but the actual calculation environment is much more complicated than when I tested it. for example :in filter() function ,Screened for sex, so the code will not get the correct result in your calculation environment.
So can you provide some non-sensitive data (if not the basic data, can you provide the code for the measure you showed in the screenshot)
This will help to solve your problem.

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-jtian-msft
Community Support
Community Support

Hi,@dilbagsidhu 
I am glad to help you.

According to your description, you want to calculate the name of the candidate who won each year's election and his/her corresponding political party separately according to the year

If my understanding is correct, you can refer to my suggestion.

Here is my test data (I simulated part of the data because the original data is too large, please correct me if there is any error)

State	Consituency	Candidate	Sex	Age	Category	Party	Party symbol	General votes	Postal Votes	Total votes	Total electors	Year
Uttar Rradesh	Baghpat	jack	Male	27	GEN	IND	Cas Stove	3975	0	3975	1505175	2014
Tamil Nadu	Chennai North	lucy	Female	47	GEN	IND	Bat	414	0	414	1422392	2014
Tamil Nadu	Chennai North	charavanan.M.P	Male	46	GEN	IND	Shuttle	1198	0	1198	1422392	2014
Tamil Nadu	Chennai North	Srimivasan.J	Male	53	GEN	IND	Ring	475	0	475	1422392	2014
Tamil Nadu	Chennai North	Deepak.C	Male	46	GEN	IND	Cot	712	0	712	1422392	2014
Tamil Nadu	Chennai North	Raja.B	Male	27	GEN	IND	Stool	964	0	964	1422392	2014
Uttar Rradesh	Baghpat	Dacs	Male	28	GEN	IND	Cas Stove	3980	0	3980	1505180	2015
Tamil Nadu	Chennai North	lily	Female	47	GEN	IND	Bat	414	0	414	1422392	2015
Tamil Nadu	Chennai North	charavanan.M.P	Male	46	GEN	IND	Shuttle	1198	0	1198	1422392	2015
Tamil Nadu	Chennai North	Srimivasan.J	Male	53	GEN	IND	Ring	475	0	475	1422392	2015
Tamil Nadu	Chennai North	Deepak.C	Male	46	GEN	IND	Cot	712	0	712	1422392	2015
Tamil Nadu	Chennai North	Raja.B	Male	27	GEN	IND	Stool	964	0	964	1422392	2015

vjtianmsft_0-1716441759936.png

Here's the measure I created, counting the candidates with the most votes and their parties, respectively.

and filtered the results by adding [Year] to the slicer.

M_totalVotes = SUM(ElectionData[Total votes])

 

M_WinCandidate = 
VAR MaxVotes= MAXX('ElectionData',[M_totalVotes])
RETURN
CALCULATE(MAX('ElectionData'[Candidate]),FILTER('ElectionData','ElectionData'[M_totalVotes]=MaxVotes))

 

M_WinParty = 
VAR WinCandidate=[M_WinCandidate]
RETURN
CALCULATE(MAX('ElectionData'[Party]),FILTER('ElectionData','ElectionData'[Candidate]=WinCandidate))

Shown below are the final test results

vjtianmsft_1-1716441834333.png

vjtianmsft_2-1716441852456.png

I hope my suggestions  give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Kudoed Authors