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.
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.
@Anonymous 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.
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
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
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.
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 |
---|---|
14 | |
9 | |
7 | |
7 | |
6 |
User | Count |
---|---|
21 | |
11 | |
10 | |
9 | |
8 |