Quantcast
Channel: Excel - Smart Fantasy Baseball
Viewing all 59 articles
Browse latest View live

Easily Combine Multiple Projection Systems

$
0
0

COMPARE_HITTERS

After over a year of working on this and getting feedback from a very helpful group of SFBB readers, the “Projection Aggregator” Excel file is finally ready!

The Projection Aggregator is an easy to use Excel spreadsheet that can combine (or average) up to three different projection sets to give you the best possible set of projections to use for the upcoming season. You can use just about any well known projection source you have at your disposal. Download your favorite projections, fill out some settings, and you’re done.

No complicated formulas. No VLOOKUPs. Just download your projections, bring them in to the Aggregator, and you’ll have better projections in minutes. Click here to find out more.


How to Update the Player ID Map in your Spreadsheets

$
0
0

You’ve been following the site for a while. You’ve even created a spreadsheet to develop your own points league or SGP rankings. You’ve spent all this time building this spreadsheet but it’s getting to be a bit out of date. Players have been traded, rookies have been called up from the minors…

How do you update things? Do you have to rebuild your spreadsheets from scratch each season?

No way, give me some credit! I’m smarter than that. I design things to be reusable.

In this post I’ll show you how to quickly and easily update the Player ID Map in your spreadsheet so you can get updated MLB teams and have new players available to tie in to your projections.

Warning!

All we’re really doing here is downloading the new version of the Player ID Map and pasting it on top of our existing Player ID Map already in your ranking file. The key is that you have to be very particular about how you paste the new version in. If you’re not careful you will break all the existing formulas in your spreadsheet that reference the PLAYERIDMAP named table.

Read carefully!

Step-by-Step Instructions

Step Description
1. Open your existing rankings spreadsheet, the one in which you want the new Player ID Map information. Save a backup copy of the file, just in case something were to go wrong during this process.

Go to the PLAYERIDMAP tab.PLAYER_ID_MAP

2. We will soon be pasting information onto this sheet so it is important to make sure all the data is currently showing.

Click on Excel’s “Data” tab and then click the “Clear” button of the “Sort & Filter” icon grouping. CLEAR_FILTERS

3. Click this link to download an updated copy of the Player ID Map.

Once the download completes, open the file. If Excel is displaying any kind of warning message, enable your ability to edit the file (provided you trust this site).ENABLE_EDITING

4. Place your mouse in cell A1 of the newly downloaded Player ID Map. Then hit the CTRL + SHIFT + End keys all at once. After you’ve done this release the keys. Then hit SHIFT + the up arrow key.LAST_PLAYER
This set of key strokes should select the entire Player ID Map table and then deselect the “Last Player”.

Now hit CTRL + C to copy the selected data.

5. Return to your customized rankings spreadsheet. Select cell A1 with your mouse and then paste the data you just copied over cell A1.

The reasoning behind this specific set of copying and pasting instruction is so that the existing table named “PLAYERIDMAP” in your rankings spreadsheet will not be renamed during this process. If you don’t deselect the “Last Player” before copying, the entire Player ID Map table will be renamed and it will break all existing VLOOKUP formulas you have looking for this information.

6. That’s it!

Well, kind of. Any new players added to the PLAYERIDMAP will not yet be listed on your “Hitter Ranks” or “Pitcher Ranks” worksheets.

This is where you have a decision to make.

If you have taken notes next to players, entered keeper dollar values, or otherwise “hard entered” information that relates to a specific player, then you manually add the player IDs of “new” players to your “Hitter Ranks” or “Pitcher Ranks” tabs.

For example, simply go to the “Hitter Ranks” tab and type the player’s ID at the very bottom of the first column. When you hit enter the Excel table should grow to add your new player and all the other formulas should automatically copy down (another benefit of using Excel tables!). FRANCISCO_LINDOR

If you’re not sure what players were added to the PLAYERIDMAP, you can look on the “CHANGE LOG” tab on the newly downloaded Player ID file to see a brief note of all the players added or updated recently. CHANGE_LOG

I try to put brief descriptions of the players that have been added so you can manually add to your “Hitter Ranks” or “Pitcher Ranks” sheets, if necessary.CHANGE_LOG_INFO

7. If you have not edited dollar values or added player notes, you can copy and paste the hitter IDs onto the “Hitter Ranks” sheet and the pitcher IDs on to the “Pitcher Ranks” sheet.

To do this, go to the PLAYERIDMAP tab in your spreadsheet and apply a filter to only show hitters. On the “POS” column filter, uncheck the “N/A” (if there are any) and “P” check boxes. This will only display the hitters.POSITION_FILTER

Then select cell the first cell below the header in column A and hit the SHIFT + CTRL + Down Arrow Key. SHIFT_CTRL_DOWNCopy this information and go to your “Hitter Ranks” tab and paste it into the first cell below the header in column A there.PASTE_HITTER_LIST

After you do this all the other information on the tab should update immediately.

No go back to the PLAYERIDMAP tab and adjust the filter to only show pitchers and repeat the process by pasting those players onto the “Pitcher Ranks” tab.

Now you’re done!

Have Any Questions?

Please leave a comment on this post.

I have to do this quite frequently to keep all the spreadsheets I maintain for the site up-to-date, but this is probably something you’ll only need to do a few times a year. Maybe after the season ends, to get all the new players I’ve added during the season, late February, to get all the players that have changed teams, and once during the season, if you’re doing in-season rankings.

Want More Tips Like This

Make sure to follow me on Twitter, that’s the best place to hear about new posts and updates at the site.

How to Add Average Draft Position Info to Your Spreadsheet

$
0
0

I think you’re gonna like this one.

In this post I’ll show you how to link live average draft position information from the web into your draft spreadsheet. Every time you open your rankings file it will pull down updated ADP information. Bam!

How We’re Going To Do This

We will use a powerful feature of Excel called web querying to pull in the ADP information aggregated by FantasyPros.com (please note, I’m an affiliate of Fantasy Pros). The web query will suck up that table of ADP information and bring it directly into Excel for us to then VLOOKUP into our existing “Hitter Ranks” and “Pitcher Ranks” tabs.

Fantasy Pros has the best ADP information I've found on the web. They have the most sources in one place and it appears to be updated regularly.

Fantasy Pros has the best ADP information I’ve found on the web. They have the most sources in one place and it appears to be updated regularly.

Assumptions

I am assuming that you’ve followed my Standings Gain Points or Points-League Ranking series and are already starting with a spreadsheet that is based off one of those (you don’t have to have those exact spreadsheets, but something similar).

Excel Functions and Concepts Used in this Post

Web Query

As you can probably imagine, the power of the web query is that it automatically updates the data in your Excel file without you having to do ANYTHING after the initial setup.

Web queries are created from the “Data” tab on the Excel Ribbon, under the “Get External Data” icon grouping. There are several ways to get data from outside sources into Excel, we will be using the “From Web” button.

GET_EXTERNAL_DATA

One “weakness” I have found in web queries is that they cannot work with “tables” in Excel. You cannot pull a web query in as the data of a table. If you’re a big follower of this site you know that’s a bit of an issue for me because I use tables all the time. Thankfully this doesn’t prevent us from doing things, I just point it out because you might wonder why I set things up the way I do in the instructions below.

Find

The FIND function searches within a specified cell for a string of text that you provide. If the FIND function locates the string, it will return the character position where the string starts at.

I know, you’re thinking “What the heck does that even mean?”. Here’s an example. Let’s say we have the text “Mike Trout (LAA)” in a cell and every player in our whole spreadsheet follows that format. If we want to pull out each player’s team we will need to start by figuring out where the team name starts in that cell. And we can’t just say it will always start at the 13th character each time when we have players like this hanging around MLB.

Instead we can use the FIND formula to intelligently determine where that opening parenthesis is for each player (it starts at 12 for Trout and 23 for Salty).

This formula requires two inputs:

FIND(Find_text, Within_text)

