This is a port of the lead calculator in Python. I believe I originally lifted the formula from UVA, but it's been a while. Steps to use: 1) Open new Google Sheet. 2) Navigate to Extensions tab at top, then Apps Scripts 3) Paste below script in. Ctrl+S, press run icon to populate your sheet with the required button (somewhere in here is a permissions check from Google; on one you'll need to click an "Advanced" button to grant permissions) 4) In top navbar, there should be a new entry called "Custom Scripts"; click and click "Create Tabs with Formulas." It'll take a few seconds to create all the sheets. (note if you click this button again, it will delete all your polling data and start fresh!) 5) From there, just populate columns A, B, and C with your poll data. L column shows %chance Candidate A is in the lead in the state. This was a lot easier to do before ABC gutted 538. Personal suggestion is to only use polls with LVs and ignore RV polls, and to prefer those with third-party candidates (in case pollster has one with and one without). I don't believe partisan-funded polls should be excluded **unless** the pollster is not credible. Script follows: function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Scripts') .addItem('Create Tabs with Formulas', 'createTabsWithFormulas') .addToUi(); } function createTabsWithFormulas() { var ss = SpreadsheetApp.getActiveSpreadsheet(); // List of sheets to create var sheetsList = [ "National", "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming" ]; for (var i = 0; i < sheetsList.length; i++) { var sheetName = sheetsList[i]; var sheet = ss.getSheetByName(sheetName); // If the sheet exists, clear it; else, create it if (sheet) { sheet.clearContents(); } else { sheet = ss.insertSheet(sheetName); } // Set up the headers var headers = ["Candidate A Poll%", "Candidate B Poll%", "Sample Size"]; sheet.getRange("A1:C1").setValues([headers]); // Style the headers sheet.getRange("A1:C1").setFontWeight("bold").setBackground("#CCCCCC"); // Set data validation for Candidate A and B Poll% (0-100) var pollValidation = SpreadsheetApp.newDataValidation() .requireNumberBetween(0, 100) .setAllowInvalid(false) .build(); sheet.getRange("A2:B").setDataValidation(pollValidation); // Set data validation for Sample Size (positive integers) var sampleValidation = SpreadsheetApp.newDataValidation() .requireNumberGreaterThan(0) .setAllowInvalid(false) .build(); sheet.getRange("C2:C").setDataValidation(sampleValidation); // Set up cells for weighted averages and calculations sheet.getRange("E1").setValue("Weighted Avg A (%)"); sheet.getRange("F1").setValue("Weighted Avg B (%)"); sheet.getRange("G1").setValue("Total Sample Size"); sheet.getRange("H1").setValue("c1"); sheet.getRange("I1").setValue("d"); sheet.getRange("J1").setValue("e"); sheet.getRange("K1").setValue("f"); sheet.getRange("L1").setValue("Probability (%)"); // Style the calculation headers sheet.getRange("E1:L1").setFontWeight("bold").setBackground("#CCCCCC"); // Formulas for weighted averages and total sample size sheet.getRange("E2").setFormula("=IFERROR(SUMPRODUCT(A2:A, C2:C) / SUM(C2:C), 0)"); sheet.getRange("F2").setFormula("=IFERROR(SUMPRODUCT(B2:B, C2:C) / SUM(C2:C), 0)"); sheet.getRange("G2").setFormula("=SUM(C2:C)"); // Formulas for intermediate calculations sheet.getRange("H2").setFormula("=((E2*0.01 + F2*0.01) * G2)"); sheet.getRange("I2").setFormula("=SQRT(((E2*0.01 + F2*0.01) - (E2*0.01 - F2*0.01)^2) / H2)"); sheet.getRange("J2").setFormula("=(ABS(E2 - F2) + (I2 * 1.96 * 100)) + (0.5 / H2)"); sheet.getRange("K2").setFormula("=(ABS(E2 - F2) - (I2 * 1.96 * 100)) - (0.5 / H2)"); // Formula for probability calculation sheet.getRange("L2").setFormula("=ROUND(NORM.S.DIST(((E2 - F2)*0.01)/I2) * 100, 2)"); // Optional: Auto-adjust column widths sheet.autoResizeColumns(1, 12); } }