The 2018 edition of Commonwealth games are on for a week now. Both of my homes – India and New Zealand have done so well. Naturally, I wanted to gather games data and make something fun and creative from it. Here is my attempt to amuse you on this Friday.

Looks interesting? Want to know how to make something like this on your own? Then read on…
1. Gather data thru live connection to gc2018.com
We want to set up a refreshable visualization. So the data will be fetched thru PowerQuery. All we need to know about medal standings, medalists and country participation data is available at gc2018.com website.
Latest Medal Standings: This is available at https://results.gc2018.com/en/all-sports/medal-standings.htm page as an HTML table (the first table on the page).
So we can get the data using below M:
= Web.Page(Web.Contents("https://results.gc2018.com/en/all-sports/medal-standings.htm")){0}[Data]
This is extracting data column of first row of the Web.Page.
Number of participants by country: There is no one page where this information is available. Instead you need to visit each country’s page on gc2018.com to get the data from participants table. For example, the page for Bermuda (available at https://results.gc2018.com/en/all-sports/entries-bermuda.htm) looks like this:

Fortunately, all URLs follow the same pattern. https://results.gc2018.com/en/all-sports/entries-<country name>.htm
So given a URL in column [URL], we can use this custom column formula to get the total number of participants.
=Table.SelectRows(Web.Page(Web.Contents([URL])){0}[Data], each ([Discipline] = "Total")))
This is extracting the first table on URL and then filtering it for Total Row.
Arranging everything in one table:
We can use a bit of built-in operations in Power Query to arrange all the necessary data in one tidy table. I am not going to explain all steps, but here is the final output. Try to come up with this on your own.

Now that our medal data is in Excel, in a table named medal_standings, let’s go ahead to next step.
2. Calculations to show medal standings by any criteria
The calculation engine for our little medal standings has few key things:
- Fetching and sorting by a column
- Slicer selection for sort options (Gold, Silver, Bronze, Total Medals, M/P)
Let’s go thru them:
Fetching and sorting by a column:
We would like to see countries by Gold, Silver, Bronze, Total medals and Medals per participant.
As per our medal_standings table, these are 3,4,5,6 and 9 respectively.
Assuming the column we want to sort is given by a named range – sort.option.num, we can use INDEX formula to fetch values, like this:
=IFERROR(INDEX(medal_standings,<row number>,sort.option.num),-10)
The -10 ensures that if we poll for a row that doesn’t exit, we get a negative value rather than 0. As some countries have 0 medals, having negative ensures that when sorting such rows are always at bottom.
Once we fetch a column, you can use LARGE() to re-order them top to bottom.
As there will be ties (few countries getting same number of medals), we can use de-duplication logic. This is when you add a very small unique fraction to each row before calling LARGE(). It is an elegant way to deal with ties and overcome Excel’s lookup formula limitations of returning only first match. See this decade old post by Robert discussing deduplication technique.
After this, just re-arrange original data (only columns needed for output) using another set of INDEX formulas.
A slicer to allow user to pick sort option
Now let’s just link up sort.option.num to a slicer so user can tell calculation engine what the sort order should be.
Start by making a pivot from a range like this:

But when you add a slicer on sort option, you realize the folly of your plan. The slicer buttons are out of order.

Technically, they are in order – alphabetical. But that is not what we want. We want them in the order – Gold, Silver, Bronze, Total Medals and M/P.
So what now?
Simple, we can ask Jackie Chan to karate chop the slicer and re-arrange it.
Alas, my summonJackie() macro was subscript out of ranging. So we need something else.
So we cheat Excel. We can pre-fix empty spaces – CHAR(129) to the slicer items. Since these are empty spaces, we just add 1 space for Gold, 2 for Silver etc. and make a slicer from these new values.
Note: In Power BI, you can simply order the sort option column by index number and that will fix the slicer problem. In fact, we wouldn’t bother with a slicer as Power BI tables are sortable by clicking on header.
That is better. Now simply style it and give it a buzz cut and you get this.

Related: Comprehensive guide and tutorial on all things Slicer – MUST READ
3. Preparing the viz
Now that everything we need is ready, simply bring calculated table to a blank worksheet (using Copy, Paste links) and arrange it in a neat table. Add Conditional formatting > Databars on medal and M/P columns. Position slicer neatly where these columns headers should be and you are gold.
Every now and then press Ctrl+Alt+F5 and go make a cuppa. When you are back, the medal table would be updated. Of course, come 16th of April 2018, there is no need to refresh it as the games would have ended.
Download the Commonwealth 2018 games medal tracker
Click here to download the Excel file. Play with it to learn more. Examine the query definition, control sheet and viz sheet to understand how it is put together. Make changes to the query (but duplicate it first, otherwise you will break the calculations) to fetch other data and make your own charts.
Ways to enhance this – adding past performance etc.
You can use the data from https://thecgf.com/ (Commonwealth Games Federation) to see historical performance and contestant data. They do not yet have 2018 values (as the games are ongoing) but you can see how countries have done in 2014 or 2010. Or you could combine this with performance in Olympics. How about combining this with demographic and well-being data (Gini scores or HDI ranks)? There are several ways you can mash-up this.
Love Games and Excel? Check out these visualizations
Me too. I like sport and I like data. Guess what, I build a lot of charts and cool visualizations on sport. Check out below and have fun.
- Roger Federer’s wimbledon win – Visualized
- Sachin Tendulkar’s cricketing awesomeness in one chart
- MLB Pitching Stats Dashboard in Excel+VBA
- Excel steeplechase keyboard shortcuts game
Want to learn how to build awesome worksheets – Check out 50 ways to analyze data course
If you liked this, you are going to love our 50 ways to analyze data online class. This program helps you analyze and visualize business data in myriad ways. Learn all about statistical analysis, financial analysis, analytical modeling, data sciency stuff (clustering, outlier detection, optimization etc.) from the comfort of your office or home. Next batch enrollments will begin soon.
Visit 50 ways course page to know more and join the waiting list.














