Preppin’ Data — 2019W17
2 min readNov 8, 2020
A wonderful topic as I am working on this on the day of US election result. Here is a link to read more — How the world votes
Input
Solution Steps
We need to create 3 different flows and union the single line results to obtain the required output structure.
First past the post
- This approach only considers a single preference from each voter and thus we need to extract only first letter of the preferences and count the no. of votes
- Take Left([Voting Preference],1)
- Drop Voter and Voting Preferences column and add a column with a value of 1 so that its easier to aggregate on that column
- Aggregate on the First preference, Rank the total votes and filter for Rank 1
Alternate Vote
This is the most complicated approach among the three.
- Take Left(Voting Preference,1) and drop all other columns
- Aggregate the number of rows to calculate the overall votes. Create Total Votes and Max Votes LOD Fields to calculate if Max votes > Total Votes/2. If Yes, thats your winner. But here it is not.
- If not, Create a calculated field to Identify lowest number of voted candidate.
- This is the tricky part. Now join this with the original datasource and remove the least voted candidate from all preferences and then redo the process of counting.
Borda Count
- This approach assigns points based to all preferences in descending order
- Split the voting preference into 3 columns and name the columns First, Second and Third accordingly
- To be able to aggregate the overall points for each candidate, the data should be in rows so that it can be aggregated. Use Pivot — Columns to Rows.
- Write a calculated field to award points to the positions based on the column names.
- Aggregate after removing the voter column. Rank the vote count and filter for rank = 1
Output
Prep Flow
The flow can be accessed here — Github Link