FIND


  1. Find_text – This is the string of text you are searching for and keep in mind it is case-sensitive. You would wrap the string you are searching for in quotation marks. So in our example above, to look for the opening parenthesis you would enter “(” here. Or if you’re trying to be slightly more precise, you could enter ” (“, a space before the parenthesis.

  2. Within_text – This is the text you want to search WITHIN. This can be a cell number.

Left

The LEFT function gives you the leftmost number of characters in a text string. You also get to specify the number of characters to specify.

For example, if you have a text string of “Mike Trout (LAA)” and you ask for the 10 leftmost characters in that string, you would get “Mike Trout” back.

This formula requires two inputs:

LEFT(Text, Num_chars)

LEFT_FUNCTION


  1. Text – This is the text string you want the leftmost characters from.
  2. Num_chars – This is the number of characters you want from the string. This can be a hard entered number (e.g. 10) or it can be a formula itself that results in a number.

Combining Functions Together

We can do something pretty powerful by combining the FIND and LEFT functions together. I’ve been hinting at it with this “Mike Trout (LAA)” example. Recall from above that the LEFT function wants to know our text string (“Mike Trout (LAA)”) and the number of characters on the left to pull from that string.

Assume that cell B2 has a value of “Mike Trout (LAA)”. Instead of using this formula:

LEFT(B2, 10)

We can use this:

LEFT(B2, FIND(" (",B2)-1)

The FIND(" (",B2)-1 part of the formula returns a 10 (if you don’t subtract the one it returns an 11), and “Mike Trout” has 10 characters in it (including the space). By using this combination of functions we don’t have to type in a “10” for Mike Trout and a “21” for Saltalamacchia.

Important Prerequisite

Before you’re able to proceed with the instructions below you must make sure the PLAYERIDMAP in the file you’re working with was updated after February 21st, 2015. I added a column to the Player ID Map called “FANTPROSNAME” that is necessary for the steps below to work.

Instructions for updating your PLAYERIDMAP can be found here. Completing the update should only take five minutes or so.

Step-by-Step Instructions

Step Description
1. Make sure you’ve completed the update of your PLAYERIDMAP tab mentioned above. Once that’s completed, insert a new sheet into your existing rankings spreadsheet.NEW_SHEET
2. Place the sheet next to your “Hitter Ranks” and “Pitcher Ranks” tabs. Name this new sheet “ADP Info”.ADP_INFO
3. Our goal is to pull the ADP information from FantasyPros.com into this new tab. The web address of the page containing the ADP information is http://www.fantasypros.com/mlb/adp/overall.php. Use your mouse to select and then copy that address.FANTASYPROS_ADP_INFO
4. Place your mouse cursor on cell A1 of the new blank worksheet and click to select that cell. Then go to the “Data” tab of Excel and click on the “Data From Web” icon.

DATA_FROM_WEB

In the “New Web Query” window that pops up, paste the ADP web address into the “Address:” field and click the “Go” button.PASTE_URL

5. I will frequently get error messages popping up at this point asking me, “Do you want to continue running scripts on this page?”. This is not unique to this example, I get those on just about every web query I do.

Click No. You may have to answer the question several times.

YELLOW_ARROWOnce you’re through those error messages you should see the Average Draft Position info. This Excel dialog gives us a preview of the web address we pasted in and we now must choose to import the entire web page into Excel or we also have the option to isolate a specific table for importing. Whenever possible, I recommend isolating in on the the specific table you are after. To choose just a specific table, look for the small yellow arrow in the top left corner of that table.

You should see one of these yellow arrows in the top left of the ADP table.

The tables at FantasyPros are web query friendly. You can try performing web queries of other sites and you might find that the yellow arrows do not appear on each individual table. In these cases you’ll need to import the entire web page and then use other Excel formulas to isolate in on the information you want. This can be difficult to do… pray for the yellow arrows!

Click the yellow arrow on the ADP information and you should see the table get selected (it shades light blue).SELECT_TABLE_WEB_QUERY

6. After the data is selected, click the “Import” button.IMPORT_WEB_QUERY

You will then be asked “Where do you want to put the data?”. You should see that Excel will add the data to cell A1 on the existing worksheet, this is what we want. But before we do the import, click the “Properties” button.IMPORT_DATA_PROPERTIES

Type “ADP_INFO” into the “Name:” field in case you ever add future web queries to your sheet (so you can tell by the name what the queries are doing). Then check the “Refresh data when opening the file” box. This will retrieve new ADP info each time you open your draft spreadsheet. EXTERNAL_DATA_PROPERTIES

7. Click “OK” to accept your changes to the “External Data Range Properties” dialog. Then click “OK” to start the data import. Excel will think for awhile and bring in the ADP info!COMPLETED_QUERY
8. Our next challenge will be to pull the ADP information from this tab to our “Hitter Ranks” and “Pitcher Ranks” tabs. And it’s going to take a bit of work to do this.

If you’re a frequent follower of the site you should be cringing a little when you look at this data… There are no player IDs! GASP!

We are going to have to match and pull data using just player names. And to make matters worse, the FantasyPros data isn’t just the player name. You can see from the image below it also contains the player’s team and position inside parentheses.QUERY_DATA

We need to isolate just each player’s name and strip away the parenthetical information. We can do this using the FIND and LEFT formulas discussed above. We’ll start with the FIND formula and use it to locate the position of the opening parenthesis. Use your mouse to select cell J2 (this should be a couple columns to the right of the player with the highest ADP, Mike Trout as I write this).

Enter the following formula in cell J2 (I chose column J to give a little bit of cushion in case FantasyPros adds more columns to their ADP report):

=FIND(" (",B2)

Note there is a space before the opening parenthesis. This is because after each player’s name is a space and then the opening parenthesis and I want to be as specific as possible to help Excel find this.

Hit Enter to accept your formula. Excel is telling us that the " (" starts at character number 11 in Mike Trout’s cell.MIKE_TROUT

9. If the " (" starts at character 11, then that means we want to use the LEFT formula to pull out the first 10 characters of Trout’s name cell. To do this we will enter the LEFT formula around the FIND formula we just added. The FIND formula will be an input into our LEFT formula. Adjust your existing FIND formula to be (the new parts of the formula are in red):

=LEFT(B2,FIND(" (",B2)-1)

Recall that the LEFT formula is looking for the cell to evaluate (B2, or "Mike Trout (LAA - CF)"). Then the second input (our FIND formula) is the number of characters to pull from that cell. For this we don’t want to capture the space (from the " ("), so we subtract 1 (we only want “Mike Trout” not “Mike Trout “).

10. BLACK_CROSSUse your mouse to select the new “Mike Trout” name we just created. Then hover your mouse over the little black square on the lower right hand corner. You should see the cursor turn to a cross or plus sign. Click your mouse and drag this down for as far as the ADP information goes on the spreadsheet.

This new column of player names corresponds to the “FANTPROSNAME” column in the PLAYERIDMAP and we can now use a VLOOKUP to get at this information.FANTPROSNAME

11. I mentioned at the beginning of this article that we cannot turn the data that comes from the web query into an Excel table, but we can turn these player names off to the side of the web query into a table.

To do this, give the list of players a column name (e.g. “FANTPROSNAME”). FANTPROSNAME_LABELThen click the “Format as Table” buttonFORMAT_AS_TABLE

12. After you format the table you should be placed into the “Table Tools” menu (if you’re not, click once on an item within the table and you should see this menu appear on the ribbon). Give your table a more meaningful name, like “ADPINFO”.TABLE_INFO
13. Type “ADP” in next to the “FANTPROSNAME” column. After you hit Enter Excel should expand the table to include this new column.ADP_COLUMN

Now choose what you think is the best ADP source of information for your purposes. If you’re preparing your spreadsheet for an NFBC draft or a Yahoo Public League, you may want to choose just those columns as your sole source. For this example I will choose the “AVG” column provided by Fantasy Pros.

I now want to pull the “AVG” column from the web query into the “ADP” column in my new table. To do this I’ll enter the formula =G2 in the first row of my ADP column.ADP_FORMULA

Hit Enter and the formula should copy down and adjust accordingly to all rows in the ADPINFO table.ADP_ALL_PLAYERS

14. Now that the web query and ADPINFO table are set up, we can add the VLOOKUP formulas to the “Hitter Ranks” and “Pitcher Ranks” sheets.

Go to the “Hitter Ranks” sheet and add two new columns to the far right of your spreadsheet. Label one “FANTPROSNAME” and one “ADP”.NEW_COLUMNS

15. In the FANTPROSNAME column we will use the PLAYERID (in column A) to go into the PLAYERIDMAP tab, locate that PLAYERID, and then return the player’s name from the FANTPROSNAME column in the PLAYERIDMAP (FantasyPros does not use an ID system, so we must match things using player names as they appear on that site).

Fortunately we already have a column on the “Hitter Ranks” tab, IDFANGRAPHS, that is doing this same thing and we can copy the formula and make a minor edit. Click on the Fangraphs ID (in the IDFANGRAPHS column) for the first player in your spreadsheet. Copy this cell. Then go to the FANTPROSNAME column and paste the formula.PASTE_FORMULA

This will bring over the Fangraphs ID information. The formula we just pasted is:

=VLOOKUP([@PLAYERID],PLAYERIDMAP,COLUMN(PLAYERIDMAP[IDFANGRAPHS]),FALSE)

We can make one minor edit to get the Fantasy Pros Name (the edit is in red):

=VLOOKUP([@PLAYERID],PLAYERIDMAP,COLUMN(PLAYERIDMAP[FANTPROSNAME]),FALSE)

Note, your formula may have the “IFERROR” function wrapped around the VLOOKUP formula. This is great. If the formula you just pasted DOES NOT use “IFERROR” before the VLOOKUP, add that now. So now your formula would be:

=IFERROR(VLOOKUP([@PLAYERID],PLAYERIDMAP,COLUMN(PLAYERIDMAP[FANTPROSNAME]),FALSE),0)

16. We can now use the FANTPROSNAME info to perform a VLOOKUP into the ADPINFO table we just created. Enter the following formula into the ADP column:

=VLOOKUP([@FANTPROSNAME],ADPINFO,2,FALSE)

This formula attempts to take the player’s name in the FANTPROSNAME column, find it in the ADPINFO table, and give us back what is in the second column (hence the 2 in the formula) of the ADPINFO table (which is the ADP info).
ADP_VLOOKUP

Hit Enter when you’ve finished typing/copying the formula. You may then have to select the entire ADP column and use the number formatting buttons in Excel to format the information correctly.NUMBER_FORMATTINGDECIMAL_POINTS

17. Repeat steps 14, 15, and 16 on the “Pitcher Ranks” tab in order to add pitcher ADP information there.
18. After you’ve added the ADP information to the “Hitter Ranks” and “Pitcher Ranks” tabs you can then hide the FANTPROSNAME columns from those. Just don’t delete them, the VLOOKUP formulas to get the ADP need that column to work. HIDE_COLUMN
19. That’s it! Each time you open your rankings file it will be updated with the newest ADP information.

Have Questions?

Please ask me any questions you have about this in the comments area at the end of this post.

Want to Know How to Do Something in Excel?

If you have a suggestion or question on how to do something fantasy baseball related in Excel, shoot me an e-mail at smartfantasybaseball at gmail dot com.

Want More Info Like This?

The best way to stay in touch with the site and to get more information like this is to follow me on Twitter or to register as an SFBB Insider.

Stay smart!

How to Automatically Shade Drafted Players In Excel

$
0
0

I know, I know. It’s mid-March, college basketball is taking over your time, and you’re in the final push of draft preparation for your baseball leagues. The last thing you want to do right now is start tinkering with your draft spreadsheet and screw something up.

Then here I come with another monster Excel post…

NOT THIS TIME! I swear. This is an easy one and you might find it helpful.

In this post I’ll show you how to use Excel’s conditional formatting to gray out players that have been chosen during your draft.

Excel’s Conditional Formatting

Conditional Formatting is a way to adjust the format of individual (or many) cells based upon the information within that cell. If you were using this in a business spreadsheet you might want really high sales months to show up in bolded font or below average sales people to show up shaded in red.

For fantasy baseball you might want all players projected to hit 30 HR to have their HR projection in bold red font. Who knows.

The point is you can tell Excel “what to format” and “how to format it”.

Here’s an example of what I’ll show you in this specific post:EXAMPLE_DRAFTED_PLAYERS

Assumptions

I’m using Excel 2013 in the screenshots below. I think this will work on Excel 2007 or 2010 without any issues. I’m also assuming you’re starting with a spreadsheet you created following either this standings gain points series or this points league series.

Step-by-Step Instructions

Step Description
1. The first thing you need to do is decide how you will track drafted players. You could use the method I’ve described here. Or if you’re in an auction you could track who has been drafted simply by putting the dollar value each player was sold at in the $ACTUAL column of your spreadsheet.

It doesn’t matter what method you choose, but for this example I’m going to assume that whatever column you use to track will be blank if the player has not been drafted and there will be some value in the column if the player has been chosen.

Make note of the column number of your choice. For example, I’ll be using column “AB” based on the image below.DOLLAR_ACTUAL

2. Click on the first player ID in column A of your “Hitter Ranks” tab. Then hit CTRL + SHIFT + END (all at the same time) to select the remaining rows and columns in the table (Excel should highlight all players and columns).

Then on the “Home” tab of the ribbon, click the “Conditional Formatting” drop down and choose “New Rule…”.CONDITIONAL_FORMATTING_NEW_RULE

3. In the “New Formatting Rule” dialog that pops up, select the last option of “Use a formula to determine which cells to format”.USE_FORMULA_TO_DETERMINE
4. In the “Format values where this formula is true:” box, enter the following formula

=$AB6<>""

The reason I’m using cell AB6 in this formula is because my $ACTUAL column is where I’ll be tracking who’s been drafted (and that’s column AB). The reason row 6 is referenced is because I added some information above my table to help define where players a slotting for determining replacement level (whether they’re a starter, falling to MI or CI, UTIL, etc.). My first player doesn’t appear in the sheet until the sixth row.ROW6

A few things to keep in mind about this formula. The equals sign at the beginning is very important. Excel will let you get away without typing in the equals sign but then the formula will not work properly.

In plain English, the <>"" part of the formula is “does not equal blank”. The greater than and less than symbols facing each other means “not equal” to Excel. The fact that there is nothing between the consecutive double-quotes is how to tell Excel to look for a blank cell (or in this case, not a blank cell).

The dollar sign before cell “AB6″ is to tell Excel, “Only look in column AB for the blank cells”. If we left the dollar sign out Excel would start shading seemingly random areas. If you get to the end of this set of instructions and you have weird shading showing up, check this again.
FORMULA

5. Now that we’ve given the instructions on what to shade, let’s decide how to shade these drafted players. Click the “Format…” button.FORMAT_BUTTON
6. You can format a variety of things for each cell (although some options gray out when you have a large block of cells selected like we do). The “Fill” tab will allow you to shade cells a certain color.FILL_TAB

I’m going to shade drafted players gray. After you’ve chosen your color click “OK” to accept your color choice and then “OK” to accept the conditional formatting rule (we’re done setting up the rule now).SHADE_GRAY

7. If you have not entered any auction values or that any players have been selected, nothing will be shaded yet. To test that everything is working, add a dollar value to the “$ACTUAL” column or enter a team name in the “LGTEAM” column (from this example).TEST_MIKE_TROUT
8. If you get to the end and you find out the formatting is not working properly, you can edit the rule by going to the “Manage Rules” drop down option under the “Conditional Formatting” menu on the ribbon.MANAGE_RULES

Then select your rule and click the “Edit Rule…” button.EDIT_RULE

Think of What Else is Possible


Conditional Formatting in Excel is something a lot of people don’t know about and even those that do know it exists can find it intimidating. It can be confusing to work with, but if you follow the principles outlined above, you’ll be able to do some really neat things.

I’ve only given you one small practical way to use this. But there are A LOT of other neat things you could do with this.

Want to shade all outfielders a certain color? Or highlight all players with multiple position eligibility? How about tell the difference between a starter and a reliever? Left-handed hitters versus righties? Shade all injured players red so you don’t draft them?

Have Questions?

Please ask me any questions you have about this in the comments area at the end of this post.

Want to Know How to Do Something in Excel?

If you have a suggestion or question on how to do something fantasy baseball related in Excel, shoot me an e-mail at smartfantasybaseball at gmail dot com.

Want More Info Like This?

The best way to stay in touch with the site and to get more information like this is to follow me on Twitter or to register as an SFBB Insider.

How to Use Excel to Web Query DFS and Other Fantasy Baseball Data

$
0
0

With a web query there will be no more manual copying and pasting of data.

With a web query there will be no more manual copy and pasting of data.

Does this sound familiar?

You’re doing prep work for setting a daily lineup or even preparing for a season-long rotiserrie league. You’re trying to set up a spreadsheet to help you prepare, but you are sick and tired of having to copy information from the web and paste it into Excel.

There has to be a better way!

In this post I’ll show you an efficient way of grabbing player salaries directly from FanDuel’s website using Excel’s web query function. In fact, I’ll show you three different variations of Excel web queries:

  1. Simple web query
  2. Dynamic web query
  3. Table-specific web query

Before I begin, I need to be honest with you about something.

I Don’t Know Where We’re Going

This is the first post of what I hope will be a series documenting how to build a spreadsheet for DFS. But the thing is, I don’t know exactly where I’m headed on this journey. I can’t promise you a panacea to cure all your DFS aches and pains. I don’t have a master plan that will lead us to a perfect functioning spreadsheet that will fit everyone’s exact desires. But my plan is to just start moving the ball in the right direction.

I don’t have much DFS experience. I don’t know exactly what you want. If you are looking for DFS lineup advice, I can tell you I won’t be giving that. But what I do have are a very particular set of skills. Skills I have acquired over a very long career… OK, I’ll end my Liam Neeson joke.

I hope that by just starting to build something, starting to share techniques you can use on your own, and by seeking feedback, we will eventually end up with something special.

Some of the techniques I’ll show you may seem silly. Or pointless. Or way too involved.

But I have a purpose in mind. You might wonder why I pull data from Site Y when Site X has the same information in an easier to use format. Or you may want to incorporate additional data that I don’t want to pursue.

That is why I want to stress it is not the “WHAT” in the instructions that is the important part. It is the “HOW”. I’m going for that whole “teach a man to fish” proverb. So let’s start learning…

Not All Versions of Excel are Created Equal

I’ll be using Office 2013 installed on a Windows 7 machine. I believe the web querying experience will be similar for Office 2007 and Office 2010 (while using Windows). Unfortunately, I have had poor results with web querying in Excel for Mac, but it can be done.

What Is a Web Query?

A web query is an automated way to copy information from a table on a web page into Excel. It removes the need for you to manually copy and paste data from websites into Excel. On top of that, you can set the query up to run each time you open an Excel file or change a particular value, so you can escape the cycle of continuously needing to go to a web site, copy the data, and paste it into Excel each day you want to set lineups. It can refresh automatically!

As you’ll soon see, setting up a basic web query is fairly easy. But there are a couple of more advanced settings that should make your life a little bit easier.

Step-By-Step Instructions, Simple Web Query

For this example, let’s just go with a simple and straight-forward web query. Later in this post we will build on this.

Step Description
1. Log into your FanDuel account using Internet Explorer.

If you don’t have one, you can sign up through this affiliate link (what’s an affiliate link?).

The reason we have to do this is because Excel uses a browser (Internet Explorer) to perform the web query, but won’t be able to access the FanDuel web site if it doesn’t have your log in information. So logging into Internet Explorer will provide that and allow Excel to get through FanDuel’s authentication. If you have Google Chrome or another browser installed on your computer, it’s still important to do this log in through Internet Explorer because that’s the browser Excel uses for the web query.

2. Once you’ve logged in, locate a contest you want to enter. Don’t click on anything yet. Just identify one. You will be able to change your mind later on the exact contest, but you do want to pick one for the slate of games you want to play with (if you want to play the late game slate, don’t pick a contest that includes only early games).

It is important that you choose a “contest” and not one of the public head-to-head competitions that are available. For example, you could choose the third or fourth contest shown in the image below but not the “vs. csuram88″ H2H matchups. Choose_FanDuel_Contest

After you have identified a contest, hover your mouse over the “Enter” button.FanDuel_Enter_Button

Then note the URL that button will take you to in the lower right hand corner of Internet Explorer (this is a good tactic to use if you think a link on a website is going to take you somewhere fishy, hover over a link on the web and see the website you’ll be taken to).FanDuel_URL

3. Right-click on that same “Enter” button and choose the option to copy the shortcut.Right_Click_Copy_Link
4. Open Excel and start a blank file. Eventually you can do this on a blank tab in an existing spreadsheet you’ve started, but I’d recommend using a test file for now until you decide exactly how you want to set up your query. On the “Data” tab, choose the “From Web” option.Data_From_Web

Once the “New Web Query” window pops up, paste the link you just copied into the “Address:” field and hit the “Go” button.
New_Web_Query

I get a variety of script errors every time I perform a new web query. It’s not unusual, and you can probably answer so that you stop running scripts on the page.Script_Error_Web_Query

5. Once the web page fully loads in the web query preview, look for small yellow squares containing an arrow pointing to the right.

These squares are intended to allow you to choose specific pieces or components of the web page to pull in. Or you could elect to import the whole entire page.

You will likely see one of the yellow boxes in the top left of the web site preview. Choosing this yellow square will import the entire page. Little_Yellow_Squares

Click your mouse on the yellow square. You should see the square turn green.Little_Green_Check_Mark

6. Now click the “Import” buttonImport_Button

A few things to keep in mind about this “Import Data” popup… The “Where do you want to put the data?” is asking where do you want the data from the website to go. You can also choose to start a new worksheet so the query doesn’t interfere with any other calculations.

Click “OK” to start the import (we’ll talk about the “Properties…” later. You should see a status message on the bottom of Excel stating “Running Background Query”.

7. Because we imported the entire page, there will be some “junk” pulling into the top of the sheet. This is the various text, links, and other information at the top of the contest page.

If you scroll through the other information to about row 90 or so, you should see the player names and salaries pulling in.Query_Results

That’s It, You’ve Completed the First Example Web Query

This example is best suited for a one-time capture of data, so it isn’t perfect. But it illustrates how quickly this can be done. When we layer on the ability to easily update the query and to focus on specific tables in a page (keep reading), the power of the web query will increase greatly.

What Do I Do With All This Garbage Info That Pulled In With the Salaries?

Junk

Ignore the special characters and extra data that has pulled in for now.

Go easy, big fella. Let’s make it through the next couple of web query examples to see some improvements to this process. But also know that I eventually plan to show you how to take a dump of information like that and use various formulas to hone in on what you truly need.

We can move this eyesore of a tab to the back of your Excel file and use formulas to pull the valuable information to other areas of the file.

What Good Does It Do Me To Have This Query On a Random Tab in My Spreadsheet?

You might be asking yourself this question. Or maybe you’re wondering how you will later be able to combine this basic salary information with several other sources of data like historical stats for players, weather information, or betting lines.

When I’m designing a reusable spreadsheet, the initial hurdle is just to get all the information into the file. We can then use VLOOKUPS and other formulas to pull the different pieces of information into a central location. I find it better to keep the different data sources compartmentalized (or independent) so they can easily be updated later (via web queries).

Step-By-Step Instructions, Dynamic and Updating Web Query

You know how that FanDuel contest URL we identified above: FanDuel_URL

With a little experimenting, I’ve been able to determine that the only part of that long URL we really need is the https://www.fanduel.com/e/Game/#####. It appears to me that the ##### is a five digit number that FanDuel uses for all contests beginning at a particular start time. Or you might refer to this as the “slate of games” (the early slate would have a five digit ID that is slightly different than the late game slate).

If you type the https://www.fanduel.com/e/Game/##### URL into your browser, you should be taken to a page that displays all the salaries for the contest (you can’t look at past days or contests that have already started, unfortunately).

Of that shortened URL, the first part of that address, “https://www.fanduel.com/e/Game” stays the same. It’s just the five digit numeric ID (12452 in the image above) that changes. Well, instead of having to go through the tedious process of creating a web query from scratch each day, we can set one up that knows to look for the URL in a cell in the spreadsheet.

We can also tell Excel to update the query anytime we change that five digit number. So tomorrow when a new set of FanDuel salaries come out, we just get that five digit number, type it in, and all the salaries in the spreadsheet will update.

NOTE: The first three steps below are identical to the first three steps in the example above, but after that things begin to differ.

Step Description
1. Just like in our first example, log into your FanDuel account using Internet Explorer.

And if you don’t already have an account, you can sign up through this affiliate link.

Remember that it is important to use Internet Explorer to log in because that is the browser Excel will be running the query through.

2. Once you’ve logged in, locate any contest running for the day. Make sure you choose a “contest” and not one of the public head-to-head competitions that are available. For example, you could choose the third or fourth contest shown in the image below but not the “vs. csuram88″ H2H matchups. Choose_FanDuel_Contest

After you have identified a contest, hover your mouse over the “Enter” button.FanDuel_Enter_Button

Then note the URL that button will take you to in the lower right hand corner of Internet Explorer.FanDuel_URL

3. Right-click on that same “Enter” button and choose the option to copy the shortcut.Right_Click_Copy_Link
4. In the Excel file you started earlier, create a new blank tab/worksheet.

On the “Data” tab, choose the “From Web” option.Data_From_Web

5. When the “New Web Query” dialog opens, paste the URL you just copied into the “Address:” field. But remember that the full web address is not needed for the query to work, so delete everything that comes after the five digit Game ID.

Then click the “Go” button.Shorten_URL

6. Click the “Save Query” button. Save_Web_Query

You will then be prompted to save the query (“.iqy” file) Save_Web_Query_File_Name

I would recommend storing all your .iqy files in one location or near the Excel files you use for setting your DFS lineups. Excel defaults to saving them in a buried location on the C: drive. I would change that to somewhere you can remember because we’ll be editing these .iqy files.

7. Using Windows Explorer (not Internet Explorer!), browse through your computer and locate that .iqy file.

Right-click on the file and choose the “Open with>Notepad” menu option. Most computers should come with Notepad, but if you don’t have it you could try WordPad or any other simple text file editor.Open_With_Notepad

8. When the file opens in Notepad, you should see something like this:Notepad_IQY_File

We’ll start by changing the third line of the file. Delete the FanDuel web address and edit the third line to be:

["WebAddress", "Enter Desired Web URL to Query Here"]

It should look like this when you’re done:
Completed_Query

9. Under the File menu, click “Save”. Then close Notepad.
10. Return to your blank Excel sheet you created above. Type the following in cells A1 and A2:Excel_FanDuel_Headings
11. Type the FanDuel contest ID from the URL you previously identified. For example, in my screenshots above the ID is 12471.FanDuel_Contest_ID

Type the following formula in cell B2:
="https://www.fanduel.com/e/Game/"&B1

Then hit Enter and you should see this (adjust for your own FanDuel contest ID):Completed_URL_to_Query

That formula we just used basically just attaches two text strings into one. We took the “https://www.fanduel.com/e/Game/” string of text and attached the value from cell B1. When Excel strings them together you get the URL we are hoping for!

12. Before we go any further, I should explain that to this point in the instructions we have not actually added the query into our Excel file. The separate act we did of creating and saving the .iqy file did not actually start the query in this particular Excel file.

To this point we set up a set of query instructions. Those instructions are going to prompt Excel to ask us to “Enter Desired Web URL to Query Here” (go look above, that’s what we typed into the iqy file). Then we separately set up cell B2 in our Excel tab that contains the URL to run the web query on.

So let’s go ahead and link all of this together. Use your mouse to select cell A4. Then click on the Data tab in Excel and then click the “Existing Connections” button.Existing_Connections

13. When the “Existing Connections” dialog opens, you should see the connection we created in our first web query. Click “Browse for More…” to start a new connection.

Then click the “Browse for More…” button.Browse_For_More

14. Browse through your computer and locate the .iqy file we just finished editing. Then hit the “Open” button.Locate_IQY_File

You should now be prompted about where do you want to put the imported data. We previously selected cell A4, but choose another spot, if you wish.

Click “OK”.

15. This is the prompt we put in earlier! Excel is asking (because we asked it to in the .iqy file) us which URL we want to query.

Use your mouse to select cell B2. Then check both of the available check boxes.Final_Settings

By checking these boxes, we will be able to type in a new contest ID in cell B1 and then Excel will immediately query the new URL.

No more going to FanDuel, copying the list of players and pasting into Excel! Just type in a five digit number and get the salaries for the selected contest.

16. Click “OK” to start the web query.

Just like our first example, you will see quite a bit of extra “junk” pulling into the query, because at this point we are bringing in the entire web page. Keep reading for information on how to isolate in on certain sections of a web page.Junk

A Couple More Tips

I’m a big fan of using color or formatting to indicate meaning in your spreadsheets. I’d recommend shading or somehow formatting the cells where you need to type (input cells). For example, you could shade the Contest ID cell yellow:Format_Input_Cells

This way if a month goes by before you come back to the spreadsheet, you’ll have some visual queues about where you can type.

You do need to be careful about typing information on a tab containing a web query. When the query comes in, if you have information to the side or below the web query and the size of the data coming in increases (wider or longer), your other information could get deleted. I think it’s safest for the query data to flow into a tab and then pull that information elsewhere to other tabs, rather than building complex formulas and analysis right onto the same tab.

Let’s Step This Up One More Notch

In this next part we will try querying specific tables from a web page. But before we start, I’ll give a quick lesson on HTML.

HTML, or Hyper Text Markup Language, is the standardized language for coding web pages. You don’t need to know much about HTML when it comes to web querying, but it helps to know the basic format of a table in HTML. At a very high level, any table you see on a web page will be coded like this:

<table>
  <tbody>
    <tr>
      <td></td>
      <td></td>
    </tr>
  </tbody>
</table>

Again, that’s a VERY simplified look at a table. There will be lots of content and some other code mixed in and around the table. But for web querying, it can be helpful to know that everything related to the table starts at the <table> tag.

Do you remember the .iqy file we created and edited in the last example? You might have noticed that there was a line in the code for “Selection”. The default entry for that line is set to “EntirePage”, but we can change that.Web_Query_Selection

Instead of “EntirePage”, you can specify the number of the table on a web page to be imported. For example, to import the third table on a web page you would use the following in your .iqy file:Specific_Table_Number

Some sites (Razzball, Baseball-Reference) even give their HTML tables specific names inside the code. If you’re lucky enough to come across this, you can enter the name of the table for the “Selection” argument.Specific_Table_Name

Let’s go through an example.

Step-By-Step Instructions, Table-Specific Web Query

Step Description
1. Open your internet browser of choice (Google Chrome, Firefox, Internet Explorer, etc.). I will be using Google Chrome which has a couple of nice features that make this step a little easier than when I perform the same steps on Internet Explorer. You’ll still be able to use Internet Explorer, but note that there may be a few differences in screenshots and features I mention.

Go to a web page (URL) containing specific data you wish you query.

To keep consistent with this FanDuel example, I’ll attempt to query the following site:FanDuel_URL

2. Once that web page has fully loaded, locate the table you want to query. Right click somewhere toward the top of that table and choose the menu item for “Inspect element…” (it appears to me that the menu item is named “Inspect element” for both Google Chrome and Internet Explorer, the exact phrasing in other browsers may be slightly different). Right_Click_Table
3. This should open up a look at the HTML code that was used to generate the web page. This view will look different in each browser. I generated the following screenshots using Google Chrome. So just be aware things may look slightly different on your screen. The HTML code itself should be the same regardless of the browser you are using, but the appearance may not.

If you were close to the top of the table when you right clicked, you might see the start of the “table” HTML. Table_HTML

4. You can see from the image above that this “table” element does not have an “id=”. If there were an “id” we could use that in the web query to pull this specific table.
Here's a table from Baseball-Reference.com that has a table ID.

Here’s a table from Baseball-Reference.com that has a table ID.

So because of that we will have to determine which number of table this is on the page (e.g. is it the first, second, third).

There is a lot of information here and it would be easy to get overwhelmed by manually searching for and counting tables. But we can use the “Find” feature to locate things.

Scroll to the top of the HTML element window so you’re at the beginning of the page.Top_of_Page

Hit CTRL + F to open the Find… dialog.

Type the string “<table” (no quotes, but use the less than symbol before the word table and with no greater than symbol at the end). Hit Enter to start the search.

5. Your browser will locate the first HTML table element and highlight it. Hover_Image_1

One of the nice features of Google Chrome is that as you hover over an element in the HTML window, that same element will be highlighted in the actual browser window. This is extremely helpful for allowing you to identify which table the search just turned up.Hover_Image_2

You can see from the image above that this is not the exact table we are hoping to query. We want the table with the full list of salaries, not just the table containing the headers.

6. Now that we’ve identified that the first table is not what we want, let’s check the second table. Return to the “Find” search box and note that two table elements were found. To confirm that the second table is the one we want, click the down arrow to view the second table instance.Chrome_Find

Once the second instance is found, hover over the line in the HTML code.Second_Table

Then verify that the full listing of players becomes highlighted.FanDuel_Player_List

7. Now that we have identified that the second table on the web page is what we want to import into Excel, browse through your computer again and locate the .iqy file from our previous examples.

Again, right-click on the file and choose to “Open with>Notepad”.Open_With_Notepad

8. When the file opens in Notepad, edit the “Selection” line value to simply be a “2”.Selection_Two
9. Save and close the .iqy file.

Return to Excel and start a new tab. Before starting the new query, return to the worksheet/tab created in the second example above. Copy cells A1 through B2 (the FanDuel Contest ID and FanDuel URL cells) and paste them into the top of the new tab you just created.Copy_Example

Once you have this completed, select cell A4, then click on the Data tab in Excel and hit the “Existing Connections” button.Existing_Connections

11. You should see the queries completed earlier. Click the “Browse for More…” button. Browse_For_More

Browse to the location of the .iqy file, select the file, and then hit the Open button.

12. You should be prompted on where to place the query results. Cell A4 of the current worksheet is where I would prefer to put my data. Choose your desired location and click the OK button.Import_Data_Dialog

When prompted to “Enter Desired Web URL to Query Here”, select cell B2. Check both available options. Then hit the OK button.Enter_Parameter

13. Because we isolated the query to only the second table, the output should be much cleaner. You should have a nice clean table that only includes the FanDuel player salaries.Cleaner_Output
14. Nice! You did it!

A Little Disclaimer About Web Querying

Use care and responsibility while web querying. It’s important to think about what you’re doing when you perform a query. You are “taking” data from a web site without really visiting the site. A typical exchange on the web involves you having to view a few ads in order to consume the information. But we are bypassing that in this scenario.

I doubt FanDuel mind that we do this. But to regularly take information from a Razzball or Baseball-Reference.com could be frowned upon. So keep this in mind. Support those sites by physically visiting them or purchasing some of their services.

Where Do We Go From Here?

I have a couple ideas. But I’d like to hear from you. Now that we have a list of player names and salaries, what should we tackle next? Let me know your thoughts in the comment area below. I’ll put my thoughts there to start the conversation.

Stay smart.

How to Use Excel Text Manipulation Formulas with Fantasy Baseball Data

$
0
0

In our last post we took a close look at a handful of different web query options available in Microsoft Excel.

By the end of that post we had an Excel file that was able to automatically go out and pull in a raw listing of player names and salaries. All you had to do was figure out the ID for the slate of games you’re entering on FanDuel and type in that five digit number.

FanDuelContestID

Then voila… Current salary information (or you can even run it for tomorrow to start planning the night before)!

FanDuel_Salaries

The Next Step

So now we have player names and salaries. And we know from doing research at how to succeed playing DFS that we also need to bring in other information like batting and pitching splits, Vegas over/unders, and weather data.

We also know that using Player IDs is a more reliable way of matching players up with all of this data.

New Column On The Player ID Map

To bring all this data together, I recognized that we need a way to match a player’s name according to FanDuel to the player ID systems shown on the Player ID Map. So I made an update to the map over the weekend and added “FANDUELNAME” in column AF (I also added over 30 new players that have been called up during this season and/or are starting to have a “fantasy impact”. Guys like Carson Smith, Nate Karns, Carlos Frias, Lance McCullers).

FanDuelName

If you’re using the Player ID Map and you want instructions on how to drop in an updated version, check this out.

But We Had a Problem

Look closely at the image below.ClaytonKershawFanDuel

Who the heck is “Clayton KershawP”?

If you look through the list a little more you will see “Jose FernandezDL”, “Yordano VenturaDTD”, and “Ervin SantanaNA”.

You can probably see that some player names are reflecting health or availability information. This is great, but it poses a challenge for our ability to match to the new column in the Player ID Map. Kershaw is going to be listed as “Clayton Kershaw” on the list. Not “KershawP”.

Enter Excel Formulas “RIGHT”, “LEFT”, “FIND”, “LEN”, and “IF”

We are going to use a series of formulas to do the following things:

  1. Identify if a player name has “DL”, “DTD”, “NA”, or “P”. I’ve scanned the list of player names and those are the only injury/availability classifications I see.
  2. If a player has one of those health indicators on their name we will strip it off
  3. If a player does not have health indicators, we’ll just use their name as it is shown

RIGHT

The RIGHT function will give you the rightmost characters in a text string. For example, we could use the RIGHT function to look at the string “Yu DarvishDL” to determine if the two rightmost characters are “DL”.

This formula uses two inputs:

  1. Text – The main string of text you want to pull the rightmost characters from (this can be a cell reference)
  2. Num_chars – The number of characters to pull out

RIGHT_FORMULA

We will use the RIGHT function to look at only the last three characters of each player’s name. We only need the last three because our longest health indicator is “DTD” (three characters in length). And we don’t want to look at full names, because one of our health indicators is just “P”. We can’t just tell Excel to look for a capital P in an entire player name because player’s like Michael Pineda or David Price might cause us trouble. So by limiting our search to just the last three letters in a player name, we should be able to located “DL”, “DTD”, “NA”, and “P” without issue.

FIND

The FIND function searches for a specific string of text within another string of text. If the string you are searching for is located, it returns a number that indicates the location where the string starts. FIND is also case-sensitive (thank goodness, otherwise looking for “NA” at the end of player names could be a problem with guys named “Santana”).

This formula requires two inputs and has one optional input:

  1. Find_text – The string of text you are searching for. You can enter your text in double quotes or use a cell reference.
  2. Within_text – The string of text you want to search within. This can be a cell reference.
  3. Start_num (optional) – What character within the string you want to start searching at. For example, if you wanted to start by searching only after the fifth character in a name, you could enter a five for this argument.
FIND_FORMULA

We will use the FIND function in conjunction with the RIGHT formula mentioned above. We will use RIGHT to first pull out only the last three characters from a player’s name. We will then run a FIND on those three characters to look for “P”, “DTD”, “DL”, or “N/A”.

LEFT

Similar to the RIGHT function, LEFT will give you the leftmost characters in a text string.

This formula uses two inputs:

  1. Text – The main string of text you want to pull the leftmost characters from (this can be a cell reference)
  2. Num_chars – The number of characters to pull out

LEFT_FORMULA

We will use LEFT on players that have health information in their name. For example, for “Clayton KershawP”, we will want to pull out the first 15 characters (out of the total 16 characters in the full string of text).

LEN

The LEN function will tell you the number of characters in a string of text.

This formula has just one input, Text, which represents the text to want to count the characters from. This can be a cell reference.

LEN_FORMULA

We will use LEN with the LEFT function mentioned above. Remember the “Clayton KershawP” example where I mentioned that string of text has 16 characters and we want to take the leftmost 15 characters? We will use LEN to easily get that 16. We’ll use LEN to evaluate how many characters are in every player’s name.

IF

The IF function allows you to evaluate a cell to see if a condition is true or false. If the condition is true, we can give one result or a specific formula. If the condition is false, we can give a second result or an alternative formula.

This formula uses three inputs:

  1. Logical_test – The condition you want to evaluate for being true or false.
  2. Value_if_true – The value or formula you want to run if the Logical_test is true.
  3. Value_if_false – The value or formula you want to run if the Logical_test is false.

IF_FORMULA

Nesting Formulas

By default, the IF function only allows you two options. One if true. One if false.

This might be a problem for us. Here are some of the tests we need to run…

If we find “P” in the last three characters of the player name, cut off the last character from the name (or if the player’s name is 16 characters in length, give me the leftmost 15). If we find a “DL” in the last three characters of the player name, cut off the last two characters from the name (or give me the leftmost 14 from a 16 character name). If we find a “DTD” in the last three characters, cut off those three letters from the name (or give me the leftmost 13 from a 16 character name). If we find an “NA”, cut off the last two characters (14 from 16). And if none of those are true, then just give me the full length of the player’s name and remove nothing.

Thankfully you can also “nest” IF functions to give you more options. In a weird combination of Excel language and plain English, our formula will look something like this:

=IF(player is status "P", give me LEFT(player_name, LEN(player_name)-1), if their status is not "P" then IF(player status is "DL", give me LEFT(player_name, LEN(player_name)-2),if their status is not "DL" then IF(player status is "DTD", give me LEFT(player_name, LEN(player_name)-3, if their status is not "DL" then IF(player is "NA", give me LEFT(player_name, LEN(player_name)-2), if their status is not "NA" just give me player_name))))

This is basically saying, if a player is marked as “P”, cut off one character from their name (that’s what the “-1″ is doing in the LEFT(player_name, LEN(player_name)-1). If the player is not marked as “P”, go to the next IF statement. If the player is marked as “DL”, cut off two characters from their name LEFT(player_name, LEN(player_name)-2). If the player is not marked as “DL, go to the next IF statement.

And so on. Until we get to the very end of all the IF statements. The final player_name just indicates that if all the previous IF conditions are false, this is what will show.

One More Web Query Option I Didn’t Mention

We looked at quite a few web query options in the last post, but I neglected to mention one that will now be helpful to use. We are going to be placing the formulas from above next to the FanDuel web query results (you can see my vision of how this will look below, they’re shaded a yellowish color).

FormulasNextToData

The potential problem with doing this is that the web query results and FanDuel’s list of player names will be changing each day and for each contest. The length of the player list is going to be a lot longer for a full slate of games on a Wednesday night than it will be for the afternoon slate on a Thursday.

Fortunately, Excel offers a setting that will attempt to fill the formulas down as far as the data in the web query reaches. To activate this setting, first select a cell in the middle of the web query results (for example, select the cell with Clayton Kerhsaw’s name).

Clayton_Kershaw_FanDuel

Then click on the “Data” tab. And then click the “Properties” button in the “Connection” section of the Data tab.

Data_Connection_Properties

This will bring up the “External Data Range Properties” dialog. Check the bottom check box for “Fill down formulas in columns adjacent to data”. This will attempt to fill our formulas to the exact size of the web query results. I also like to uncheck the “Adjust column width” box because each time the web query runs, it resizes my columns and I find it annoying.

External_Data_Range_Properties

Step-By-Step Instructions

If you want to make sure you’re at the same starting point as me, here’s an Excel file containing the FanDuel Web Query that has the “Fill down formulas…” option already checked. When you open the file in Excel, you will likely have to enable data connections. And then you’ll need to go to FanDuel and identify a contest ID to enter in cell B1.

Enable_Data_Connections

Step Description
1. Before we get into the formulas, enter headers in columns H-L (next to the web query results) for “DL”, “P”, “DTD”, and “NA”.Column_Headers

I formatted my column headers bold, I aligned them in the center of the cell, and put a border at the bottom of each cell.

We will use the combination of the RIGHT and FIND functions discussed above in the “DL”, “P”, “DTD”, and “NA” columns to detect if a player has any of those statuses in his name.

Then the “Name” column will hold our massive IF formula that uses LEFT and LEN to pull out just the player’s name.

2. Combining multiple Excel functions together can be confusing and lead to errors, so I like to build them up one step at a time. We mentioned earlier in this post that the first step in detecting the availability/health information is to look only at the three rightmost characters in his name. To do this, we’ll use the RIGHT function.

Enter the following formulas in the first “DL” cell (H5 in my example file):

=RIGHT($B5,3)

The reason for the dollar sign is because we will be using the same RIGHT formula in the “P”, “DTD”, and “NA” columns. We want the column to be an absolute and not relative cell reference (if we copy the RIGHT formula to column I, we don’t want it to become =RIGHT(C5,3)).

You should be able to see that our formula is working.RIGHT_FUNCTION_RESULT

3. Now we will wrap the FIND function around the RIGHT formula we just created. Adjust your existing formula by adding the red text below:
=FIND(H$4,RIGHT($B5,3),1)

CLAYTON_KERSHAW

We want to find the string “DL” in the three rightmost characters of Clayton Kershaw’s name and we want to start looking for the “DL” string at the first character. This time we want our row number to be absolute, so the dollar sign goes to the left of the row number. As we copy this formula to column I, we want it to look at the “P”. But as we copy the formula down to other rows we still want it to be locked on row four.

4. After you complete that formula, you’ll likely have a “#VALUE!” error. This is indicating that the “DL” string was not found in the player name. We need to correct this because our “NAME” column will eventually be referring to this cell and that formula will then also result in an error.

To resolve this we will now wrap our existing formula inside one more function:

=IFERROR(FIND(H$4,RIGHT($B5,3),1),0)

IFERROR_FORMULA

5. Select the cell containing your completed formula (cell H5). Copy this formula to the “P”, “DTD”, and “NA” columns by dragging the square in the bottom right hand corner of the cell to those columns. Then double click the same square to copy the formulas to all of the data below.Copy_Excel_Formula
6. Look closely and verify the results. You should see that anyone with an availability status shows a number greater than 0 in the applicable column, while players with no status show zeroes across all columns.

FORMULA_RESULTS

7. Put your thinking cap on. Here comes the monster IF formula.

Find a player that has a “DL” status. We’ll first start with just getting the LEFT function to work on one player. My first DL’ed player is Yu Darvish in row 22. I’ve hidden some rows in between so you can keep some perspective when looking at the screenshots.

Enter the following formula in the appropriate row of the “NAME” column (I’m entering my formula in cell L22, adjust your formula for the row you’re working on):

=LEFT(B22,LEN(B22)-2)

YU_DARVISH

In this case, the LEN function will determine that “Yu DarvishDL” contains 12 characters (including the space). We then subtract two from that because we know the “DL” is included on the end of the name, meaning we only want the leftmost 10 characters from the string.

Moving outward from the LEN function, the LEFT function looks at “Yu DarvishDL” and takes the 10 leftmost characters (the length of 12 minus 2), resulting in just the name “Yu Darvish”.YU_DARVISH_COMPLETE

8. The LEFT formula we just completed is what we want evaluated if a player is on the DL. To make this happen, we’ll use the LEFT formula as our true condition in an IF function.
=IF(H22>0,LEFT(B22,LEN(B22)-2),B22)

We know that any player with a health status after their name will have a number greater than 0 in the applicable status column. That’s where the H22>0 logical test comes in.

If a player is on the DL, our formula should strip off the “DL” status. But if he’s probable or day-to-day, we should still see those codes. Copy the current formula to all players, in order to see if this is what’s happening.DL_WORKING

9. Now we’ll nest in another IF function to identify “P” players using the same principles we just used in steps 7 and 8. Remember, I’m working in row 22, just because that’s where I started. Adjust the “22” references in my formula to the row you’re working on.
=IF(I22>0,LEFT(B22,LEN(B22)-1),IF(H22>0,LEFT(B22,LEN(B22)-2),B22))

The new LEFT formula is identical to the last one except this time we’re subtracting 1 instead of 2. This is because “P” is one character long while “DL” was two.

Copy this formula to all players.

I’ve just taken our original IF formula and made it the “Value_if_false” argument inside a new IF formula. Now our formula is checking to see if a player is “P” and stripping that status off and if they’re not “P”, it checks to see if they’re “DL” and strips that off, and if neither of those conditions are true, it just takes the full name (so you should still see “DTD” and “NA” players).

10. Let’s nest another IF function. This time to identify “DTD” players. Remember, I’m on row 22…
=IF(J22>0,LEFT(B22,LEN(B22>-3),IF(I22>0,LEFT(B22,LEN(B22)-1),IF(H22>0,LEFT(B22,LEN(B22)-2),B22)))

This time we’re looking at column J for “DTD” players and subtracting three characters from the player’s name. Copy this formula to all players. All “P”, “DL”, and “DTD” player names should be correct! “NA” is all that remains.

11. Last IF function. Row 22 reminder…
=IF(K22>0,LEFT(B22,LEN(B22)-2),IF(J22>0,LEFT(B22,LEN(B22)-3),IF(I22>0,LEFT(B22,LEN(B22)-1),IF(H22>0,LEFT(B22,LEN(B22)-2),B22))))

This last time we’re looking at column K for “NA” players and subtracting two characters from the player’s name. Copy this formula to all players.

12. BAM! Nice work.

Now That We’ve Separated the Men From the Boys

If you’re reading this line of the post, I just want to say thanks. I know the information on this site isn’t for everyone. But at the same time, there are a select few curious and hard working fantasy baseball players wanting to get their hands dirty and to get better at what they do. You’re obviously one of those people and hopefully you’re finding some value in this.

What’s Next

I think we’ll try to bring the FanDuel information from this spreadsheet together with the Player ID Map. Then from there we can bring in outside information like player stats, weather, and opponent data.

How to Import Draft Kings Salaries into Excel

$
0
0

I’ve been exclusively focusing on web querying Fan Duel to this point. But what about Draft Kings? Is there a way to web query their salary information? Here’s an e-mail I recently got from a reader of the site…

Hey Tanner, I just got back from vacation and saw some of your recent posts. That looks great… but I play on Draft Kings. When I try to do those steps on that site, it doesn’t work. No player names. No salaries. Any ideas?

Draft Kings salary info.

There is no <Table> element on the Draft Kings salary info.

I followed the same web querying steps we went through in this post, “How to Use Excel to Web Query DFS and Other Fantasy Baseball Data”, using FanDuel’s site this time. And sure enough, no matter what web querying option you use… No dice. If you do an investigation using the “Inspect element” option for your browser, I believe the technical reason the web query is unsuccessful is because the salary information is not coded as an HTML table.

So things aren’t going to be as easy as the web query. But due to a nice feature on Draft Kings, we can get very close. It’ll take just a few extra mouse clicks to get to the same place.

You see, even running a FanDuel web query isn’t seamless. You still have to log into your FanDuel account in your browser, locate a contest ID (URL), and type it into your Excel file to kick off the web query.

One Extra Step for Draft Kings

While Draft Kings salary info can’t be web queried, they do offer the ability to export all player information from a given contest into a nicely packaged CSV file. The link for a contest appears just below the player list you sort through to select players for your lineup.Export DraftKings salary information to CSV.

“CSV” stands for “comma separated values”. Many computer generated data export files have some kind of delimiter, or character, that breaks the data into columns. The CSV format specifically uses a comma to separate the values. Here’s what a CSV file looks like when opened outside of Excel:

Draft Kings comma separated values export file.

That Looks Awful, How Do I Work With That File?

The CSV format does not look user-friendly when viewed outside of Excel. But fortunately, once you install Excel, it becomes the default program to open CSV files… And this format is so standardized, Excel is trained to clean up the data and put it in our friendly Excel format:

Draft Kings CSV export opened in Excel.

This Doesn’t Look as Efficient as a Web Query

Right about now you’re probably thinking something like this…

You mean to tell me each time I want to update my DFS baseball spreadsheet, I need to…

  1. go Draft Kings,
  2. find a contest to enter,
  3. export the salary information,
  4. open that CSV file,
  5. copy the information,
  6. and then paste it into my spreadsheet?

Not quite. Some of those things we have to do regardless. We can’t really automate the selection of the contest you want to enter. But we can have Excel automate steps four, five, and six (the process of getting the CSV data into a preexisting DFS spreadsheet.

Excel Data From External Sources

DATA_FROM_TEXTYou might remember in the previous web querying article that we used the “From Web” option to “Get External Data” into our Excel files.

Fortunately, Excel also has an external data option for “From Text” (and a CSV file is a text file) that works on the exact same principles of a web query.

Just like how the web query is set up to pull information from a very specific web URL, this text file link can be set up to pull information from a very specific file path.

So as long as we save and name our Draft Kings CSV file in the same place each time, the data can automatically pull in to our DFS Excel files each time we open it.

Step-By-Step Instructions

Step Description
1. Log into your Draft Kings account (unlike for a web query, you can use any browser you wish for this).

Once you’ve logged in, locate a contest you’d like to participate in and click the “ENTER>>” button.ENTER_DK_CONTEST

2. After the contest loads, click the “EXPORT TO CSV” button below the player salaries (located on the left half of the contest screen).

NOTE: It does not matter if you check or uncheck the “ONLY PROBABLE PITCHERS” box. The export always contains all pitchers.EXPORT_TO_CSV_DRAFT_KINGS

3. Depending on the browser you’re using and its settings, one of three things will likely happen at this point:

  1. The CSV file will automatically download to your pre-specified download location
  2. You’ll be prompted to name the CSV file and choose where to save the file
  3. Or Excel may open and display the CSV file immediately

Regardless of what scenario you find yourself in, the main goal here is to save the CSV in a location where you want it to stay going forward. Maybe that’s your desktop or maybe you have a “Fantasy Baseball” or “DFS” folder on your computer. Save the CSV file in that long-term location.

So if it automatically downloaded to your “Downloads” folder, move it. If you’re being asked where to save the file, point it to the desired location. If Excel launched, perform a “Save As” to the desired folder. If you have the CSV file open, close it now.

4. Open your DFS spreadsheet (you may want to make a backup before proceeding) or start a blank Excel file if you’re just beginning (don’t start in the CSV file!).
5. Go to the “Data” tab and click the “From Text” button.
DATA_FROM_TEXT
6. At this point Excel will prompt you to browse for the text file you want to import. Browse to and locate your CSV file.
DKSalaries.csv

Once you’ve located the file, select it and click the “Import” button.
Import DKSalaries.csv

7. Excel’s “Text Import Wizard” will launch and ask which type of text file you’re importing. Remember that a CSV file is a special type of delimited text file that uses a comma to separate the values. So choose the “Delimited” option and click “Next” (a fixed width file doesn’t have a character (like a comma or semi-colon) separating the data, it would just have clearly visible spaces separating the data into columns).

IMPORT_DELIMITED

On the next screen, choose the “Comma” delimiter option and uncheck any other options. You’ll get a preview of how the columns will be identified. Click “Next”.
COMMA_DELIMITED

On the final screen of the Text Import Wizard you can likely just hit “Finish”. For future imports, if you have a column containing something you only want treated as text or a date, you can choose those options. But “General” is fine for our purposes.

FINISH_TEXT_IMPORT_WIZARD

8. Once you click “Finish”, you’ll be prompted about where you want to import the CSV data to in the Excel file. If you are working in your pre-existing DFS spreadsheet, click on the tab you want the text to import to and use the “Existing Worksheet” option, or just choose the “New worksheet” radio button.

Don’t click OK yet! Click the “Properties” button.

IMPORT_DATA_OPTIONS

9. There are many available properties to adjust, but I’ll call out a few I feel the most strongly about changing:

Prompt for file name on refresh – If you plan to save the CSV file in the same location and with the same name each time, you should uncheck this option. If left checked, each time you refresh the connection to the CSV file you will need to browse to and select the file. Conversely, if you don’t want the restriction of having to name the file consistently and in the same spot, you may want this checked. But you’ll then need to browse and point to the new file each time you want to refresh the link.

Refresh data when opening the file – As you can probably guess, if you check this box, each time you open your DFS spreadsheet it will link to and import the text file information.

Fill down formulas in columns adjacent to data – We may not need this, but if we end up needing formulas next to the data being imported, I would recommend checking this box.

IMPORT_PROPERTIES

Click “Ok” to accept the settings changes.

Then click the next “OK” button on the “Import Data” window.

10. That’s it! The next day, when you go to prepare for a new contest, simply repeat steps 1 through 3.

In doing so, be careful to name or save the CSV with the exact same name and in the exact same location as your Excel file is looking to.

For instance, if you saved your first Draft Kings export as C:\Users\brent.franey\Downloads\DKSalaries.csv, then make sure you save it there again the next day. If you have an older CSV already sitting in that location, the export will likely save as “DKSalaries (1).csv”. Not a problem. Just delete the older one and rename the new download to be just “DKSalaries.csv” (right-click on the file and choose “Rename”).
Draft Kings Salary CSV Export

Web Query vs. CSV Import

I’m not sure which is superior or if there is even a clear winner. There is something elegant about the web query. And I really like how you can create a dynamic web query (I wish there were a way to do a dynamic text file link, but I can’t see a way to do that). But the web query is slow.

The text file import does require a couple of extra steps, in terms of naming the CSV file, but once that part is complete it’s essentially the same. The actual import of the data into Excel is much faster for the text file option (at times my web queries can take 30 seconds or more to complete).

For both options, Excel will seamlessly import the data and the rest of your Excel file can be built around this to automatically update based on the salary list.

Second Look at FanDuel

Having noticed this for Draft Kings, I took another look at FanDuel… Lo and behold, FanDuel has the same export option.

Export FanDuel player list and salaries.

One key difference in the FanDuel CSV is that it has a unique file name associated with the contest ID. Unique FanDuel CSV file name.

So if you decide to go the CSV route for FanDuel, instead of using this unique name, rename/save the file with a generic name like “FDSalaries.csv”. If you also save the file in the same location each time, you would be able to link an Excel file to it repeatedly. At that point, just follow the setup instructions above and there is no difference in the setup of a FanDuel export and a Draft Kings export.

But Wait… What is that on the FanDuel Salaries List???

Oh my… This might be enough to convert me off the web query and to an exported CSV approach even for FanDuel (damn you Chris Youngs and Jose Ramirezes!).

FanDuel Player ID Numbers

Player IDs (don’t know what a Player ID is?)… FanDuel player IDs, coming soon to a Player ID Map near you.

How Is Your DFS Spreadsheet Coming Along

Do you have any neat features you’ve added? Struggling to get some kind of information added? Feel free to post a message below to share what you’ve done or let me know your struggles and maybe I can help.

Stay smart.

FanDuel Name, FanDuel ID, and Draft Kings Name Added to Player ID Map

$
0
0

Short and sweet update here… Columns for “FanDuelName”, “FanDuelID”, and “DraftKingsName” have been added to the Player ID Map (click to download the Excel file).

FanDuel and Draft Kings names for Paul Goldschmidt, Carlos Gomez, Yan Gomes, and Adrian Gonzalez.

FANDUELNAME, FANDUELID, and DRAFTKINGSNAME columns have been added to the Player ID Map.

New to the site? Here are some past articles about how to use the Player ID Map in developing your spreadsheets (they focus on the season-long game, but the principles of using Player IDs or the map to account for differences in player names across sites still apply).

Please keep in mind that the Player ID Map is not intended to be all encompassing. I aim to keep all “fantasy relevant” players on the list. On choice days when a bench player or swing-man starting pitcher get the call, one might argue they become “fantasy relevant” to the daily game, but such players may not be included in the listing. I have to draw the line somewhere!

Thanks for following the site and stay smart.


Importing a CSV File as an Excel Table

$
0
0

In this post I’m going to put a slight twist on the Draft Kings CSV salary file import we discussed recently and show you how to import the data into an “Excel table” (or sometimes referred to as an Excel structured reference).

If you’ve followed any of my previous “how to” sets, you know I’m a big proponent of using these Excel tables. They give a number of benefits:


  1. Efficiency – When you add a formula to a cell, Excel automatically copies that same formula to all other rows in the table. No more copying and pasting and scrolling around to copy your formulas.

  2. Consistency – Reduces the likelihood of an error in your spreadsheet by making sure formulas in a column are identical.

  3. Easier to Build Formulas – Your table becomes part of Excel’s reference system giving you useful type ahead featuresTable_Type_Ahead

  4. More Reliable Formulas – Because of the naming and reference system, formulas can better adjust when rows/columns are added or deleted. Ever had a VLOOKUP formula fall apart after you added a column to your spreadsheet? Or how do you think your spreadsheet will respond when you import a large list of players for a big slate of games and the next day you play a small slate of afternoon games? Setting the range of salaries as an Excel table allow formulas to adjust automatically.

  5. Meaningful Formulas– Structured reference formulas inherently have more meaning to them than standard formulas not using structured references. Look at these two examples…

    Traditional Excel Formula

    =VLOOKUP(A3,PLAYERIDMAP!$A$1:$AH$1502,4,FALSE)

    Structured Reference Excel Formula

    =VLOOKUP([@PLAYERID],PLAYERIDMAP,COLUMN(PLAYERIDMAP[FIRSTNAME]),FALSE)

    While the first formula is shorter in length, it’s also shorter on meaning. You can’t look at the formula and easily determine its purpose. You can easily look at the second formula to see it’s trying to locate the PLAYERID in the PLAYERIDMAP table and return the FIRSTNAME of the player.

    I think this is a HUGE benefit…

Is This Really Necessary?

Necessary? Probably not. An improvement? I think so. Since discovering Excel’s structured reference system, I’ve been using it on all my spreadsheets. I was excited to find a way to do this while importing data from an outside source. I didn’t know it was possible… I just wish we could get it to work with a web query too!

Step-By-Step Instructions

Here are instructions to bring in a Draft Kings or FanDuel CSV salary listing into an Excel file as a table. I use FanDuel in the example, but this can just as easily be performed with a Draft Kings CSV export.

Step Description
1. Log into your FanDuel account and download the CSV relating to the contest you wish to enter.

To do this, choose the contest you wish to enter. After identifying the contest, click the “Enter” button.FanDuel_Enter_Button

Once the contest loads, scroll to the bottom of the player salary list and click the link to “Download player list”.FanDuel_Download_Players_List

The file you download will have a unique name. Recall from our previous post on using CSV files that we will be better off to change this to a more generic name, like “FanDuel.csv”. We can then use that generic name going forward and instruct Excel to import “FanDuel.csv” each time it opens.

FanDuel CSV File Name

Instead of using the unique name provided by FanDuel, rename the file to a more generic name like “FanDuel.csv”.

By saving the file in the same spot and using the same name each time, Excel can seamlessly open and update the salary information with us not having to perform the CSV import each time.

So, after you have renamed it, save your “FanDuel.csv” file somewhere you don’t mind it residing in the future.

2. Start a new Excel file or open the file you wish to add the FanDuel salary list to.

On Excel’s Data tab, click the “Get External Data From Text” button.Import CSV file into Excel

Then browse to and select your “FanDuel.csv” file. Then hit “Import”.FanDuel CSV File

3. At this point, Excel’s “Text Import Wizard” will open, asking you which type of file you’re importing. Choose the “Delimited” option and be sure to check the “My data has headers” box.IMPORT DELIMITED

At step 2 of the import wizard, check the “Comma” delimiter box and uncheck any others. Click “Next”.Text Import Wizard Comma Delimiter

No changes are necessary at step 3. Just click “Finish”.TEXT IMPORT WIZARD STEP 3

4. This is where we diverge from the previous instructions. To format the imported data as an Excel table, check the “Add this data to the Data Model” box (other options on this screen will be grayed out until you check that option). Then ensure the “Table” radio button is selected under the “Select how you want to view this data in your workbook” area.

Click the “Properties…” button. Add_This_Data_to_the_Data_Model

5. In the past, I’ve suggested you check the “Refresh data when opening the file box” at this point. But don’t do that yet!

When I check that box at this point, my Excel file gets an error each time I open it. I get the sense the connection is still working, but the error bothers me. In researching the error, it seems others have experienced the same thing. The simple workaround to the error is to not check that box now, and just come back and check it later in the process.

I would recommend unchecking the “Prompt for file name on refresh box”.
Refresh_Data_When_Opening_the_File

Click “OK” to close the “Connection Properties” settings. Then click “OK” to close the “Import Data” settings.

6. Your import should be complete! You’ll know that Excel formatted your data as a table if it’s somehow shaded with alternating colors.

FanDuel_CSV_Table

You can change the colors under the “Table Tools Design” tab that should appear on the Excel ribbon when you click within the table.Change Excel table color.

7. After the import is done and you’re satisfied with the color, go to Excel’s “Data” tab and click on the “Connections” button.Data_Connections

In the list of “Workbook Connections” that loads, choose your FanDuel connection and hit the “Properties…” button.
Workbook_Connections

Now check the “Refresh data when opening the file” option that we purposely held off on earlier.
Connection_Properties

8. To test the connection, close your Excel file. Then browse to and open the “FanDuel.csv” file.

Make an obvious edit to a player’s salary (for example, change Clayton Kerhsaw’s salary to “99999”), save your changes, and close the CSV file.
Clayton_Kershaw_FanDuel_Salary

Note, your CSV file may open in Excel. You can still edit a player’s salary. When you go to save the file, you’ll get a series of annoying messages about “Do you want to keep using the CSV format?”. Just be sure you’ve saved the file and say “Yes” to those questions. You’ll get prompted with the same set of questions when you close the CSV file.

9. Now open your Excel file and verify that the salary change you made flows through. You might first get a security warning from Excel that data connections have been disabled. Click the “Enable Content” button and watch the data below update.

My data files sometime import in a strange order. You may have to use the “Salary” drop down menu to sort by salary in descending order (to see Kershaw at the top).Sort_Salaries_in_Descending_Order

Clayton_Kershaw_FanDuel_Salary_Excel

Changing the Name of a Table

Now that you’ve created an Excel table, you an edit its name and other properties on the “Table Tools” tab. This tab is not always visible but should appear when you select a cell within the table.

Excel's Table Design Tools

Once you’ve selected the “Table Tools” tab of the ribbon, you can change the name of the table under the “Properties” icon set all the way to the left of the tab. Remember, a great deal of the value from using structured references is the ability to use type ahead formula building and to have meaning in your formulas. So avoid names like “Table1″ and go for things like “FanDuel_Salaries” or “Table_FanDuel”.

TABLE_NAME

Using Type Ahead in Formulas

Once you’ve set up a table, the type ahead features immediately activate with no effort needed on your part. To see the type ahead in action, just start by typing the name of your table in a formula.

You can see in the image below that just typing “Ta” (for “Table_FanDuel”) pulls up the table. You can then use your mouse to double-click on one of the items in the list or use your arrow keys to select one and then hit the “Tab” key to select the highlighted item.

TYPE_AHEAD

Once you have completed adding the table name, an open bracket (“[“) will then present you with a list of field names, all of which you can cycle through with the up and down arrrow keys and then hit Tab to select a column/field.

Excel Type Ahead Field Names

Wrapping Up

A little bit of a personal story here. I occasionally give Excel trainings at work to people that know their way around a spreadsheet pretty well. Most could even rattle off a VLOOKUP formula without much thought. I show them Excel tables and structured references and everyone’s eyes glaze over and they look like a bunch of deer in headlights.

I get it. The structured reference thing is new. If you already know how to do a VLOOKUP it’s hard to see the value in changing. Why take the time to do this?

Keep in mind that I try to design spreadsheets that will last for a long time and be reusable. At least for one season and possibly into future seasons. You could easily just get caught in a cycle of whipping up an inferior spreadsheet each time you want to create a lineup. But I would rather invest the time to build a long-term tool on a strong foundation. This way I can save time each night by having a prebuilt tool and because it’s built on a strong foundation I can continue to add new data, projections, and features over time.

And don’t you just love the pretty alternating row colors????

The SFBB way is all about doing things yourself, building things the right way, and continually improving and learning new things. So take the time to play around with structured references and learn the language.

Stay smart.

How to Add Batter and Pitcher Handedness to your DFS Spreadsheets

$
0
0

In this post I’ll show you how to add batter and pitcher handedness to your spreadsheets. To do this, we’ll have to learn two new Excel formulas we have not tackled yet.

I’ve avoided doing this for a long time… But there’s just no way around it now. It’s time to say goodbye to relying exclusively on VLOOKUP. Let’s put on our big boy pants and tackle VLOOKUP’s more flexible and powerful counterpart… INDEX and MATCH.

Sometimes VLOOKUP Can’t Get the Job Done

Take this scenario. You’ve started to build a DFS spreadsheet and you’ve imported FanDuel player salaries from a CSV file. Now you want to add player handedness (Lefty/Righty) as a column to your spreadsheet.

FanDuel Player Salaries Excel CSV

FanDuel Salary Information

You are also aware of the Player ID Map and know that it’s an easy way to get handedness information on players.

Batter_Pitcher_Handedness-e1438976169811

The Player ID Map contains information for batter and pitcher handedness, date of birth, team, position, and many player ID and naming systems.

You look at this data above and you think, “No problem!”. FanDuel ID is in both sets of data. How hard could this be? A simple VLOOKUP and we’re done.

But you quickly realize things are not that easy. You see, the VLOOKUP has a very restrictive assumption. If you are doing a VLOOKUP from the salary information into the Player ID Map, the Excel function assumes that “FanDuelID” will be the FIRST column in the Player ID Map.

And that’s NOT the case.

Let’s look at an example VLOOKUP formula:

=VLOOKUP([@FanDuelID],PLAYERIDMAP,10,FALSE)

In this formula we’ve told Excel to go look for the “FanDuelID” column in the “PLAYERIDMAP” table and give us back the value in the 10th column.

But “FanDuelID” is not the first column of the PLAYERIDMAP. It’s the 33rd (wow… the Player ID Map is getting to be quite large). So VLOOKUP will not work.

Other Weaknesses of VLOOKUP

Not only is assuming the data you want to match is in the first column awfully restrictive, if you think about it, VLOOKUP also ties you to a left-to-right lookup. For example, if you’re trying to use Excel to VLOOKUP which team Michael Brantley plays for, his player ID must be in the first column of your data set and you are then forced in to looking only to the right.VLOOKUP_LEFT_TO_RIGHT

We want a formula that will allow our lookup to be in any column and then to look to the left! For example, go find Nelson Cruz’s FanDuelID and then look to the left a few columns and give me the side of the plate he bats from.INDEX_MATCH_LOOK_LEFT

=VLOOKUP([@FanDuelID],PLAYERIDMAP,10,FALSE)

Going back to this example formula right above, the hard coding of a “10” in the formula to return the information in the 10th column is a flimsy approach, but that’s how many people are taught to write VLOOKUP formulas.

The flimsiness comes in if you decide to insert a column somewhere in the PLAYERIDMAP. If column 10 becomes column 11, Excel will not adjust its formula accordingly. Because you are likely building a spreadsheet that you’ll use all throughout the season, it seems highly likely you’ll want to add a new piece of information to your analysis. That inevitably means adding columns to bring that new information in. You don’t want to have to hunt through your formulas to figure out what the new column number in your VLOOKUP needs to be.

Enter “INDEX” and “MATCH”

That’s right. To defeat the almighty VLOOKUP formula, we need to combine the powers of two functions (that last sentence just made me think of this). Let’s take a look.

INDEX

When I’m using a function I’m unfamiliar with, I will add it through the “Insert Function” button. I like doing this because Excel will then give you a search menu to find a formula. And after locating your function you’ll get a helpful wizard that breaks down all the inputs it needs. INSERT_FUNCTION

If you follow that approach to add the INDEX function, you’ll soon realize there are two versions of it.

Excel Index formula has two versions.

I always use the first version, which allows us to locate a cell anywhere within a block of data and return the value from that cell. This function uses the following inputs:

INDEX(Array, Row_num, Column_num)

  1. Array – The range of cells you are searching for a value in. This could be a table or a block of cells.
  2. Row_num – The row within that array that the value is in. This should be a number representing the row.
  3. Column_num – The column within the array that the value is in. Again, this should be a number representing the column (not the letter representation of the column).

It may help to see a visual representation of the function. Assume we’re trying to find Nelson Cruz’s batting handedness. If we tell the index function to look in the PLAYERIDMAP (the “array”), in row 309 (“row_num”), and column 26 (column_num), it would return “R”.

Index Excel formula image example.

We know the array to look in. And we can easily determine the column we want to look in. The challenge we now face is how to determine the row to look in… How do we easily determine that Nelson Cruz is listed on row 309. That’s where the “MATCH” function can help us.

MATCH

The MATCH function will look for a specific value in a range of cells. The function will return a number representing where the matched item falls in the list.

Translating that into English, a realistic use for the function is to look in an entire column for a match. The function will start at the top of the column and proceed down until it locates the desired value. The function then returns where the item falls in the list, which happens to be the row the item is in.

The function uses these inputs:

MATCH(lookup_value, lookup_array, [match_type])

  1. Lookup_value – This is the value you are hoping to match in the array (or column). For us, this will usually be a Player ID of some sort.
  2. Lookup_array – This is the area you are searching for the match within. When using the MATCH function with the INDEX function, this will usually be a column of data.
  3. Match_type – This is an optional input telling Excel some more details about the kind of match you are looking for. You can enter a 1, 0, or -1. Entering a 1 or -1 are forms of approximate matches and are useful if you are looking up numeric values. But we are typically looking to match strings (I consider a Player ID made up of all numbers to still be a string) of text.

    This means we want exact matches only. Accordingly, I always use a 0 for this argument (even though it’s optional, leaving it blank tells Excel an approximate match is acceptable).

MATCH_FUNCTION

Combining INDEX and MATCH

As I alluded to before, the power of these two formulas comes when you combine (or nest) them together. Recall that the INDEX function looks like this:

INDEX(Array, Row_num, Column_num)

If we drop the MATCH function in place of the “Row_num” argument:

INDEX(Array, MATCH(lookup_value, lookup_array, [match_type]), Column_num)

We now have a formula that is more flexible and powerful than a VLOOKUP! The combination of INDEX and MATCH can look for a value anywhere in a table of data and we are no longer tied to the first column and a right-only lookup.

Step-by-Step Instructions

Lets go through the example scenario proposed above. We have a table of FanDuel salary information and we want to pull in handedness information from the Player ID Map.

Prerequisites

I am assuming you have already started an Excel file based off a FanDuel CSV export. If not, you can read how to do that here.

Step Description
1. Open your Excel file containing FanDuel salary information.

Then download and open the SFBB Player ID Map (click that link and it should begin to download).  Once you’ve opened the Player ID Map, right-click on the “PLAYERIDMAP” tab and choose “Move or Copy…”.Move_PlayerID_Map

In the “Move or Copy” menu, select your FanDuel salaries spreadsheet in the “To book:” drop down menu (we’re copying the Player ID Map into the FanDuel salaries file).MOVE_OR_COPY

Choose the “[move to end]” option and click “OK”.

2. Return to the tab containing the salary information and add two new columns. You can do this simply by typing your column name in the first row of the open columns.

If your FanDuel CSV file is the same as mine, my first open columns are “O” and “P”. In cell “O1″ type “Bats” and in cell “P1″ type “Throws”. These are the columns we’ll use to pull in each player’s hitting and throwing handedness. As soon as you type in these cells Excel should automatically bring them in as part of the table and shade them (another benefit of using Excel tables).Batter and pitcher handedness columns

I shaded these columns red to indicate this information is coming from another source. This is just a small visual cue to let me know that columns A through N are from my FanDuel CSV and columns O and P are now coming from somewhere else.

I have also sorted my spreadsheet by “Salary” in descending order so I can see names I recognize toward the top.SORT_DESCENDING

3. Now it’s time to add our newly learned INDEX and MATCH formula.

As I mentioned above, we need to embed the MATCH formula inside of the INDEX formula. We could attempt to write that one complicated formula right now, but I find it a lot easier to start small and expand my formulas rather than trying to write them all at once. And to do this I also find it easier to work from the inside out (another example of this is to start with a VLOOKUP formula first and then add IFERROR around it).

So let’s start with MATCH. Start to type the following into the first empty cell in your “Bats” column:

=MATCH(

At this point you should see Excel recognize the formula and display the inputs needed to make it work. Match function inputs

The first input is the lookup_value. Our goal is to look up a player’s FanDuel ID in our salaries list and locate the same ID in the “FANDUELID” column of the “PLAYERIDMAP” table. To reflect this, simply click on cell A2, which should contain the FanDuel ID of the first player listed (Clayton Kershaw in my file).

Because we are using tables, Excel should automatically translate cell A2 to become “[@Id]”, which is the convention for referring to a value in the same row but in the “Id” column.MATCH_ID

4. Type a comma after the “[@Id]” input. The next input for the MATCH function is the lookup_array, which is where we want to find the FanDuel ID. In this scenario we are going to look within the “PLAYERIDMAP” and more specifically within the “FANDUELID” column.

Start to type “PLAYERIDMAP” after your existing formula and you should see Excel recognize the table name we’re trying to refer to:TYPE_AHEAD

When you notice that Excel has recognized what you’re going to type, hit the Tab key and Excel will complete the item for you. This is called “type ahead”.

Let’s keep using this type ahead benefit to tell Excel we want the “FANDUELID” column of the “PLAYERIDMAP”. Type a “[” and you will be presented with a list of all the fields (or columns) in the “PLAYERIDMAP”.Excel table field list

Use your up and down arrow keys to cycle through the list of fields. When you find the “FANDUELID” column, hit the Tab key to select it for the formula. Excel MATCH formula animated gif.

After you have selected the column, type a the closing bracket (“]”) and a comma to end the lookup_array argument.

Finally, type a “0” in for the match_type argument and close the entire MATCH formula with an ending parenthesis and hit ENTER. Your complete MATCH formula should be:

=MATCH([@Id],PLAYERIDMAP[FANDUELID],0)
5. After you complete the formula, you should see Excel automatically copy that formula to all the players below. Scroll through the list to make sure it appears to be working properly.Lookup error #N/A

It’s very likely (inevitable) that you’ll find players displaying a “#N/A” error message. This doesn’t mean there’s an error in your formula. It means that the FanDuel ID was not located in the PLAYERIDMAP table. This is because I only aim to keep the list updated with “fantasy relevant” players. So bench players, non-impact rookies, and role players won’t be listed in the Player ID Map.

Even if these players aren’t going to enter our DFS lineups, we still need to handle this error message, but let’s table it for now and come back to it later.

6. Remember that the MATCH formula we just finished is an input into the INDEX function we will now use. Specifically, the MATCH function is the second input (Row_num) in the INDEX function:
INDEX(Array, Row_num, Column_num)

The first input, Array, is going to be “PLAYERIDMAP”. And the last input, Column_num, is the column number representing the batter handedness within the PLAYERIDMAP table. The “BATS” column, indicating batter hitting handedness, is in column AA of the Player ID Map, or the 27th column.

To wrap the INDEX formula around the MATCH formula, type the edits in red below:

=INDEX(PLAYERIDMAP,MATCH([@Id],
PLAYERIDMAP[FANDUELID],0),27)

After making that edit, you should now see batter information coming into the column.

HANDEDNESS

If you want to get really fancy, the hard coded “27” in the formula can be replaced with a formula that will determine that “Bats” is in the 27th column. Swapping out the “27” for this formula in blue will prevent problems down the line if the “Bats” column gets shifted into another column:

=INDEX(PLAYERIDMAP,MATCH([@Id],
PLAYERIDMAP[FANDUELID],0),COLUMN(PLAYERIDMAP[BATS]))

Excel’s type ahead feature can still be used while editing things, even though other parts of the function have been tailored properly.

I’ve written previously on the COLUMN function. You can read more about it and see another example of its use here.

7. Now let’s revisit the players that are displaying errors in this column. Leaving errors here could lead to more errors further down the line if we base future formulas on this handedness column. Lookup error #N/A

The IFERROR function is ideal for handling lookup errors like these. It’s also very easy to use. Simply wrap the IFERROR formula around your existing formula, and give one more input outlining the text or message you want to display if there is an error in the formula. You can read more about IFERROR here.

Let’s say we just want to leave the “BAT” column blank if an error is encountered. Entering two double quote marks consecutively will tell Excel to give a blank cell. With this our formula becomes:

=IFERROR(INDEX(PLAYERIDMAP,MATCH([@Id],
PLAYERIDMAP[FANDUELID],0),COLUMN(PLAYERIDMAP[BATS])),"")

I realize the formula is getting to be a little out of control at this point. If you’re having a hard time understanding what is going on, try using the tip on complicated formulas shown below this table of instructions.

Any formula that previously was resulting in an error will now show as a blank item.
IFERROR_RESULT

8. To create the formula for throwing (or pitching) hand, start by copying one of the cells in the “Bats” column.
COPY

Note, do not “drag” the formula using the black box in the lower right hand corner of the selected cell.BLACK_BOX

If you drag a formula that’s in an Excel table, the formula will adjust for the fact that you’ve moved it this way. Just like when you copy any normal Excel formula, the relative row and column references will change.

There is no way to enter absolute cell references in table formulas that I’m aware of (these are the “$” symbols you might put in an Excel formula so cell references don’t shift as the formula is moved). But if you copy and paste a formula, the cell references don’t change!

9. Because we haven’t changed the formula, the results in the “Bats” and “Throws” columns will be identical. So now just make the simple edit or replacing “BATS” with “THROWS” and you’ll be done!
=IFERROR(INDEX(PLAYERIDMAP,MATCH([@Id],
PLAYERIDMAP[FANDUELID],0),COLUMN(PLAYERIDMAP[THROWS])),"")

Just replace the "BATS" reference with "THROWS".

Just replace the “BATS” reference with “THROWS”.

When It Makes Sense To Use INDEX & MATCH

If you’re a long time reader of the site, up until now (whether it’s creating SGP rankings, in-season rankings, or points league rankings) we haven’t merged more than one set of data together.

I’ve only relied upon Baseball-Reference IDs (like kershcl01 for Clayton Kershaw) to lookup Fangraphs’ Player IDs and because of that, VLOOKUP always worked. That’s because the Baseball-Reference IDs are in the first column of the Player ID Map. A necessity for VLOOKUP.

But now that we are letting other Player ID systems run the show (FanDuel IDs) and we need to look in columns that are to the left of our main ID system, we need INDEX and MATCH to make things work.

Tip If You’re Struggling

If you find that you’re having a difficult time layering all of these formulas on top of each other, try using multiple columns in Excel to build your formulas. You can have a column for each of the main formula components:

  1. BatsMatch – Holds the Match formula
  2. BatsIndex – Holds the Index formula and uses BatsMatch as one of the inputs
  3. Bats – Is really just the IFERROR formula

Break you complicated formulas into multiple columns.

Here’s what each of the formulas would be:

BatsMatch: =MATCH([@Id],PLAYERIDMAP[FANDUELID],0)

BatsIndex: =INDEX(PLAYERIDMAP,[@BatsMatch],COLUMN(PLAYERIDMAP[BATS]))

BatsIndex: =IFERROR([@BatsIndex],"")

Instead of having lengthy formulas, these just reference and build upon one another.

What’s Next?

It’s going to be a bit of a challenge. But I think the next domino to fall has to be getting the opposing pitcher to show up in our file somewhere. We need starting pitcher to be able to determine which splits to use from our hitters and also to determine the quality of the overall matchup.

The FanDuel CSV file actually gives probably starting pitchers. We could just use formulas to pluck out the starter in each contest. But there’s no such information in Draft Kings’ exports.

I’m sure some of you are ahead of me in developing you spreadsheets. What websites are you pulling matchup information for? Keep in mind that we most likely want to find starting pitcher matchups for TOMORROW’s games. Not just the current slate of games. My goal is to provide an opportunity to start building a lineup a day in advance.

Thank you for following the site! Stay smart.

Adding Excel’s “Power Query” to Your Arsenal

$
0
0

About a week ago I got an e-mail from a reader of the site asking me for help using “Power Query” to pull some Fangraphs data into Excel. Power Query is an add-in for Microsoft Excel that offers more advanced data importing options and ability to combine data from different resources.

Power Query is an add-in that will appear on the Excel ribbon.

Power Query is an add-in that will appear on the Excel ribbon.

I knew Power Query existed. But as I was reading the e-mail, my palms began to sweat and an overwhelming sense of guilt washed over me.

“I don’t know anything about Power Query!!!”

Coincidentally, my wife was out of town for the weekend and with the girls in bed early, I had a handful of hours on Saturday night to give myself a crash course in how to use Power Query (ah, the exciting and glamorous nightlife of a baseball nerd!).

And now I might be hooked.

Tables, Tables, Tables!!!

I recently wrote a post (about importing a CSV file into Excel) that included a list of benefit to using Excel tables.

But I missed a really important one… If you import your data into Excel as a table, you create a connection to the data that is linked and can be updated automatically.

Let that sink in for a minute.

I’ve shown you how to make a lot of the Excel file’s that are isolated, dead, and not directly linked to any outside information.

I might have you download some data. Then copy and paste it into Excel. And then convert it into a table. But this is not ideal. The only way to update that information is to manually download it, open the file you downloaded, copy the data, paste it into your file, and cross your fingers that none of your formulas break when you paste over the top of everything.

If we can start importing data directly into Excel as tables, rather than copying and pasting data manually, we can maintain the link to the original data and then very easily update it in the future. And Power Query is capable of helping us do that. It gives more options to create live links to data sources and better options to manage those connections.

Power Query gives us more options to link to live data sources and better options to manage those connections.

Click the link to see a larger version of this image.

Imagine not having to rebuild a new rankings and dollar value file from scratch EVERY season. If you set the file up intelligently, you can use the same file to quickly get in-season values or to update the file for the next season in only a couple of minutes.

Power Query and the Power of Tables

When using Excel's standard web query to import data, you don't have the option to import the information as a table.

When using Excel’s standard web query to import data, you don’t have the option to import the information as a table.

In my limited use of Power Query so far, the thing that has me most excited is that it gives you the ability to import more data sources as tables. We have previously looked at how to use web queries to get information into Excel, but if you use a basic web query, the information does not come in as a table.

Granted, a web query does still leave a live link to the original data. But I want the best of both worlds. I want a live link to the original data AND to import it as a table!

There is a Catch

When using a standard web query (outside of Power Query), you do have the option to import the entire web page. This is messy and loaded with complications, but it’s helpful to have the option.

To view the actual HTML code of a site, right click on a web page and choose the option to "Inspect Element". If you don't see < TABLE > references, you may not be able to import the page with Power Query.

To view the actual HTML code of a site, right click on a web page and choose the option to “Inspect Element”. If you don’t see “<TABLE>” references, you may not be able to import the page with Power Query.

There is no such option in Power Query. You can only use Power Query to web query actual HTML tables from a web site. My educated guess is that to set something up as a table in Excel requires a neat and structured block of data, which querying an entire web page is not.

This is unfortunate, because some really great sites like Baseball Press don’t use tables to present their data. Instead, they use the division (< DIV >) HTML tag.

Downloading Power Query

Despite Power Query not being the silver bullet we need to resolve all our data needs, it’s definitely a tool worth having in the arsenal. And it’s free!

You can download the add in from this page. There are some restrictions you should know about. The program requires at least Windows 7 (sorry again Mac users… you should really look into partitioning your Mac to run Windows).

You also need to be running Excel 2013 (any version) or Excel 2010 “Professional Plus”. After you’ve downloaded the installation, close out of Excel and proceed through the installation. The new toolbar on the ribbon should appear the next time you open Excel. If you’re not seeing a “Power Query” tab, you may need to activate the add-in. Check out the instructions here on how to turn on the add-in (look for the section labelled “My Power Query Tab Disappeared”). POWER_QUERY_ADD_IN

Making Your First Web Query With Power Query

If you’ve read any of my previous pieces on web queries, this really isn’t that much different. The improvement is with the data being in a table and some additional capabilities to fine tune the data that is imported. But let’s take a closer look at how the basic functionality changes.

Step Description
1. The first task is to identify a web page you want to query AND to determine that it does contain HTML tables. My excitement over Power Query is tempered some by that fact that it is difficult to locate useful resources that put their data into tables. Many valuable sites and specific pages don’t!

Remember, to determine if data is in a table, right click somewhere on the web data you would like to capture and choose the menu option to “Inspect Element”.Inspect element

This will load the HTML “code” used to create the web page. If you see references to table, tr (means table row), or td (means table cell), this is a table and a web query should be successful.TABLE_ELEMENTS

A few examples of potentially helpful tables that I’ve found:

  1. FantasyPros.com ROS Projections
  2. Individual Fangraphs Player Pages
  3. Razzball.com ROS Projections
  4. Fangraphs Probable Pitchers List

After you have located a table to import, copy the web page address. For my example, I’ll use the Fantasy Pros rest of season projections (link is http://www.fantasypros.com/mlb/projections/ros-hitters.php). I realize this is not useful for DFS, but I just want to demonstrate the basics of Power Query now.Copy web page URL

2. Open a blank Excel file. Click the newly added “Power Query” tab. Then click the “From Web” icon on the left of the ribbon.Import from Web

Then paste the copied URL into the dialog box and click “OK”.Paste URL

3. The “Navigator” dialog will appear. It may take a minute or two to load as Excel processes each of the tables on the page.

Once the loading process completes, you will see a list of all the tables available for import. Click your mouse to locate the data you want. If you wish to import more than one table, check the “Select multiple items” box.

As you click on the various tables, watch the preview pane on the right in order to locate the exact table you want.Click tables and preview

4. Stop! This step is informational only. Don’t do anything!

At this point, you could click the “Load” or “Load To…” button. LOAD_TO

The “Load” button will import the data exactly as you see it into a newly created worksheet tab.

The “Load To…” option gives you a few more control over how the data loads. In the ensuing menu you have the option to import the table (recommended) or only add the connection to your file (not sure why you would want to do this unless you were unsure of where to place the table now). You can also choose to create a new worksheet or to place the table in an existing spot. Working with data models is something I may explore in the future. If you want to look ahead, you can start hereLOAD_TO_SETTINGS.

Loading from here bypasses some of the real value that Power Query offers. These features are available when you click the “Edit” button.Edit query settings

5. Start! You can start following along again.

Click the “Edit” button and the “Query Editor” will load. In this screen we not only see the preview of the data that will be imported, we can also clean things up.

For example, the first column is labelled “VBR”. This looks like some kind of a ranking, but I don’t want to import this. Additionally, the second column has a lot of information in it. Instead of seeing “Mike Trout(LAA – CF)” all in one column, I want to try breaking that into separate columns.QUERY_EDITOR_SCREEN

Rather than bring it in and have it clog up my screen, we can tell Power Query not to import this column. To do this, click on the “VBR” column to select it. Then click the “Remove Columns” button.CLICK_TO_REMOVE_COLUMN

6. Now let’s move on to splitting apart the player name, team, and position.

Click once on the “Player” column. Then click the “Split Columns” button.SPLIT_COLUMNS

And then click the “By Delimiter” option.BY_DELIMITER

A delimiter is a unique character that represents a change in the field or information. Looking at the data we have, the opening parenthesis is a delimiter between player name and team. There is no option to choose that from the drop down menu, so instead select the “–Custom–” option.CUSTOM_DELIMITER

Then type in the open parenthesis, “(“, and select the option for “At the left-most delimiter”.PARENTHESIS_LEFT_MOST

You should now see that the columns automatically get split!SPLIT_PLAYER

7. Let’s keep going and try to separate out each player’s position. Click the new “Player.2” column and then click the “Split Columns>By Delimiter” menu button again. This time use the settings in the image below to split the column at the hyphen.HYPHEN_DELIMITER

Power Query is really looking useful.PLAYER_TEAM_POS

8. The last thing bothering me is the closing parenthesis after each player’s position. To get rid of this, click to select the “Player.2.2” column and then click the “Replace Values” icon.REPLACE_VALUES

Once the “Replace Values” dialog loads, enter the closing parenthesis in the “Value To Find” field AND LEAVE THE “REPLACE WITH” FIELD BLANK! Then click “OK”.REPLACE_SETTINGS

Check this out…CLEANED_DATA

10. Now that the data is cleaned up, click the “Close & Load To…” button on the “Home” tab of the ribbon.CLOSE_AND_LOAD_TO

This will load the same “Load To” box discussed earlier. Adjust the settings as you see fit and click the “Load” button when you’re done.LOAD_TO_SETTINGS

The data loads exactly as you cleaned it up!CLEANED_TABLE

This Is Not the Best Example

Because I’m in the middle of a series of DFS-related blog posts, I wish I had a more concrete example that specifically tied in DFS information. But I did want to demonstrate the power of cleaning and tweaking data with Power Query. Hopefully you can recognize there is a great deal of value in knowing these tools exist so you can use them to solve issues as you build your own DFS spreadsheet with the information you like using.

I’ve included a couple more links below that may help you down the Power Query path.

As always… stay smart.

Are You Using Power Query? Other Add-Ins?

Is anyone using Power Query already? What kinds of things are you using it for? What sites are you loading the data from?

I’d love to hear it if you are. Please e-mail me or leave a comment below.

Other Resources

I’ve only given a brief overview of the full capabilities. If you’re intrigued and looking for more examples, check out these additional resources below.

Name Description
Download Page Free download page. Power Query is free, but it does require you to have Excel 2013 or Excel 2010 “Professional Plus” (I don’t know exactly what that means). It also requires you be using at least Windows 7.

If you’ve been on the fence about upgrading to the newest version of Excel, I list out a few of the purchasing options here.

Interactive Online TutorialIf you choose only one of these items to click on. Choose this one. The demo is only a few minutes long, but it does a great job of demonstrating how you can really fine tune and clean up the data you import through Power Query.
Interesting Examples that Might Apply to Baseball DataThis is a fairly lengthy post, but look specifically for the sections labelled “Append (Combine) Tables with Power Query”, (I could see this being a way to import a player’s last three seasons of data, or to import multiple projection systems) and “Merge Tables – A VLOOKUP Alternative” (a way to combine DFS salaries with info from other sites).
Introduction to Power QueryThis is simply a written explanation of Power Query and its features and benefits. More detailed than I’ve explained above.
Advanced Example, Dynamic and Multi-Layered QueriesI started this post off by referring to a question I received from a reader of the site. He wanted to provide Excel with a list of player IDs and then have it systematically go out to the player pages for each of those IDs and pull back data.

I wasn’t sure this was possible in Excel, but turns out that it is! This resource demonstrates how to make advanced edits to your query to make it dynamic (to ask for a player ID) and to make it multi-layered. Said another way, you can have one query go and fetch a list of player IDs and you can have a subsequent query run off each of those IDs. “Hey Excel, go get this list of players. Then go through each player on that list and go get me the standard data from their Fangraphs page.”

It’s slow… But it works.

How to Pull Projected Starting Pitcher Information into Your Daily Fantasy Baseball Spreadsheet

$
0
0

In this post I’m going to address two common questions I get about creating daily fantasy baseball spreadsheets:

  1. Where and how can I download today’s AND tomorrow’s projected starting pitchers?
  2. Why I don’t see the yellow arrow when trying to web query a site in Excel?

And in addressing those two questions, we’ll also take a look at a powerful tactic of using Google Sheets and Excel together to get baseball data off the web. We’ll be focusing closely on obtaining a list of projected starters, but the concepts behind using Google Sheets and tying that back into Excel is one that can be applied in many other areas (like creating spreadsheets for your season long leagues).

Where Can I Find a Reliable and User-Friendly List of Probable Starting Pitchers?

To view the actual HTML code of a site, right click on a web page and choose the option to "Inspect Element". If you don't see < TABLE > references, you may not be able to import the page with Power Query.

To view the actual HTML code of a site, right click on a web page and choose the option to “Inspect Element”. If you don’t see “<TABLE>” references, you may not be able to import the page into Excel.

We all know DFS is exploding and there are countless sites out there providing lineup information, alerts, weather data, and more. But unless I’m looking in the wrong spot, most of that information is intended for that day’s games. And as a father of two with a day job, I can’t practically create a lineup the day of a contest. I need to prepare a day in advance for the next day’s games.

The other challenge in finding this information is that it will be a lot easier to deal with in Excel if we can find the data in a table format (see image to the right, I won’t bore everyone with technical details, but just because data looks to be in columns and rows on a site, doesn’t mean it’s in the format Excel can handle easily).

I have struggled and struggled to find a good resource for tomorrow’s projected pitchers. AND IT HAS BEEN RIGHT IN FRONT OF MY FACE ALL SEASON! Take a look at the Fangraphs home page:

Fangraphs probable pitchers link.

If you visit the “Probables Leaderboard” (here’s an example link), it looks perfect. A table of all the projected starters, and even some friendly advanced metrics we could use in evaluating each player.

Fangraphs probable starting pitchers.

Now take a look at the URL for the page:

Fangraphs probable starting pitchers URL.

The URL for the probable pitchers list is dynamic and changes based upon the day you’re accessing it.

I started to write this post on September 4th. And when I clicked the “Probables Leaderboard” link, it took me to the “p2015-09-04” web address. You can see that last part simply reflects the current date.

Anytime you see a URL like that, with all the different arguments and parameters (like “pos”, “stats”, “lg”, “season”, etc.), you should get excited. It likely means you can manually type in values for those parameters and create your own “query” of the site. Here’s an example I wrote awhile back using Brooks Baseball to illustrate these concepts.

So instead of just using the “p2015-09-04” address, I tried “p2015-9-5”. This was to test two different things. First, to see if I could get tomorrow’s probables in the same table format. Second, to see if the zeros before the month and day numbers were important… And it worked!

Fangraphs dynamic URL

You can edit the URL to see tomorrow’s probable pitchers.

So not only do we have a reliable list of probable starters, we can also get the projected starters for days in advance!

We Need a Dynamic Web Query

While it’s great that we now know where to get tomorrow’s probable starters, the fact that the URL changes each day is a challenge. We’ll need to create a dynamic web query that can determine tomorrow’s date and download the data from the appropriate web address.

With this in mind, I brushed up my memory on how to create a dynamic web query (look for the section titled “Step-by-Step Instructions, Dynamic and Updating Web Query”) and started the process of building it in Excel.

Why Don’t I See the Yellow Arrow in My Excel Web Query Window?

Everything was going so well until I hit a common stumbling block that occurs when web querying in Excel. No yellow arrow displays on the table of data I want to capture in my web query. No yellow arrow displaying in Excel's web query preview window.

Why does this happen? One definite cause is if the information isn’t really in HTML table format (remember that image above?). But the Fangraphs table is in fact a table. I checked. I don’t have a great explanation as to why you don’t always see the yellow arrow, but I imagine it has something to do with how the table is coded or just Excel’s ability to properly process it.

But if you do in fact see that the data is stored in an HTML table, Google Sheets offers a very simple method of doing a web query. One that works even when the yellow arrow box is missing!

Why Don’t You Use Power Query?

Power Query was able to import the table, even when a traditional web query could not... But I can't yet figure out how to create a dynamic query in Power Query.

Power Query was able to import the table, even when a traditional web query could not… But I can’t yet figure out how to create a dynamic query in Power Query.

That’s a really good question. I just spent thousands of words spouting the virtues of Power Query, and in my next post I turn my back on it?

I would like to. But the dynamic web address tripped me up. I spent three days trying to figure out how to get it to work and was unsuccessful.

I ultimately realized that I knew a much easier way to do this with Google Sheets, and this is something I’ve been meaning to demonstrate for a long time. So rather than continue to waste time trying to get Power Query to do the job, why not go with something I already know?

The ultimate irony of the situation is that Power Query didn’t have a problem importing the probables! If I could only have gotten a dynamic query to work…

Enter Google Sheets

If you’re not familiar with Google Sheets, it is a very strong spreadsheet alternative to Microsoft Excel. And it’s free.

So why don’t I write more about using Sheets? Quite frankly, Excel is the better product. It is much more powerful and responsive, largely because it’s an application that runs on my own computer. Google Sheets is web-based and suffers from performance limitations and access issues because of it (if you have a slow internet connection or a lot of calculations in your spreadsheets, you’ll drive yourself crazy using Google Sheets).

With that said, there are some really interesting benefits to Google Sheets. Being free is hard to beat. It’s very easy to share a workbook and work on the spreadsheet at the same time as others. And as I mentioned, importing HTML table data is a snap!

Another really neat feature is that you can publish (or share) the results of a spreadsheet online in CSV format.

And a file in CSV format is easily importable into Excel!

So we can create a Google Sheet to web query troublesome table data. Publish that data as a CSV. And then use Excel (and even Power Query) to import the data into our master spreadsheet.

IMPORTHTML within Google Sheets, publish as CSV, the import the CSV into Excel.

Google Sheets makes the process of querying data from a web page very easy. You can then “publish” you Google Sheet as a CSV file on the web and then use Excel to import the CSV.

Let’s get started!

Prerequisites

To use Google Sheets, you need to have a Google account (if you use Gmail, Google Drive, or any other Google service beyond searching the web, you already have one). If you don’t have a Google account you can create one from the Google Sheets sign up page here.

Google Sheets Functions Used in This Post

IMPORTHMTL

Google IMPORTHTML formula guidance

In Excel, we set up a special connection to pull information from a website. Things are much simpler in Google Sheets. You enter a very simple formula and the data gets pulled into the document.

The specific function we’ll use is “IMPORTHTML”. The function has three inputs:

  1. URL – Enter the web address of the page to be queried in quotation marks. In our example, it will be the address of the Fangraphs Probables page.
  2. Query Type – This is the data type you wish to pull from the web page. You can enter either “table” or “list”. Similar to what we look for when doing an Excel web query, we most likely will be using the “table” option.
  3. Index – This is the instance number of the table (or list) on the web page. Google’s documentation says the index begins at 1, meaning if you want to query the first table on a page you would simply type a 1. If you want the fourth table on a page, you’d enter a 4. But for some reason using a 0 is what works for the Fangraphs page we’ll be using.

MONTH, DAY, and YEAR

These are three separate functions. Each is looking for one input, a date.

The MONTH function will return the numeric representation of the month in the date. DAY returns the numbers from the date string corresponding to the days. And YEAR returns the numbers of the year in the date.

Going back to our example date string from earlier, a formula of =MONTH("09/04/2015") will return “9”.

TODAY

The TODAY function requires no inputs. And when used it simply returns today’s date.

For example, if you enter the formula =TODAY() and look at your spreadsheet on September 5th, 2015, your spreadsheet will display “9/5/2015”.

The formula updates when your spreadsheet recalculates. So if you opened the spreadsheet the next day, the formula would display “9/6/2015”.

You can perform addition with the TODAY function. So if you wanted to display tomorrow’s date, the formula would be =TODAY()+1. Or a week from now would be =TODAY()+7. Knowing that we can add one to the TODAY function will be important to finding tomorrow’s probable starters.

CONCATENATING or BUILDING TEXT STRINGS

By now you probably realize that we’re going to take the beginning of that long Fangraphs URL and then attach the date, as calculated by the TODAY function, to that. Every day these formulas will update and automatically create the new URL to determine tomorrow’s pitchers.

To attach two strings of text together in Google Sheets (or in Excel), you can use the ampersand (“&”). For example, we could put tomorrow’s date in cell A1 of a spreadsheet and then use this formula to build the Fangraphs web address:

="http://www.fangraphs.com/leaders.aspx?pos=all&stats=pit&lg=all&qual=0&
type=8&season=2015&month=0&season1=2015&ind=0&team=0&rost=0&age=0&filter=&players=p"&A1

Step-by-Step Instructions – Create a Google Sheet and Use the IMPORTHTML Function

Step Description
1. Go to the Google Sheets home page and click the button to start a new blank spreadsheet.Start a new Google Sheet
Click on the “Untitled spreadsheet” title and give the file a better name. Maybe something like “Tomorrow’s Probables”.UNTITLED_SPREADSHEET
2. Next, we’ll use the date formulas previously discussed to build the date string to attach to the Fangraphs probable starters URL. Enter the following formula in cell A1:

=YEAR(TODAY())


This should result in just the year of today's date. As I write this post in September of 2015, the formula returns "2015".

Now we'll continue to build on this formula. Add the following to the existing formula in cell A1:

=YEAR(TODAY())&"-"&MONTH(TODAY())

Hit ENTER to accept your changes. See how the ampersand is used to add the hyphen and then another ampersand is used to add the month? As I write this post, that last formula results in "2015-9". We'll continue to use the ampersand to add new pieces of text to this string.

Now add the following to the end of the formula:

=YEAR(TODAY())&"-"&MONTH(TODAY())&"-"&DAY(TODAY())

This last piece puts in one more hyphen and then the current day of the month. In my example file it's showing "2015-9-5", which is the exact format we need for the Fangraphs page.

But remember, we want to show tomorrow's date. Not today's. So make these last final adjustments:

=YEAR(TODAY()+1)&"-"&MONTH(TODAY()+1)&"-"&DAY(TODAY()+1)

The reason we have to add one to all three pieces of the date is to account for when you reach the last day of a month. If you don't add one to the month component, your day would reset to "1" but your month would still be lagging one behind (e.g. If it's August 31st and I don't add one to all of the today formulas, my formula would results as "2015-8-1", not "2015-9-1").

3. We've completed the last date piece of the Fangraphs web address, so let's create the full address to the page so that it will update dynamically. Visit the Fangraphs probables page (here's a link you can use that will lead to an old date). Fangraphs probable pitchers link.
Use your mouse to select all but the end of the URL that contains the date (get the "p" though!).
Copy the entire Fangraphs web address but exclude the date piece of the Fangraphs URL.

Exclude the date piece of the Fangraphs URL.


Copy that URL. Then return to your Google Sheet. In cell A2 type an equal sign then a quotation mark:

="

Then paste the Fangraphs URL and close it with another quotation mark:

="http://www.fangraphs.com/leaders.aspx?pos=all&stats=pit&lg=all&qual=0&
type=8&season=2015&month=0&season1=2015&ind=0&team=0&rost=0&
age=0&filter=&players=p"

Now use an ampersand to append in cell A1 (the missing date component to the end of this formula):

="http://www.fangraphs.com/leaders.aspx?pos=all&stats=pit&lg=all&qual=0&
type=8&season=2015&month=0&season1=2015&ind=0&team=0&rost=0&
age=0&filter=&players=p"&A1

Hit ENTER to complete the formula and you should see a fully usable hyperlink that will take you to tomorrow's probable starters. IMPORTHTML_URL
To test the hyperlink, hover your mouse over it and then click on the popup that appears.Pop up URL link.

4. There are just two more inputs needed for the IMPORTHTML function. Type TABLE into cell A3 and a zero into cell A4.IMPORTHTML_ARGUMENTS
Now click the downward pointing arrow on the sheet name at the bottom of the screen and then choose the menu option to "Rename...".Rename sheet
Give this tab or the spreadsheet a meaningful name, like "IMPORTHTML Inputs".IMPORTHTML_INPUTS
5. Now click the "+" sign, to the left of this newly renamed tab, in order to start a new sheet.Add a new sheet.
Click the downward pointing triangle on this new sheet and rename it to something meaningful, like "Probable Starters".RENAME_PROBABLE_STARTERS
6. Click your mouse into cell A1 and enter the following formula:

=IMPORTHTML('IMPORTHTML Inputs'!A2,'IMPORTHTML Inputs'!A3,'IMPORTHTML Inputs'!A4)

If you named your first tab exactly the same as I did, you can copy and paste the formula above into cell A1. Or instead of typing out the formula, you can click to your "IMPORTHTML Inputs" tab and select the applicable cells.

Hit enter to accept the formula. After several seconds (depending on the speed of your internet connection), you should see the probable pitchers load!Fangraphs probable starting pitchers list

You can see that it's very easy to pull data from the web into Google Sheets. Much easier and with fewer steps than in Excel.

7. Before we go on, think for a moment about how an Excel spreadsheet runs its calculations. Similar to Google Sheets, Excel has a TODAY calculation. But if the Excel file containing the TODAY formula was closed for an entire week, we wouldn't expect that the TODAY formula was updating each day in that closed spreadsheet.

We face a similar problem with this Google Sheet. We don't want to have to open this list of probable starters each day just so it can update the list. It would be great if there were a property we could turn on so that the spreadsheet would refresh itself every so often... And fortunately Google offers this feature!

Within the Google spreadsheet, go to the "File>Spreadsheet Settings..." menu.File menu, spreadsheet settings

In the ensuing menu, adjust the "Recalculation" setting to the "On change and every hour" setting. This means the spreadsheet will reevaluate the TODAY formula each hour and update the list of probable starters accordingly. Recalculation settings, recalculate on change and every hour.

Click the "Save settings" button to accept this change.

8. The last task we need to complete in the Google Sheet file is to publish the list of starters as an online CSV file.

To start this process, click on the "File>Publish to the web..." menu. Publish Google Sheet as online CSV file.
Click the drop down that currently says "Entire Document".PUBLISH_TO_WEB_SCOPE
Then choose to only publish the "Probable Starters" tab.PUBLISH_PROBABLES
Now click the drop down that says "Web page" and change it to the "Comma-separated values (.csv)" option.Publish Google sheet as CSV file.
Click the "Publish" button to complete your changes.PUBLISH

9. After you click the publish button, the menu will change to display a link to the published CSV file. Copy this link for now. We'll need it in the next section. In fact, you may want to copy and paste it into a Word file or some other place for easy access. We will use it again a couple of times.COPY_CSV_LINK
You can always return to review or change these settings under the "Publish to the web..." menu. Just click the "Stop publishing" button, reconfigure the settings to your liking, then republish the document.STOP_PUBLISHING

Google Sheets Wrap Up

Now you see how much more simple the "web query" is in Google Sheets. Especially the creation of a dynamic query that can grab the results of a different page each day with no need for us to update or even open the file! When a new day rolls around, the probable starters list will automatically update in the Google Sheet and in the published CSV file.

The ease of importing data is a huge benefit of Google Sheets, but on the whole I don't find it to be up to par with Excel. So now let's take a look at how to get this CSV file into our daily fantasy baseball spreadsheets.

Step-by-Step Instructions - Import a Published CSV File Into Excel

Step Description
1. Open your daily fantasy baseball spreadsheet (if you haven't been following along to this point, you should be able to catch up reading these).

We will need the web address of the published CSV file we just imported. So if you've lost it from your clipboard, return to your Google Sheet and the "Publish to the web..." screen to copy the address again.

In your Excel file, click the button toward the bottom to insert a new sheet. New Excel sheet

Then right-click on the new sheet and choose the menu option to rename it. Name it something like "Probable Starters Import".RENAME_EXCEL_SHEET

2. Click on the "Data" tab of the Excel ribbon and then click the "From Text" button on the "Get External Data" grouping of icons.Get external data from text file.

You will then be presented with a browsing window where you are expected to look for some kind of text file on your computer. Instead, just paste the published Google Sheet's URL you copied earlier into the "File name:" field and then hit "Open".PASTE_GOOGLE_SHEET_PUBLISHED_URL

3. Excel's "Text Import Wizard" should appear. A CSV file is a "Delimited" file, which just means there is a comma or some other character that divides the file into different columns or fields (CSV literally stands for comma separated values). So leave the "Delimited" option selected.DELIMITED
Looking at the preview of the file, you can also see that the first row of information is really column headers or field names.FIRST_ROW_HEADERS
Hit the "Next" button to proceed to the next importing step.
4. This screen of the import wizard is asking what character type the delimiter is. Because we are importing a CSV, it's a comma. Check that option in the list of delimiters and look at the "Data Preview" to make sure the columns are breaking in the proper places (you should see lines drawn between each column).COMMA_DELIMITED
Click "Next" to proceed to the next step.

The ensuing screen allows you to classify each column as a certain data type. I don't think we need to worry about changing data types here, so just click the "Finish" button.FINISH_CSV_IMPORT

5. You should then be asked where to import the data. This is an important screen here. I want to import this as an Excel table, but that option is currently grayed out. GRAYED_OUT_TABLE
Check the "Add this data to the Data Model" check box. This should activate the "Table" radio button. ADD_THIS_DATA_TO_THE_DATA_MODEL
You can choose where you want the data to be placed. Or you can leave it set to cell A1 in the worksheet we just created.

Before hitting "OK", click the "Properties" button.

This should bring up the "Connection Properties" menu. Rename the connection to be something like "Google CSV Probable Starters" (or else you're going to have to remember what that awful mess of letters and numbers means). And then adjust the property check boxes to those shown below.

Make sure to uncheck the "Prompt for file name on refresh" box. And although it sounds like a good idea to check the "Refresh data when opening the file" box, DON'T! Checking that now seems to cause error messages when opening my spreadsheets. But we can come back later and check it with no issue.CONNECTION_PROPERTIES

Click "OK" to close the Connection Properties. Then click "OK" to accept the "Import Data" settings and to perform the actual import.

6. Now we can return to update the refresh file on opening setting. Click on the "Data" tab of the ribbon. Then click the "Connections" button.DATA_CONNECTIONS
Locate the Google CSV connection we just created. Select it from the list. Then click the "Properties..." button.GOOGLE_CSV_CONNECTION_PROPERTIES
Now check the "Refresh data when opening the file" box and hit "OK" to accept the change.REFRESH_FILE_ON_OPENING
7. You should now have a full table of probable pitchers for tomorrow's games, allowing you to more easily start your lineup research the day before. The list should update when you open the file, and it should always be looking one day ahead of the current day (remember, even though you're not opening the Google Sheet, it's updating itself each hour).Final CSV probable pitchers list imported into Excel

Why You Might Want to Try Power Query

Writing a post for the site often takes me one or two weeks. And it's a good thing in this case, because I noticed that the Google IMPORTHTML results will show an odd result on certain days. Take a look.GOOGLE_SHEET_EXTRA_TABLE_TAG

I can't determine why, but some days the results bring in some kind of "[TABLE]" tag before and after the list of pitchers.

This isn't a big deal, but it does cause a problem if we do want to import the information as a table. The reason being that the first row of the CSV file is expected to be the column names of the Excel table. We'll have a problem if that row is blank some days and shows "Name", "Team", "W", "L", and "SV" on other days.BAD_COLUMN_HEADERS

This is another example where using Excel's Power Query to clean up the data before importing will come in handy. Specifically, we can tell Power Query not to import any row with a value of "[TABLE]" in the first column. That will then move the actual column names up to the proper row.

If you haven't yet read this introduction to Power Query, I highly suggest you start there first. You don't necessarily need to complete the example, but learning how to activate Power Query and an overview of how it works will be important.

Let's take a look.

Step-By-Step - Instructions Using Power Query

Step Description
1. Remember that URL to your published Google Sheet CSV file? We will be using that again shortly. If you saved it on the side in a Word document, go copy it again now. Or if you need to return to your Google Sheet and copy it again from under the "File>Publish to web..." menu.Publish Google Sheet as online CSV file.
Return to your daily fantasy baseball Excel file. Add another blank sheet and rename it something like "Power Query Probable Starters".NEW_TAB_POWER_QUERY
On the "Power Query" tab of the ribbon, click the "From File" drop down menu and then choose the "From CSV" menu option.Power Query menu, From File, From CSV import option
When the browsing window opens, simply paste the Google Sheet CSV URL into the file name field and hit "Open". PASTE_CSV_URL
2. You may then be prompted to choose if you need to use special log in information to access the file. In this case we do not (because we published the CSV publicly on the web), so you can use the "Anonymous" option on the right side of the menu.

I don't think it matters the URL to apply the settings to. I elected to only apply the settings to the exact CSV file in question (the second option) and not all Google documents.

Click the "Connect" button.Power Query anonymous log in.

3. Once the data loads into the Query Editor, our goal will be to filter out the "[TABLE]" item.

If you don't currently see the item, I'm afraid you will eventually. And we should still be able to filter out the item for when it inevitably shows up. Here's another look at what I've seen several times.UNWANTED_TABLE_TAG
To apply a filter, click on the drop down menu over the first column of the table. Choose the "Text Filters" menu option and then the "Does Not Equal..." choice from the list. We will be trying to display all items that do not equal "[TABLE]".
FILTER_COLUMN1_NOTEQUAL

4. When the filtering dialog appears, type [TABLE] in the cell. And then click OK.DOES_NOT_EQUAL_FILTER
The table should then update and if you were seeing the [TABLE] tag, it should now be filtered out.TABLE_TAG_REMOVED
5. Now click the "Use First Row as Headers" button. USE_FIRST_ROW_AS_HEADERS
This will move the row containing "Name", "Team", "W", and "L" up to be the column headers.CLEANED_UP_FIRST_ROW
6. At this point, our data has been set up and cleaned. It's ready to load into the Excel file. Click the drop down on the "Close & Load" button and then choose the "Close & Load To..." option. CLOSE_AND_LOAD
The "Load To" menu should appear. Because we already set up the worksheet to hold this data, change the radio button under the "Select where the data should be loaded" section to "Existing Worksheet". Then click the "Load" button.LOAD_TO_EXISTING_WORKSHEET
Your data should be loaded!FINAL_POWER_QUERY_IMPORT
At this point you may want to complete step 6 in the table above (the second set of instructions on this page) in order to get your probable pitcher data to refresh automatically each time you open the Excel file.

Wow, This is Cool. Now What Do I Do?

Unfortunately, I have to stop this post somewhere. Or it will go on forever!

But if you want to forge ahead, the logical next step is to use a VLOOKUP or an INDEX & MATCH combination to get each probable pitcher listed next to each batter on the FanDuel Salaries list. The link between the Fan Duel salary info (image below) and the probable pitchers is not obvious, so it will take some work.

FANDUEL_SALARY_INFO

My thoughts are to use the "Opponent" column from the Fan Duel data and attempt to link it to the "Team" column on the Fangraphs probable starters list.

To match a hitter against his probably opposing pitcher, you might try matching the "Opponent"...

To match a hitter against his probably opposing pitcher, you might try matching the "Opponent"...

...to the "Team" on the probable pitchers list. But we'll have to deal with one side using team abbreviations and another team nickname.

...to the "Team" on the probable pitchers list. But we'll have to deal with one side using team abbreviations and another team nickname.

This may bring me into a future post about another problem I've recently realized... We need an MLB Team Map just the same way we needed a Player ID Map. There is no standard way to refer to MLB teams. Many sites use a slightly different way of doing it. Heck, sometimes the Chicago White Sox are "CHA" and sometimes they're "CHW". Sometimes the Cubs are "CHC" and others "CHN". We also have the issue of the Fangraphs data which spells out team names!

Do Things The Right Way

At this point, you may be feeling overwhelmed. Like there is too much to tackle here.

Just remember that if you set things up correctly so they are linked and pull data automatically from some resource (whether the web, a CSV in Google, or a CSV you save to your desktop), you will save time in the long run. Invest the time now. Save time later.

The Big Takeaway

Whether or not you use this strategy to pull in probable pitchers, the tactic of using Google Sheets as an import tool into your daily fantasy Excel file is a very valuable tool. I don't want that to get lost in the shuffle. This is powerful stuff!

Thoughts

I'd be curious to hear your thoughts on a couple things.

  1. Am I crazy for trying to bring information like this in?
  2. Have things gotten too complicated for you?
  3. Even if you don't use it for probable pitchers, I'm loving the Google Sheets to CSV approach. The other neat thing about this is one person could create this and share it to other... What web pages would you like to see in this format?
  4. What other DFS, baseball, or matchup data would you like to look at importing

As always, thanks for reading. And for letting me rub a little dork off on you.

Stay smart.

New Tool – MLB Team ID Map

$
0
0

Here’s a not so hypothetical scenario…

You have downloaded a CSV file of player salaries from DraftKings or FanDuel. You pull that information into Excel. Your goal is to take the “Opponent” information and use it to determine who each player’s opposing starting pitcher will be.

FANDUEL_SALARIES

A list of DFS player salaries and an abbreviation for the opposing team.

You have also followed this very brief set of instructions on how to get a list of starting pitchers into Excel that refreshes automatically each day (OK, not so brief).

FANGRAPHS_PROBABLES

A list of the day’s probable starting pitchers and their team name. How can we get this list of probable starters listed against the player salary list from above?

The challenge is that the list of starters does not use the same team name system as the DFS salary information. This is but one example of this. If you ever try to combine information about MLB teams that comes from different web sites, you’ll likely find a number of other inconsistencies. Even the sites that use abbreviations (like the DFS info above), don’t use them consistently. Sometimes the Giants are “SF” and sometimes they’re “SFG”. The Nationals might be “WAS”, “WSN”, or “WSH”!

The Solution – a Team ID Map

To solve this problem, I have created an “MLB Team ID Map”. It’s similar in concept to the Player ID Map.

Click the image to see the live web page of the Team ID Map.

Click the image to see the live web page of the Team ID Map.

The map lays out the abbreviations (or team name, in Fangraphs’ case) from the following sites:

  • Fangraphs
  • Baseball Reference
  • FanDuel
  • DraftKings
  • Yahoo!
  • ESPN
  • FantasyPros
  • BaseballPress
  • Baseball Prospectus
  • Rotowire

Two Formats to Use the Team ID Map

The information is available in both a web page format (so you can web query it) and in an online CSV file (see instructions on how to use the CSV option later in this post).

Link to the Web Page Format:
http://www.smartfantasybaseball.com/TEAMMAPWEBPAGE

Link to the CSV File:
http://www.smartfantasybaseball.com/TEAMMAPLINK

Importing the CSV Team ID Map Into Excel


Step Description
1. Open fantasy baseball spreadsheet you’re trying to add the Team ID Map too.

In your Excel file, click the button toward the bottom to insert a new sheet. New Excel sheet

Then right-click on the new sheet and choose the menu option to rename it. Name it something like “MLB Team ID Map”.RENAME_EXCEL_SHEET

Now copy this bolded web address:
http://www.smartfantasybaseball.com/TEAMMAPLINK

That’s the address of the CSV version of the Team ID Map.

2. Click on the “Data” tab of the Excel ribbon and then click the “From Text” button on the “Get External Data” grouping of icons.Get external data from text file.

You will then be presented with a browsing window where you are expected to look for some kind of text file on your computer. Instead, just paste the web address you just copied earlier into the “File name:” field and then hit “Open”.PASTE_TEAM_MAP_URL

3. Excel’s “Text Import Wizard” will appear. Make sure the “Delimited” option selected (a CSV file is a data file in which the columns of data are separated by commas, this makes it “delimited”). Also make sure you have checked the “My data has headers” check box.TEXT_IMPORT_TEAM_MAP

Hit the “Next” button to proceed to the next importing step.

4. This screen of the import wizard is asking what character type the delimiter is.

Because we are importing a CSV, it’s a comma (CSV stands for “comma separated values”). Check that option in the list of delimiters and look at the “Data Preview” to make sure the columns are breaking in the proper places (you should see lines drawn between each column).COMMA_DELIMITED

Click “Next” to proceed to the next step.

The ensuing screen allows you to classify each column as a certain data type. The Team ID Map is simply a list of text information, so we don’t need to worry about changing data types here. Just click the “Finish” button.DATA_TYPE_IMPORT

5. You should then be asked where to import the data. This is an important screen here. I want to import this as an Excel table, but that option is currently grayed out. GRAYED_OUT_TABLE

Check the “Add this data to the Data Model” check box. This should activate the “Table” radio button. ADD_THIS_DATA_TO_THE_DATA_MODEL
You can choose where you want the data to be placed. Or you can leave it set to cell A1 in the worksheet we just created.

Before hitting “OK”, click the “Properties” button.

This should bring up the “Connection Properties” menu. You might want to rename the connection to be something like “Team ID Map”. And then adjust the property check boxes to those shown below.

Make sure to uncheck the “Prompt for file name on refresh” box. And although it sounds like a good idea to check the “Refresh data when opening the file” box, DON’T! Checking that now seems to cause error messages when opening my spreadsheets. But we can come back later and check it with no issue.TEAMMAPLINK

Click “OK” to close the Connection Properties. Then click “OK” to accept the “Import Data” settings and to perform the actual import.

6. Now we can return to update the refresh file on opening setting. Click on the “Data” tab of the ribbon. Then click the “Connections” button.DATA_CONNECTIONS
Locate the connection we just created. Select it from the list. Then click the “Properties…” button.RENAME_CONNECTION

Now check the “Refresh data when opening the file” box and click the “OK” button.REFRESH_WHEN_OPENING

7. You now have the Team ID Map in your spreadsheet and it will update automatically any time I make adjustments in the future (if I add a new site’s team abbreviations, they’ll show up in your file). FINISHED_TEAM_ID_MAP_IMPORT

Give Me An Example of How to Use This Thing

You’ll need to use Excel’s INDEX and MATCH functions to make the best use of the Team ID Map (here’s an example of INDEX and MATCH).

FINISHED_OPP_SP

Sticking with the same example from earlier in this post, you can use INDEX and MATCH to take the “Opponent” column in the image above, go into the Team ID Map, and bring back the Fangraphs standard team name.

INDEX_MATCH_FANDUEL_FANGRAPHS

Then in the “OpposingSP” column in the image above, take the value in your “FangraphsOpp” column, go into the probable starting pitchers list, and bring back the name of the starter for that team.

INDEX_MATCH_FANGRAPHS_PROBABLE

Download a completed Excel file example of this Google Sheet CSV Link w Team ID Map.

Need Another Site Added?

Let me know in the comments below if you’d like team abbreviations added from another site.

Thanks for reading. Stay smart.

Important Player ID Map Update

$
0
0

I’m a little biased, but I think the Player ID Map is an invaluable tool.

But if I’m being honest… it has a really big weakness. When I make changes to it, there’s not a great way for me to get that updated information to you.

Until now!

The Easy-to-Update Player ID Map

After discovering that you can create a live connection from a Google Sheet to an Excel file, I have moved the Player ID Map into a Google Sheet.

The advantage of doing this is that you can link to this Google Sheet in your own spreadsheets. And if you download the Excel version, it will already have a pre-established link to the Google Sheet version.

How to Update the Player ID Map

Once you’ve downloaded the new version, you can simply right-click anywhere in the player listing and choose the option to “Refresh” the connection. Any changes will automatically pull into your file.

REFRESH_CONNECTION

The “Change Log” tab of the Player ID Map will work the same way. Right-click and refresh the connection on that page to get an updated listing of the changes that have been made.

CHANGE_LOG_PLAYER_ID

In the past you would have to come back to the site, download a new copy of the Excel file, and then paste it into your existing spreadsheets. Now you’ll just need to right click (or keep reading to see how you can have it update automatically) and update it!

The Links

The Player ID Map and Change Log are available in a variety of formats, depending on the goal you’re trying to accomplish.

Description Information
Player ID Map Excel File Link: http://www.smartfantasybaseball.com/wp-content/uploads/2013/03/SFBB-Player-ID-Map.xlsx

This is a link to download the Player ID Map in Excel. The only notable change here is that the table within this Excel file now is connected to an online source so that when I add players to the list, they can easily be refreshed in your files.

Player ID Map Web Page Link: http://www.smartfantasybaseball.com/PLAYERIDMAPWEB

This is a web page version of the Player ID Map. You can web query it into your Excel files or simply look at the list if you’re searching for a piece of information.

Player ID Map CSV File Link: http://www.smartfantasybaseball.com/PLAYERIDMAPCSV

This link can be used to create a connection to an online CSV version of the Player ID Map that you can set up within Excel. We’ll take a closer look at how to do this in a set of instructions below.

Change Log Web Page Link: http://www.smartfantasybaseball.com/PLAYERIDMAPCHANGELOG

This is a web page version of the Player ID Map Change Log. You can web query it into your Excel files or simply look at the list of changes to see what updates have recently been applied.

Change Log CSV File Link: http://www.smartfantasybaseball.com/PLAYERIDMAPCHANGELOGCSV

Similar to the CSV of the actual Player ID Map, this link can be used to create a connection to the change log within Excel. We’ll take a closer look at how to do this in a set of instructions below.

What If I Currently Have the Old Player ID Map in my File?

It’s great that the newly downloaded Player ID Map comes with the connection. But what about those who have the old version? Here’s a short set of instructions of how to establish this connection.

Step Description
1. Open the existing Excel file you have that contains the unlinked Player ID Map*. Save a backup of this file just in case something goes wrong in this process.

* Please note this will not work on the Projecting X Excel Template. If you’re interested in updating that file, please contact me for information.

2. Download and open the new Player ID Map (click here to download). After the file downloads, you will likely have to “Enable Editing” by clicking the warning button.ENABLE_EDITING

Then click the button to enable the external data connections in the file (this is so the information can connect to the Google Sheet and download any updates I make).
ENABLE_EXTERNAL_DATA_CONNECTIONS

3. Next, we will copy the entire Excel table from the new Player ID Map and paste it right over the top of the old Player ID Map table in your existing file.

To do this, click in cell A1 of the new Player ID Map. Then hit the SHIFT+CTRL+END keys on your keyboard. This should select the entire body of the Player ID Map table.COPY_PLAYER_ID

Then copy the selected data (right-click Copy or CTRL + C).

4. Now open your existing Excel file and go to the “PLAYERIDMAP” tab. Select cell A1 and paste the new Player ID Map right over the top of this old Player ID Map.

Depending on the security settings you have set in Excel, you may see a warning that pasting this will create a connection within your Excel file. If you trust the information I provide, click “OK”. This is your goal. To create a connection to the Player ID Map.
COPY_PLAYERIDMAP_TO_NEW_FILE

5. After you have pasted in the connection, you can adjust the settings of how it updates by clicking on the “Data>Connections” button on the ribbon.DATA_CONNECTIONS

Then locate and click once on the “PLAYERIDMAP CSV Link” connection and click the “Properties…” button.CSV_LINK_PROPERTIES

I would suggest checking the “Refresh data when opening the file” box. The alternative is leaving it unchecked but then having to remember to periodically refresh it manually to see if updates have been made.REFRESH_ON_OPENING

Click “OK” to close the Properties window and then “Close” to close the Connections window.

You Can Also Create Your Own Connection

If you’re starting a file from scratch or are interested in adding the Player ID Map to an existing Excel file, you can easily create a linked connection in that file.

In the instructions below, I’ll show you how to create a connection to the “Change Log” in the Player ID Map, but the same steps can be used to add a link to the “Player ID Map” information or any other published CSV file. You might want to link in the Change Log so you can see what updates have recently been made.

Step Description
1. Open the fantasy baseball spreadsheet you’re trying to add the connection too.

In your Excel file, click the plus sign button toward the bottom to create a new sheet. NEW_SHEET

Then right-click on the new sheet and rename it something descriptive. For my example, I’ll name it “Player ID Change Log”.RENAME_SHEET

Now copy this bolded web address:
http://www.smartfantasybaseball.com/PLAYERIDMAPCHANGELOGCSV

That’s the address of the CSV version of the change log.

2. Click on the “Data” tab of the Excel ribbon and then click the “From Text” button on the “Get External Data” grouping of icons.Get external data from text file.

You will then be presented with a browsing window where you are expected to look for some kind of text file on your computer. Instead, just paste the web address you just copied earlier into the “File name:” field and then hit “Open”.PASTE_CSVLINK

3. Excel’s “Text Import Wizard” will appear. Make sure the “Delimited” option selected (a CSV file is a data file in which the columns of data are separated by commas, this makes it “delimited”). Also make sure you have checked the “My data has headers” check box.CSV_IMPORT

Hit the “Next” button to proceed to the next importing step.

4. This screen of the import wizard is asking what character type the delimiter is.

Because we are importing a CSV, it’s a comma (CSV stands for “comma separated values”). Check that option in the list of delimiters and look at the “Data Preview” to make sure the columns are breaking in the proper places (you should see lines drawn between each column).COMMA_DELIMITED

Click “Next” to proceed to the next step.

The ensuing screen allows you to classify each column as a certain data type. The change log is simply a list of text information, so we don’t need to worry about changing data types here. Just click the “Finish” button.FINISH_CSV_IMPORT

5. You should then be asked where and how to import the data. This is an important screen here. When given the option, I think you should choose to import data as an Excel table, but you see that option is currently grayed out. GRAYED_OUT_TABLE

Check the “Add this data to the Data Model” check box. This should activate the “Table” radio button. ADD_THIS_DATA_TO_THE_DATA_MODEL
You can choose where you want the data to be placed. Or you can leave it set to cell A1 in the worksheet we just created.

Before hitting “OK”, click the “Properties” button.

This should bring up the “Connection Properties” menu. If you wish to do so, you can rename the connection here. And then adjust the property check boxes to those shown below.

Make sure to uncheck the “Prompt for file name on refresh” box. And although it sounds like a good idea to check the “Refresh data when opening the file” box, DON’T! Checking that now seems to cause error messages when opening my spreadsheets. But we can come back later and check it with no issue.CSV_IMPORT_PROPERTIES

Click “OK” to close the Connection Properties. Then click “OK” to accept the “Import Data” settings and to perform the actual import.

6. Now we can return to update the refresh file on opening setting. Click on the “Data” tab of the ribbon. Then click the “Connections” button.DATA_CONNECTIONS
Locate the connection we just created. Select it from the list. Then click the “Properties…” button.CSV_CHANGE_PROPERTIES

Now check the “Refresh data when opening the file” box and click the “OK” button.REFRESH_ON_OPENING_CHANGELOG

7. You now have the Change Log listing in your spreadsheet and it will update automatically any time I make adjustments to the Player ID Map in the future (if I add a new players or fill in missing information, it will be listed on the log). CHANGE_LOG_PLAYER_ID

Note, sometimes information comes into my tables sorted in an odd manner. You can sort the Change Log listing so the most recent changes appear on the top by clicking the filter drop down menu above the “DATE” column and choosing the “Sort Newest to Oldest” option.SORT_NEWEST_TO_OLDEST

Need a Player Added?

Now that I can push out updates to your file much more easily, let me know if you need a player added to the Player ID Map. Let me know on Twitter if you find a missing player.

Thanks for reading! Stay smart.

An Important Lesson and How to Resolve VLOOKUP Errors

$
0
0

Let me come clean. I screwed up. And it likely will cause you to see errors in your spreadsheets. That’s the whole reason for this post.

Having trouble with VLOOKUP error messages? This post should help.

Having trouble with VLOOKUP error messages? This post should help.

What Happened?

While this post is going to address a very important topic (resolving VLOOKUP errors), there wasn’t much of a need for this until I came up with a new format for the Player ID Map. The intent was to make the Player ID Map easily updatable. I hate having to lookup the IDs, birth dates, and handedness of all the new players.

And it’s always bothered me that there was no easy way for you to get updated Player ID information.

Let’s be honest. It’s a pain in the ass. Especially this time of year when players are switching teams every day and minor league players we haven’t had to deal with in the past are now projected to reach the big leagues this season. It’s tedious to keep teams up-to-date and to add these new players.

I needed to find a way to improve this process and to make everyone’s lives a little easier.

The Solution

The solution was to make the Player ID Map available in an online CSV file. One you connect that online file to your Excel spreadsheet, you simply have to right-click on the Player ID Map and hit “Refresh”. You will instantly get any update I’ve made.

Sounds amazing, right?

Major leaguers  have a purely numeric Fangraphs ID while minor leaguers have text in their ID.

Major leaguers have a purely numeric ID while minor leaguers have text in their ID.

The Problem

The fly in the ointment happens to be the way Fangraphs structures their player IDs. Major leaguers, like Jose Abreu, have a purely numeric ID. Whereas minor leaguers that have not reach the big leagues, like Yoan Moncada, have the text “sa” in front of a string of numbers.

The unintended consequence of importing the Player ID Map file is that because some IDs contain text, Excel will treat the ENTIRE imported column as text.

The problem is that reports you download from Fangraphs and then open in Excel treat the player ID column as numeric values.

Warning… It’s About to Get Technical

If you’re fine with the old Player ID Map and the fact that it doesn’t get updated very often, you don’t have to use the new one. The old one can be downloaded here and will still be updated periodically. You can stop reading this post and save yourself some sanity.

But if a little complication doesn’t scare you off and you see the value in being able to refresh the Player ID Map and get regular updates… Keep reading.

Text and Numbers Are Treated Differently

Excel and most other computer applications treat text and numbers differently. And this is a common problem with VLOOKUPS. So the number “15676” is not the same as a text string of “15676”. So in our VLOOKUPS, we need to make sure we are comparing numbers to numbers and text to text.

Consider the Error Message

The first step in resolving a VLOOKUP problem is to understand the error message you’re seeing.

The “#N/A” error is the most common VLOOKUP error. And it essentially means that a match was not found during the lookup.

There are two main reasons a match would not be found:

  1. The item (player ID) doesn’t exist where you told Excel to look for it
  2. Or you told Excel to look for the wrong data type (look for a text value in a list of numbers, or vice versa)

These are the downloaded Steamer Projections. Abreu's ID is the there. It's in the first column. Why isn't the VLOOKUP finding this???

Abreu’s ID is the there. It’s in the first column. Why isn’t the VLOOKUP finding this???

You can easily test the first error by manually performing the search yourself. Let’s walk through a hypothetical example with Jose Abreu. He’s a well known player. He’ll surely be in the Steamer projections I’ve downloaded.

I see from the data that Abreu’s Fangraphs ID is 15676. If I trace that through into the Steamer Hitter projections, I am able to locate Abreu. So why isn’t the VLOOKUP finding the same match?

Check Your Formula

Now that you’ve verified the ID exists, check your formula to make sure it’s performing the same search you did manually. This is another reason I am a big fan of using table names and structured references in Excel, especially when setting up lookup formulas. If you look at the formula below, you can make pretty decent sense of it.

DOUBLE_CHECK_FORMULA

It says to use the value in the “IDFANGRAPHS” column and look for its match in the first column of the “STEAMER_H” table. Then after you find the match, bring back the value in the “PA” (plate appearances) column.

At this time it’s important to revisit the main weakness of the VLOOKUP. The data you’re hoping to match up has to be in the FIRST column of the data set. So when you tell Excel to look in the “STEAMER_H” table, your player IDs have to be in the first column of that table.

That formula looks good to me. You can see from the image above that the PlayerID column is the first column. So we’re confident our formula looks good. Then we may be experiencing the other reason for a VLOOKUP failure – perhaps we told Excel to look for the wrong data type.

Things to Look Out For

Here are some clues you can look for to determine if you have a data type problem.

Num What to Look For
1. Look in the “IDFANGRAPHS” column of the image. Data that is left-aligned is usually being treated as text. LEFT_ALIGNED
2.Data that is right-aligned is usually being treated as a number. RIGHT_ALIGNED
3. Be on the lookout for small green triangles in the top left corner of the cells you’re using in the lookup. If you see these, Excel is trying to tell you it’s not sure how to handle numeric values.GREEN_TRIANGLE

Click on a cell containing the green error indicator and then hover over the error symbol to see more about the issue. If you see a warning about numbers being formatted as text, you are on the right track to resolving your error. TEXT_WARNING

4. If you’re looking at your VLOOKUP results and you see errors on all your numeric IDs and no errors on text IDs, you surely have a data type problem. In the image below, see how almost all the rows are showing an error except for the one with an ID of “sa551307”?VLOOKUP_ERROR

Fixing Your Lookup

Now that we’ve identified the problem, how do we go about fixing the data? Or fixing the lookup?

If you are lucky enough to see the green error triangle, you may be able to use Excel’s built in tools to quickly convert numbers being treated as text back to straight numeric values.

To do this, select the first item in the column with the green triangles. Then hit your SHIFT + CTRL + DOWN ARROW KEYs together. This should select the entire column. Then look for the same error warning and choose the option to “Convert to Number”. CONVERT_TO_NUMBER

Sometimes this works. But this is not the most reliable approach. You won’t always see these triangles. And it can be difficult to resolve even when you do. The best bet is to be able to force the issue by being able to convert a numeric item into text and vice versa.

Excel Formulas to Convert Numeric and Text Data

Fortunately, Excel offers formulas that let us explicitly state that we want something to be treated as a number or treated as text. I think there are more ways than one to do this, but we’re going to look at using the VALUE and TEXT functions.

VALUE

The VALUE function converts a string of text into a number. The string must be numeric in nature, but is treated as text by Excel (this just means you can’t convert the word “four” into a number, it can only convert the text “4” into a number).

The formula requires only one input, the text to be converted.

VALUE(text)

VALUE_FORMULA

text – This can be a text string in quotation marks or a reference to a cell that has the text to be converted.

An example might be a player ID like Jose Abreu’s, “15676”. If we have a feeling that “15676” is being treated as text, we can convert it to a number using the formula =VALUE(“15676”).

TEXT

The TEXT formula is the reverse of VALUE. It converts a number into a text string (assuming the string is composed of numbers). The inputs of the formula are:

TEXT(value, format_text)

  1. value – This can be a numeric value or a reference to a cell containing the numeric value.
  2. format_text – a way for you to format the value after it has been converted to a number. Examples of things you can do are to show decimal places, thousands separators (commas), dollar signs, and more.

TEXT_FORMULA

Enough Chit-Chat, Let’s Get to an Example Formula

Alright. Let’s go back to our Jose Abreu example. We’ve double-checked our formula. We’re sure he’s listed in the projections. But we’re still getting an error.

Here’s the current VLOOKUP formula (this should look familiar to you if you’ve followed one of my rankings processes before):

=VLOOKUP([@IDFANGRAPHS],STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE)

Forcing Text to be Treated as a Number

The IDFANGRAPHS column is left aligned, indicating it's text. Let's try forcing it to be a number.

The IDFANGRAPHS column is left aligned, indicating it’s text. Let’s try forcing it to be a number.

Taking a closer look at the spreadsheet, I see the IDFANGRAPHS column is left aligned. This suggests it’s being treated as text. So if we can force that to be treated as a number, it may resolve the issue. The change to the existing VLOOKUP formula is pretty simple (changes are in red):

=VLOOKUP(VALUE([@IDFANGRAPHS]),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE)

I’ve just taken the existing formula and inserted VALUE around the [@IDFANGRAPHS] information. This tells Excel to force this to be numeric.

After that edit is made, here’s the updated spreadsheet:

Many errors disappeared. The #N/A error on an obscure player probably means he's not in the Steamer Projections. But what about the #VALUE! error?

Many errors disappeared. The #N/A error on an obscure player probably means he’s not in the Steamer Projections.
But what about the #VALUE! error?

We went from 99% errors to only a few. That’s a good start.

Seeing David Adams, an obscure player, with the “#N/A” error probably just means Steamer didn’t project him.

But the “#VALUE!” error is new. This is Excel telling us that using the “VALUE” formula on a cell that’s not numeric in nature can’t be done. It can’t convert “sa551307” into a number.

Forcing an Item to Be Treated as Text

We can work around the new “#VALUE!” error with the IFERROR formula. I’ve written about this before and you may recall that IFERROR’s power is that it let’s you enter a formula (like a VLOOKUP) and if that formula results in an error, it let’s you control what happens next.

IFERROR is perfect for our situation.

We want to conduct the VLOOKUP first with our IDs being treated as numbers. And if that ends up in an error (#VALUE!), then we want to conduct the same VLOOKUP with the ID being treated as text!

So our formula becomes:

=IFERROR(VLOOKUP(VALUE([@IDFANGRAPHS]),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE),
VLOOKUP(TEXT([@IDFANGRAPHS],0),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE))

Before you freak out, this formula isn’t as bad as it looks. Remember that IFERROR can be thought of like this:

=IFERROR(Formula to evaluate,Formula to evaluate if the first one is an error>

And we’re using it this way:

=IFERROR(VLOOKUP with Numeric IDs,Same VLOOKUP but with Text IDs)

The difference is in how we treat the [@IDFANGRAPHS] piece.

To treat [@IDFANGRAPHS] as a number:

=VLOOKUP(VALUE([@IDFANGRAPHS]),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE)

To treat [@IDFANGRAPHS] as text:

=VLOOKUP(TEXT([@IDFANGRAPHS],0),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE)

Those are the EXACT same formulas except for the differences in the red font.

But We Still Have Errors!

After making that change we still have the issue of players not included in the Steamer Projections at all. We still see “#N/A” errors. But these are for the obscure players. Not because we have formula issues.

STILL_MORE_ERRORS

To resolve this, we can use IFERROR one more time. We’ll use it like this:

=IFERROR(super long IFERROR from above,0)

This means if a player isn’t found in our “super long IFERROR from above”, then we’ll just see a zero. Here’s the whole formula written out:

=IFERROR(IFERROR(VLOOKUP(VALUE([@IDFANGRAPHS]),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE),
VLOOKUP(TEXT([@IDFANGRAPHS],0),STEAMER_H,COLUMN(STEAMER_H[AB]),FALSE)),0)

You Made It!

Thanks for making it this far. If you made it to this point, you’re exactly the kind of person I’m writing all this for! I mean that.

What a screw up this turned out to be. I still love the idea of an updatable Player ID Map, so I’m not going to get rid of it. But I also realize this post just got really technical in order to solve a silly problem.

But sometimes that is what it takes. I don’t want to hold back on a topic just because it’s challenging. I’m doing this to help people that aren’t afraid of “complicated”. And in the grand scheme of things, this was probably a helpful discussion that had to be had at some point.

Thanks again for sticking with me. Hopefully you found this discussion valuable. Even if it was caused by a silly mistake.

Please Follow Me on Twitter


Now Available – The Projecting X 2.0 Bundle!

$
0
0

Projecting X 2.0 and the updated Excel template are now available!

Projecting X 2.0 and the Excel Template are now available!

Yes, that’s right. Mike Podhorzer has just released Projecting X 2.0. And I’m excited to announce an updated Projecting X Excel template has been upgraded to be more helpful than ever and has been updated to be consistent with all the new projection methodologies used in Projecting X 2.0.

What’s New in Projecting X 2.0?

While I would not consider version 2.0 to be a complete re-write of the original Projecting X, it’s certainly an improvement of the process, methods, and formulas used in the original book.

Don’t get me wrong, I love the Projecting X approach. But I did feel there were a couple of methods in the original version that I thought had room for improvement. For example, I’ve come to learn that using K% is superior to using K/9. And I thought the approach to projecting runs and RBI was too subjective.

Well, Podhorzer has addressed all of those issues, improved upon several of his methods, and even introduced new ones.

My favorite changes to the process are:

  • A much improved and more scientific methodology for projecting Runs and RBI
  • Switching from K/9 and BB/9 to K% and BB%
  • A method for projecting quality starts (I get asked about QS projections all the time!!!)
  • Addition of metrics like strike percentage (STR%), looking strikes (L/STR), and swinging strikes (S/STR) to pitcher projections, and
  • Revisions to the projection of stolen base frequency

What’s New in the Excel Template

The Excel template has been updated to be 100% consistent with all the new methodologies and formulas used in Projecting X 2.0. Take a look.

If you’re a user of the Projecting X 1.0 Excel template, the biggest improvements in the file are:

  • Addition of career stats
  • Addition of a customizable three-year weighted average
  • New team hitting and pitching totals that sum as you project
  • More league average information
  • New links to Baseball Savant, Brooks Baseball, and RosterResource.com
  • It’s now easier to add a new player to the spreadsheet
  • The Player ID Map is now easily refresh-able so that when I add new players or change player teams, this information updates in your spreadsheet too

Download the Updated Bundle Today

The updated book and spreadsheet are available for the bundled price of $17.99 (they separately sell for $9.99 each). Click the Add to Cart button below to begin the checkout process.

PDF Buy Now
MOBI (Kindle) Buy Now
EPUB (Nook, Apple iPad/iBooks, Sony Reader, Kobo) Buy Now
View Cart

Still Not Quite Sold? How About Some Screenshots?

No problem. Click on an image below to see a much larger version. The “Hitter Projections”, “Pitcher Projections”, and “Team Hitting” worksheets are shown here.

PROJECTINGX2_PITCHERS

PROJECTINGX2_HITTERS

PROJECTINX2_TEAMHITTING

This Seems Interesting, But I’d Like to Know More

Click here to read the story of how I came to find Projecting X and my review of the original book.

Order Now

PDF Buy Now
MOBI (Kindle) Buy Now
EPUB (Nook, Apple iPad/iBooks, Sony Reader, Kobo) Buy Now
View Cart

How to Get Reliable SGP Data

$
0
0

I’m an SGP guy. Standings gain points are what I first learned. The approach has been good to me. And it seems I’ve been fairly successful using the approach. But SGP has a weakness. It’s a big weakness that prevents a lot of fantasy baseball players from using the approach.

Where Can I Get Reliable SGP Data?

Where can I find historical SGP data??? This is one of the most common questions I get about the use of standings gain points. If you’re starting a new league, don’t have access to league history, or switched website providers, you’re screwed. You can’t really start using SGP. And let’s not even mention those of you that play in AL or NL-only leagues (I still don’t have an answer for that, sorry).

In this post I’ll share with you where and how you can get great quantities of actual league standings in competitive mixed leagues (again, sorry mono-leaguers, I would love to help you one day but I haven’t found out how yet).

Where Can You Find Standings Information for Competitive Leagues?

I haven’t proven the theory yet, but I’m pretty certain you could write some kind of web scraping program to pull down the standings information for public Yahoo! and ESPN leagues. But who knows what the level of competition is in those? You would have to find a way to weed out the non-competitive leagues and teams to prevent those that draft and then never change their lineup the entire season from distorting the standings information.

NFBC_LOGO

Enter the National Fantasy Baseball Championship (NFBC)

The National Fantasy Baseball Championship (NFBC) is the industry leader in premium fantasy baseball leagues. Meaning leagues that people pay an entry fee to join in an effort to win prize money.

The fact that people are paying money to enter these leagues and that prize money is at stake is the best mechanism we could hope for to ensure competitiveness. The standings information will not be tainted by schleps that draft a team and abandon in after the first week of the season.

Not only that, but the NFBC also publishes final league standings by category and makes them available to anyone! This is an SGP jackpot.

Different Types of Leagues

The NFBC has several different competitions. The two most likely to be of value to us are the “Online” and “Draft Champions” leagues. These leagues have the most entrants, so we can reduce concerns over small sample sizes. Here’s a summary of the two league types and links to the standings information for them:

NFBC League Type Standings Links Description of League
Online Overall Standings
BA, R, HR, RBI, SB
ERA, WHIP, W, K, SV
  • Standard 5×5 roto categories
  • 12 teams
  • Online 30-round draft
  • Standard 23 player lineup (14 hitters, 9 pitchers, 7 bench spots)
  • Online drafts, February through April
  • Free agency FAAB bidding proccess
  • No trading
Draft Champions Overall Standings
BA, R, HR, RBI, SB
ERA, WHIP, W, K, SV
  • Standard 5×5 roto categories
  • 15 teams
  • Online 50-round slow draft
  • Standard 23 player lineup (14 hitters, 9 pitchers, 27 bench spots)
  • Online drafts, November through April
  • Draft and hold, no free agency
  • No trading

So the big differences to note are that the “Online” leagues have 12 teams and a 30 round draft. The “Draft Champions” leagues have 15 teams and have 50-round drafts because they don’t have free agency during the season. We’ll a look at this in future posts to see if it seems to affect things.

Now That We Have This Information, What Do We Do Next?

There were 125 leagues and 1,500 teams in the 2015 Online NFBC leagues and 192 leagues and 2,880 teams in the 2015 Draft Champions leagues.

That’s a lot of data. Is there a practical way to take all of that data and use it to calculate SGP factors? Of course! (NOTE: I got the idea to do this by reading Jeff Zimmerman’s fantasy draft prep series in 2014 and 2015)

You’re Boring Me and I Don’t Want to Do This Myself

NOTE: I’m about to go through instructions how to calculate the NFBC SGP numbers yourself, but if you just want my completed analysis, you can download them here:

I may not update this information every year into the future… So remember, the instructions below will remain so you can do this yourself!

Excel Functions Used in this Post

We’ll be using the SLOPE, IF, and AVERAGEIFS formulas to calculate SGP for the NFBC leagues.

SLOPE

You can read more about the SLOPE formula in a three part series I wrote about here, here, and here.

The short description is that the SLOPE function finds the line of best fit through a given set of data points. With our rotisserie standings data, the SLOPE formula essentially calculates the actual SGP factor or denominator. I’d highly suggest reading the three part series. Or at least Part I!

IF

The IF function checks to see if a condition is met. If the condition is met, the function returns one response. If the condition is not met, the function returns another response. One important fact to realize is that the responses you specify in the IF formula can be formulas. So if the condition you specify is met, you can have the cell use formula A. And if the condition you specify is not met, you can have the cell use formula B.

The function requires three inputs:

  • Logical_Test – This is typically a formula to be evaluated. An example might be “is cell C2 greater than cell D2”.
  • Value_If_True – This is the value to be shown or the formula to be evaluated if the Logical_Test is passed,.
  • Value_If_False – This is the value to be shown or the formula to be evaluated if the Logical_Test is failed.

AVERAGEIFS

The AVERAGEIFS formula will calculate the mean of groups of cells that meet a set of conditions. You can specify multiple groups of cells and multiple conditions that must be met. The function requires three inputs (but can use more…):

  • Average_Range – These are the cells to be included in the calculation of the average
  • Criteria_Range1 – This is the first set of cells you want to be evaluated for the condition
  • Criteria1 – This is the condition that must be met for the item in the Average_Range to be included in the calculation of the average
  • If you have more conditions to be evaluated, you can continue to add pairs of Criteria_Range2 and Criteria2, Criteria_Rang3 and Criteria3, etc.

This is a little vague until I tell you more about how we will design this spreadsheet to work.

Our goal will be to design a spreadsheet containing a separate tab for each rotisserie scoring category.

ROTO_CATEGORIES

And one tab that will analyze each scoring category and calculate the average needed to finish in each place for that category. For example, this table will show what the average batting average was for each of the 15 places in an NFBC Draft Champions league.

This is what the finished spreadsheet calculating the NFBC average standings will look like.

This is what the finished spreadsheet calculating the NFBC average standings will look like.

Each cell under the roto categories will contain an AVERAGEIFS formula. For example, the table tells us that first place in the Batting Average category had an average of 0.277. The formula in this cell is set up to look on the “BA” tab for the batting average of each team (the Average_Range), then look in the “Place in League” column (the Criteria_Range1) for any rows with a “1” in them (the Criteria).

That 0.277 calculation is the average of all (and only) first place teams.

Step-By-Step Instructions to Calculate SGP for NFBC Leagues

In the instructions that follow I’ll be calculating the SGP factors from the 2015 NFBC Draft Championship standings data.

Step Description
1. Start a new Excel file and create the following tabs in the spreadsheet: “SGP Data”, “BA”, “R”, “HR”, “RBI”, “SB”, “ERA”, “W”, “WHIP”, “K”, and “SV”.TAB_NAMES
2. We’ll start by creating the area that will summarize and interpret the standings data we download from the NFBC website.

Enter the following information on the “SGP Data” tab (I listed “Rank” up to 15 because I’m using the Draft Championship in my example). SPREADSHEET_FRAMEWORKThen click once to select cell A1. And then click the “Format as Table” drop down menu and choose a desired format for the table.
FORMAT_AS_TABLEExcel should select the table we’ve created. Make sure the “My table has header” box is checked and click “OK”.TABLE_HAS_HEADERS

3. Now we’ll go to the NFBC site and copy the standings information for the various categories. Here are the links to standings information for the various categories in the NFBC Online and NFBC Draft Champion Leagues:

Online HittingBA, R, HR, RBI, SB
Online PitchingERA, WHIP, W, K, SV
Draft Champion HittingBA, R, HR, RBI, SB
Draft Champion PitchingERA, WHIP, W, K, SV

Again, I’m using the Draft Champions information.

I’ll start with the “BA” category and click the link to be taken to the NFBC page listing the BA data.

To copy the data, carefully click your mouse before the word “Rank” in the top left of the standings data. Then hold your mouse button down and drag it toward the bottom right of the table, in order to select all the information. Then right-click on a selected piece of data and “Copy” it.Copy NFBC Data

4. Return to the Excel file and click on the “BA” tab.BA_TAB

Paste the data you just copied into cell A1. But you’ll want to do a special type of paste so the formatting from the NFBC website doesn’t come over into Excel. In the right-click menu, choose the “Paste – Match Destination Formatting” menu option (or you could do a “Paste Special” and choose the “Text” option).DESTINATION_FORMATTING

Next, we will format the data as an Excel table, just as we did in step 2 above. FORMAT_TABLE

Be sure to check the “My table has headers” box.TABLE_DIMENSIONS

5. Now name the table so we can more easily refer to this data for calculation of our standings gain points data. To do this, click the “Table Tools Design” tab of the ribbon. This menu will only show up when you have selected a cell within an Excel table.TABLE_TOOLS_DESIGN

Then adjust the “Table Name” field all the way to the left side of the “Table Tools Design” tab.

Enter the name “STANDINGS_BA”.STANDINGS_BA

6. Repeat steps 3, 4, and 5 above with the other categories (R, HR, RBI, SB, ERA, WHIP, W, K, SV).

Name the tables in Excel as follows:

  • STANDINGS_R
  • STANDINGS_HR
  • STANDINGS_RBI
  • STANDINGS_SB
  • STANDINGS_ERA
  • STANDINGS_WHIP
  • STANDINGS_W
  • STANDINGS_K
  • STANDINGS_SV

7. At this point you should have ten tabs of NFBC data. One for each of the ten roto categories. If you look closely at the data, it’s sorted in such a way to rank a team among all other NFBC team in the Draft Championship league type.

But we want to sort the data in a way that will bring all teams from the same league together in the list. And we then want to sort the teams within the league in order. To do this, click the “Sort” button on the “Data” tab of the Excel ribbon.DATA_SORT

Adjust the “Sort” dialog box as shown in the image below. We will first sort by “League” in order to bring all teams from the same league to be next to each other in the list. We will then sort by “Rank” in ascending order. This will put the top teams to the top of each league.SORT_BY

8. The sort also has the side effect of moving co-managers down to the bottom of the list (some NFBC teams are owned or managed by more than one person). These names fall to the bottom because co-managers are listed below the first manager and no other standings data appears on these rows. BLANK_CLIPBOARD

Remove these rows by clicking your mouse on the row numbers to the left of column A. Hold the left mouse button down and drag it to select all of the rows containing co-manager names (in my NFBC Draft Championship data I had to delete from row 2,882 to row 3,061.SELECTED_ROWS

After you have selected the rows to delete, right-click within the selected rows and choose the “Delete” menu option.DELETE_ROWS

Perform this step on each tab of standings data (BA, R, HR, RBI, SB, ERA, WHIP, W, K, SV).

9. Return to the “BA” tab.

If you look closely at the sorted data for each category, you should notice we’re missing an important piece of information. The sorting brought all teams in the same league next to each other. And then it put the teams in order of finish within that category. But it would be helpful to see a column showing “place in the league”.

After sorting, all teams in the same league are grouped together. And they're listed in order of finish within the category.

After sorting, all teams in the same league are grouped together. And they’re listed in order of finish within the category.

To add this column, type “PLACE” at the top of column G.PLACE

After you hit enter, the column should automatically become part of the table.PLACE_TABLE

Now enter the following formula in cell G2:

=IF(D2=D1,G1+1,1)

Let’s look at what this is doing.

FORMULA

In plain English, if cell D2 is equal to D1 (if this row relates to the same league as the row above), add one to the row above (in column G). If this row does NOT relate to the same league (if this is the first team listed for the next league), return a “1”.

Select or click on cell G2 once again. Copy this formula to all rows in the table by double-clicking on the small square in the corner of cell G2.
BLACK_BOX

You should see that this “PLACE” column is properly ranking the teams within each league. Once the list of teams reaches another league, the “PLACE” column starts over at “1”.NEW_LEAGUE

10. Repeat step 9, adding the “PLACE” column, for all of the other category tabs.
11. Now comes the fun part. Go to the “SGP Data” tab and select cell C2, the cell representing first place in the BA category.

We’re about to use the AVERAGEIFS formula to calculate the average BA for all first place teams in this NFBC competition. Type the following into the cell (keep reading to the end of this step for a tip on how to enter formulas like these):

=AVERAGEIFS(STANDINGS_BA[BA],STANDINGS_BA[PLACE],[@RANK])

Or this is the same as:

=AVERAGEIFS(STANDINGS_BA[BA],STANDINGS_BA[PLACE],A2)

Think back to the three inputs to the AVERAGEIFS function. The first is the Average_Range. In this example we want to take the average of items in the “BA” column of the “STANDINGS_BA” table.

The second argument is the CRITERIA_RANGE1, or the column we want to test for meeting a certain rule. In this example we want only want first place teams, as indicated in the “PLACE” column of the “STANDINGS_BA” table.

And the third argument is “CRITERIA1”, or the rule we want to test CRITERIA_RANGE1 for. The “[@RANK]” reference tells Excel to look in the “RANK” column for this current row that’s selected. In this case, that’s a “1”.

All of this means that any batting average on the “STANDINGS_BA” tab will be included in our calculation if there is a “1” in the “PLACE” column.

The formulas for the R, HR, RBI, SB, ERA, WHIP, W, K, and SV categories are as follows:

  • =AVERAGEIFS(STANDINGS_R[R],STANDINGS_R[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_HR[HR],STANDINGS_HR[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_RBI[RBI],STANDINGS_RBI[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_SB[SB],STANDINGS_SB[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_ERA[ERA],STANDINGS_ERA[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_WHIP[WHIP],STANDINGS_WHIP[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_W[W],STANDINGS_W[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_K[K],STANDINGS_K[PLACE],[@RANK])
  • =AVERAGEIFS(STANDINGS_SV[SV],STANDINGS_SV[PLACE],[@RANK])

Enter these formulas into row two of the applicable column. Then select the cells shown below and drag the formulas down to the rows below.COPY_FORMULAS

Excel Tip – One of the main benefits of using Excel tables is that Excel will recognize the names of these as you are typing in formulas. Watch the animation below for an example. When you type “STANDINGS_” into a formula, Excel should list out all the standings tables in the Excel file. To select one, hit “Tab”.

Once you’ve selected a table (e.g. “STANDINGS_BA”) and type in an open bracket, “[“, Excel will list out all the columns within that table. You can then use your arrow keys to cycle up or down the list. And hit “Tab” to select one.AVERAGEIFSwCALLOUT

12. Spend a minute formatting the cells in the stat category columnns (e.g. show three decimals in the BA column, and show two (or none) in the other columns. Review your data to make sure it makes sense. You should see the categories descending (or increasing for ERA and WHIP) as the “RANK” changes. ROTO_AVERAGES
13. These averages would be useful by themselves, But let’s finish this project by determining what the SGP denominators/factors should be.

Type “SGP Calc” in a cell below the standings information (you’ll want to be at least two rows below the data so this information isn’t pulled into the table itself). SGP_CALC

14. Enter the following formula in that same row but below the “BA” column:

=SLOPE(C2:C16,$B$2:$B$16)

This is the SLOPE formula, mentioned above, that calculates the line of best fit based on all the standings information in the table above. The result of this calculation is your SGP factor/denominator!

That formula is setup so it can easily be dragged to the right and applied to all the other roto categories.COPY_FORMULAS_2

And you should now have a finished product showing that average standings for all the NFBC leagues AND the SGP factors associated with those standings!FINAL SGP FACTORS

Example Files to Download

If you’ve made it this far and don’t want to go scouring back up this post for the other example files I’ve created, here you are:

What Does All Of This Data Mean?

We just unearthed a great deal of data. If you’re like me, this seems valuable, but you’re probably full of questions at this point.

“Where do we go from here?”

“Why the eff don’t my SGP factors look like those ones?”

“Can I use these? They seem more reliable than the data I have from my league that’s only been around two years.”

“What if I play in a 13-team league?”

So stay tuned! I have plans to dive into this data and answer questions like these as we continue to prepare for the 2016 season.

If you have a specific question you’d like addressed, please leave it in the comment area below

Please Do Me a Favor!

If you found this article helpful and would like to see more like it, please do something to support the site.

This can be something simple and free, like following me on Twitter.

Or you can register for the site using the sign up box below (I won’t share your e-mail with anyone and I rarely e-mail more than once a month).

Or if you liked this post, you may like my book, “Using Standings Gain Points to Rank and Value Fantasy Baseball Players“.

Alright. Enough pandering…

Thanks for reading. Stay smart.

Player ID Map Updated for 2016-17 Offseason

$
0
0

It’s been awhile. But, yes, I’m still alive! And if you’re like me and itching to start thinking about and preparing for next season, you’ll be excited to know the SFBB Player ID Map has been updated.

The update includes additions of many players that entered the major leagues during the 2016 season as well as players projected to be impactful for the upcoming 2017 season.

In addition, players’ teams listed in the spreadsheet are updated for all transactions that occurred through December 6th. Finally, player positions have been updated to reflect games played during 2016. The position listed reflects the “most valuable position” played (if a player qualified at catcher and first base, he’s listed as a catcher).

You can download the updated map here.

Or you can view a web version here.

A complete list of changes can be viewed here or on the “Change Log” tab of the spreadsheet.2017updates

If you’re new to the site, consider checking out these past posts that illustrate some interesting things you can do with player IDs.

Please let me know if I’ve missed anyone (you can use Twitter to do that). Stay smart.

Start Preparing for the 2017 Season!

$
0
0

It’s time! Are you getting the itch to start thinking about fantasy baseball again? Are ready to take on a new challenge this year and calculate your own rankings or create your own projections? All spreadsheet templates have been updated for the upcoming 2017 season. Take a look at the available books and tools below.

Title Description
Bundle Image The Projecting X 2.0 Bundle
***UPDATED for 2017***

The Projecting X 2.0 Bundle comes with Mike Podhorzer’s instructional guide to creating your own baseball projections, as well as an accompanying Excel template to help save you hours and hours of time as you work through the projection process.

The Projecting X 2.0 Excel Template Only
***UPDATED for 2017***

(NOTE: the Excel template requires you to enter certain formulas from the book, Projecting X 2.0. If you purchased the bundle prior to the 2016 season, this is being offered to save you the time of having to manually update the player names, teams, and positions in the spreadsheet in order to start projecting the 2017 season.)

AGGREGATOR Projection Aggregator
***UPDATED for 2017***

An easy-to-use Excel spreadsheet that can combine (or average) up to three different projection sets. The aggregator can use just about any well known projection set you can find on the web (if you find one that doesn’t work, let me know!). Simply download your favorite projection sets, fill out some settings, and you’re done. No complicated formulas or VLOOKUPS for you to add.

Using Standings Gain Points to Rank and Value Fantasy Baseball Players

Ever wanted to create your own rotisserie rankings? This is my instructional guide written specifically to show you how to create customized rotisserie player rankings, dollar values, and inflation dollar values, in Microsoft Excel, tailored to your own league. No more downloading rankings from the web, hoping they apply to your unique league. 10, 12, or 15-team league? $260 or $300 budget? AL-only or mixed league? 10 hitters or 14? It doesn’t matter. This book will guide you through the process of developing rankings for just about any kind of rotisserie league.

How to Rank and Value Fantasy Baseball Players for Points Leagues

My step-by-step guide to building custom rankings, dollar values, and inflation dollar values, in Microsoft Excel, for your points league. This book will guide you through the process of developing rankings for just about any point-based scoring format.

Have Small Parts of Your Projecting X 2.0 Spreadsheet Stopped Working?

$
0
0

There were some big waves in the nerdy baseball world (I’m a proud card-carrying member) last week, when Baseball-Reference.com released a redesigned website. While the improvements are very nice, especially on a mobile device, the unfortunately broke the link to the Projecting X 2.0 spreadsheet.

Unfortunately, the newly designed site doesn’t seem to allow for the web querying function that was used to extract several of the pieces of information necessary to project pitcher stats. Because of this, we’ll have to make a few small edits to your spreadsheet that will allow you to link directly to the player you are projecting so that you’re taken right to the table containing the desired information (if we can’t pull it into the file, we’ll create a link that takes you right to where the information is located).

What follows are instructions that will help create these helpful hyperlinks and add them to your spreadsheet.


Step Description
1. To start with, we’ll delete some information on the top of the “Pitcher Projections” tab. We’ll remove anything we no longer expect to pull in automatically. The ranges of cells to be deleted are:
  • IP/GS – Delete the formulas from cells H5 through H9.IPperGS
  • QS – Delete the formulas from cells M5 through M10 (yes, this one can go to row 10!).QSCELLS
  • STR% – Delete the formulas from cells AA5 through AA9.
  • L/STR – Delete the formulas from cells AB5 through AB9.
  • S/STR – Delete the formulas from cells AC5 through AC9.
  • F/STR – Delete the formulas from cells AD5 through AD9.StrikeMeasures
2. As you might have guessed, I’m a little uptight about the appearance of my spreadsheets.

I think it’s important to convey where you are expected to type or enter data into a spreadsheet. And since we can no longer pull in the information above automatically, if you want averages calculated for you, you’ll need to input those measures.

Accordingly, we should shade the cells from above in the same yellow color our other input cells are shaded.

To do this, first click on cell G33 (this should be the “IP S” cell for the first pitcher in the list). Then click the “Format Painter” button on the “Home” tab of the Excel ribbon. FormatPainter

Afterwards, click and hold your mouse button in order to select cells H5 through H9. YellowShadedCells

We’ll now format the QS area. Click to select cell N33 (this should be the “SV” cell for the first pitcher in the list). Then click the “Format Painter”. Then hold your mouse button down and click to select from cell M5 all the way to cell M10.

Then, click once on cell AA33 (this should be the “STR%” cell for the first pitcher). Click the “Format Painter”. Then hold the mouse down and click to select from cell AA5 all the way down to AE9 (this should cover from the top STR% cell to the bottom I/STR cell).Selected Area

3. Now we’ll add hyperlinks that will take us to the selected pitcher’s “Starting Pitching” data (for IP/GS and QS) and their “Pitch Summary” data (for the STR%, L/STR, S/STR, and F/STR.

Copy the following formula, select cell H4, delete the current contents, hit F2, then paste this formula:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_starter::none","IP/GS")

Copy the following formula, select cell M4, delete the current contents, hit F2, then paste this:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_starter::none","QS")

Copy the following formula, select cell AA4, delete the current contents, hit F2, then paste this:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_pitches::none","STR%")

Copy the following formula, select cell AB4, delete the current contents, hit F2, then paste this:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_pitches::none","L/STR")

Copy the following formula, select cell AC4, delete the current contents, hit F2, then paste this:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_pitches::none","S/STR")

Copy the following formula, select cell AD4, delete the current contents, hit F2, then paste this:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_pitches::none","F/STR")

Copy the following formula, select cell AE4, delete the current contents, hit F2, then paste this:
=HYPERLINK("http://www.baseball-reference.com/players/"&LEFT(INDEX(
PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(PLAYERIDMAP[BREFID])
,1))&"/"&INDEX(PLAYERIDMAP,MATCH($B$2,PLAYERIDMAP[IDFANGRAPHS],0),COLUMN(
PLAYERIDMAP[BREFID]))&"-pitch.shtml#pitching_pitches::none","I/STR")

4. That completes the setup. When you go to project a pitcher, you can click on these newly created links to be taken directly to the appropriate spot on the player’s Baseball-Reference page.

It gets manual at this point, but you can type in the last three years or all five years of data, depending on the approach you’ve decided to use for making your projection (three-year vs. looking at all five years of data).

Any Other Suggestions to Make the Process Faster?

I do have one more thing to consider. It’s unfortunate to have to suggest this, but instead of projecting each of the individual components of Mike Podhorzer’s xK%, you could just project K%. This could save you a significant amount of time over the course of projecting 100+ pitchers.

If you have any suggestions or would like to share tips on how you’ve worked around this new issue, please let us know in the comments below.

Thanks. Stay smart.

Viewing all 59 articles
Browse latest View live