15 Responses to “Modeling Interest During Construction (IDC) – Excel Project Finance”
Thanks again for a very helpful post.
I had a similar problem when trying to model a balance sheet and profit and loss projection. The problem was that interest expense (in P&L) was dependent on a cash shortfall (in BS) which had to be funded. The cash shortfall depended on how much interest was paid, so the mutual dependency made a circular reference.
I addressed it with a macro that calculated interest outside of the P&L, then pasted the calculated amount into the P&L as a value. The model was out of balance, but by repeating the pasting and calculating loop the imbalance reduced to zero. It was a bit messy, and had to be repeated every time a line changed - but it worked.
If I have to do it again I'll read this article again first and see if it can be done more elegantly.
Hi,
The use of a circular reference can be avoided in this case. Just make use of the geometric sum to calculate the interest required. I’ll walk through the example from the spreadsheet.
First calculate the cash needed each year without the interest expense. So you year 1 you need 55 Mn, year 2 105 Mn, and 190 Mn for year 3. The total amount to borrow for year 1 is then (50 Mn)/(1-interest_rate) = (50)/(1-0.1). For years 2 and subsequent the amount borrowed is the cash needed in that year plus the interest_rate times the amount already borrowed. For year 2 (105 + interest_rate * sum(previous debt raised))/(1-interest_rate)=(105+0.1*61.1)/(1-0.1).
This process avoids the need for a circular reference, and makes the calculation more stable.
Thanks,
Tristan
The question is for the year 1 in your case, the amount works out to 45 mn. However in the year 2 you have applied the loan amount as 61.1 mn.
Am I missing something ! Please help !
very helpful information!!!
using circular references and to make model more stable we can use combination of "IF" and "ISERROR" functions. i.e
=if(iserror(formula1),"",(formula1))
this formula will return blank value if there is any error otherwise give the result required.
I usually use this in my models and it makes them very stable......
🙂 🙂 🙂
@Terry: Thats right. Exactly same problem is seen in Interest - Cash cycle in P&L and Cash Flow statement as well. In our trainings on financial modeling in excel, we demonstrate using both the circular loops as well as the macros to take care of this problem. Circular loops have their own pitfalls. If the model enters into a state of error, the error percolates!
@Tristan: Thanks for pointing out. I agree with you that if circular loops can be avoided, they should be avoided.
@Yogesh: This is one way of avoiding the problem. Although circular loops have another problem that they make your sheet slower. Each time, there is a change in the sheet, all the calculations are redone. So if they can be avoided, they should be avoided.
Please note that this was an example (a large one indeed) and I didn't have space to speak about the pitfalls of this approach! I just wanted to illustrate an approach and am glad that some of you found it useful!
I think while posting, there is an error in the images! The last image should be flipped with the one that is posted in step VII!
I think you can try the following simple solution given by Microsoft itself to make the circular works:
Windows: Excel Options -> Formulas -> Put a tick on "Enable iterative calculation"
Mac: Excel -> Preference -> Calculation ->Put a tick on "Limit iteration"
You can change the maximum number of calculation iterations as well as the maximum changes which iteration stops for goal seeking or for resolving circular references based on the number you type in the maximum change box.
Thank you.
Hey All
I heard that we can take care of the circularity with the help of macro for IDC. Can anybody help on the steps to construct the macro for the same.
Regards
Vinay
Hi Vinay,
If you look closely, you are essentially copying the values from the interest calculation to the IDC in project cost.
Basically you can record a macro, that takes the values from interest and pastes special the values in IDC row in project cost.
Then you can run that recorded code in a for loop.
Hope this helps.
Thanks Param for reply.
But before calculating interest, i need to provide for Upfront Equity and Equity, which are essentially part of total project cost. Hence, i need to put in Upfront Equity and Equity to calculate the IDC which is again hitting the total project cost.
Bit of confused on how to remove this circular reference.
Regards
Vinay
Wow, this was a brilliantly simple post. I was looking online for a while before I found this page. Never seen this been explained so beautifully yet so crisply before. Thanks for saving my ass at work! (i'm relatively new to finance + modeling)
I'm not sure why but this web site is loading very slow for
me. Is anyone else having this issue or is it a problem on my end?
I'll check back later and see if the problem still exists.
[…] Project Finance Modeling using Excel – Part 1 & Part 2 […]
I have been reading your blog since my college days. Today, I'm writing just to say thanks.
We have calculated Financial Rate of return of a hydropower projects, and the observer has raised an observation regarding Total Project cost with IDC Rs. 8616.01 million (PKR) and with-out IDC 8352.46 million (PKR). How does the Financial nalysis be calculated on the basis of with-out IDC Or With IDC?????
Please helpf. if possible to spare some time.