Searching for Balance Sheet Calculations with the Sep 2013 CTP

I have been working with a Gepsio user who is interested in finding balance sheet information for the Target Corporation 10-K posted at http://www.sec.gov/Archives/edgar/data/27419/000104746913003100/0001047469-13-003100-index.htm. The user wrote:

 “I am looking at the CosolidatedStatementOfFinancialPositionUnaudited, and I am trying to get all of the fields used in the _cal.xml file for Balance Sheet (or CosolidatedStatementOfFinancialPositionUnaudited).  This “role” has all of the fields used to calc the balance sheet, and calculationArc tells me what heading the field is under (i.e. AssetsCurrent, InventoryNet, StockholderEquity).  It also holds the names of the field tgt_AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax that is not a standard GAAP field.”

The BalanceSheet role type is defined in the schema for the 10-K:

<link:roleType roleURI="http://www.target.com/role/BalanceSheet" id="BalanceSheet">
    <link:definition>0030 - Statement - Consolidated Statements of Financial Position</link:definition>
    <link:usedOn>link:presentationLink</link:usedOn>
    <link:usedOn>link:calculationLink</link:usedOn>
    <link:usedOn>link:definitionLink</link:usedOn>
</link:roleType>

The role has a URI of “http://www.target.com/role/BalanceSheet”, which is also referenced in the calculation link through the calculation link’s “role” attribute:

<link:calculationLink xlink:type="extended" xlink:role="http://www.target.com/role/BalanceSheet">
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_Assets" xlink:label="Assets" xlink:title="Assets" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_AssetsCurrent" xlink:label="AssetsCurrent" xlink:title="AssetsCurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="Assets" xlink:to="AssetsCurrent" xlink:title="calculation: Assets to AssetsCurrent" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_CashCashEquivalentsAndShortTermInvestments" xlink:label="CashCashEquivalentsAndShortTermInvestments" xlink:title="CashCashEquivalentsAndShortTermInvestments" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="AssetsCurrent" xlink:to="CashCashEquivalentsAndShortTermInvestments" xlink:title="calculation: AssetsCurrent to CashCashEquivalentsAndShortTermInvestments" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_LoansHeldForSaleConsumerCreditCard" xlink:label="LoansHeldForSaleConsumerCreditCard" xlink:title="LoansHeldForSaleConsumerCreditCard" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="AssetsCurrent" xlink:to="LoansHeldForSaleConsumerCreditCard" xlink:title="calculation: AssetsCurrent to LoansHeldForSaleConsumerCreditCard" use="optional" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_NotesReceivableNet" xlink:label="NotesReceivableNet" xlink:title="NotesReceivableNet" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="AssetsCurrent" xlink:to="NotesReceivableNet" xlink:title="calculation: AssetsCurrent to NotesReceivableNet" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_InventoryNet" xlink:label="InventoryNet" xlink:title="InventoryNet" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="AssetsCurrent" xlink:to="InventoryNet" xlink:title="calculation: AssetsCurrent to InventoryNet" order="4.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_OtherAssetsCurrent" xlink:label="OtherAssetsCurrent" xlink:title="OtherAssetsCurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="AssetsCurrent" xlink:to="OtherAssetsCurrent" xlink:title="calculation: AssetsCurrent to OtherAssetsCurrent" order="5.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_PropertyPlantAndEquipmentNet" xlink:label="PropertyPlantAndEquipmentNet" xlink:title="PropertyPlantAndEquipmentNet" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="Assets" xlink:to="PropertyPlantAndEquipmentNet" xlink:title="calculation: Assets to PropertyPlantAndEquipmentNet" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_Land" xlink:label="Land" xlink:title="Land" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="PropertyPlantAndEquipmentNet" xlink:to="Land" xlink:title="calculation: PropertyPlantAndEquipmentNet to Land" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_BuildingsAndImprovementsGross" xlink:label="BuildingsAndImprovementsGross" xlink:title="BuildingsAndImprovementsGross" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="PropertyPlantAndEquipmentNet" xlink:to="BuildingsAndImprovementsGross" xlink:title="calculation: PropertyPlantAndEquipmentNet to BuildingsAndImprovementsGross" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_FurnitureAndFixturesGross" xlink:label="FurnitureAndFixturesGross" xlink:title="FurnitureAndFixturesGross" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="PropertyPlantAndEquipmentNet" xlink:to="FurnitureAndFixturesGross" xlink:title="calculation: PropertyPlantAndEquipmentNet to FurnitureAndFixturesGross" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_CapitalizedComputerSoftwareGross" xlink:label="CapitalizedComputerSoftwareGross" xlink:title="CapitalizedComputerSoftwareGross" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="PropertyPlantAndEquipmentNet" xlink:to="CapitalizedComputerSoftwareGross" xlink:title="calculation: PropertyPlantAndEquipmentNet to CapitalizedComputerSoftwareGross" use="optional" order="4.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_ConstructionInProgressGross" xlink:label="ConstructionInProgressGross" xlink:title="ConstructionInProgressGross" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="PropertyPlantAndEquipmentNet" xlink:to="ConstructionInProgressGross" xlink:title="calculation: PropertyPlantAndEquipmentNet to ConstructionInProgressGross" order="5.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_AccumulatedDepreciationDepletionAndAmortizationPropertyPlantAndEquipment" xlink:label="AccumulatedDepreciationDepletionAndAmortizationPropertyPlantAndEquipment" xlink:title="AccumulatedDepreciationDepletionAndAmortizationPropertyPlantAndEquipment" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="PropertyPlantAndEquipmentNet" xlink:to="AccumulatedDepreciationDepletionAndAmortizationPropertyPlantAndEquipment" xlink:title="calculation: PropertyPlantAndEquipmentNet to AccumulatedDepreciationDepletionAndAmortizationPropertyPlantAndEquipment" order="6.0" weight="-1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_OtherAssetsNoncurrent" xlink:label="OtherAssetsNoncurrent" xlink:title="OtherAssetsNoncurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="Assets" xlink:to="OtherAssetsNoncurrent" xlink:title="calculation: Assets to OtherAssetsNoncurrent" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_LiabilitiesAndStockholdersEquity" xlink:label="LiabilitiesAndStockholdersEquity" xlink:title="LiabilitiesAndStockholdersEquity" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_LiabilitiesCurrent" xlink:label="LiabilitiesCurrent" xlink:title="LiabilitiesCurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesAndStockholdersEquity" xlink:to="LiabilitiesCurrent" xlink:title="calculation: LiabilitiesAndStockholdersEquity to LiabilitiesCurrent" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_AccountsPayableCurrent" xlink:label="AccountsPayableCurrent" xlink:title="AccountsPayableCurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesCurrent" xlink:to="AccountsPayableCurrent" xlink:title="calculation: LiabilitiesCurrent to AccountsPayableCurrent" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_AccruedLiabilitiesCurrent" xlink:label="AccruedLiabilitiesCurrent" xlink:title="AccruedLiabilitiesCurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesCurrent" xlink:to="AccruedLiabilitiesCurrent" xlink:title="calculation: LiabilitiesCurrent to AccruedLiabilitiesCurrent" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_OtherShortTermBorrowings" xlink:label="OtherShortTermBorrowings" xlink:title="OtherShortTermBorrowings" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesCurrent" xlink:to="OtherShortTermBorrowings" xlink:title="calculation: LiabilitiesCurrent to OtherShortTermBorrowings" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_SecuredDebtCurrent" xlink:label="SecuredDebtCurrent" xlink:title="SecuredDebtCurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesCurrent" xlink:to="SecuredDebtCurrent" xlink:title="calculation: LiabilitiesCurrent to SecuredDebtCurrent" use="optional" order="4.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_LiabilitiesNoncurrent" xlink:label="LiabilitiesNoncurrent" xlink:title="LiabilitiesNoncurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesAndStockholdersEquity" xlink:to="LiabilitiesNoncurrent" xlink:title="calculation: LiabilitiesAndStockholdersEquity to LiabilitiesNoncurrent" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_UnsecuredLongTermDebt" xlink:label="UnsecuredLongTermDebt" xlink:title="UnsecuredLongTermDebt" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesNoncurrent" xlink:to="UnsecuredLongTermDebt" xlink:title="calculation: LiabilitiesNoncurrent to UnsecuredLongTermDebt" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_SecuredDebtOther" xlink:label="SecuredDebtOther" xlink:title="SecuredDebtOther" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesNoncurrent" xlink:to="SecuredDebtOther" xlink:title="calculation: LiabilitiesNoncurrent to SecuredDebtOther" use="optional" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_DeferredTaxLiabilitiesNoncurrent" xlink:label="DeferredTaxLiabilitiesNoncurrent" xlink:title="DeferredTaxLiabilitiesNoncurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesNoncurrent" xlink:to="DeferredTaxLiabilitiesNoncurrent" xlink:title="calculation: LiabilitiesNoncurrent to DeferredTaxLiabilitiesNoncurrent" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_OtherLiabilitiesNoncurrent" xlink:label="OtherLiabilitiesNoncurrent" xlink:title="OtherLiabilitiesNoncurrent" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesNoncurrent" xlink:to="OtherLiabilitiesNoncurrent" xlink:title="calculation: LiabilitiesNoncurrent to OtherLiabilitiesNoncurrent" order="4.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_StockholdersEquity" xlink:label="StockholdersEquity" xlink:title="StockholdersEquity" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="LiabilitiesAndStockholdersEquity" xlink:to="StockholdersEquity" xlink:title="calculation: LiabilitiesAndStockholdersEquity to StockholdersEquity" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_CommonStockValue" xlink:label="CommonStockValue" xlink:title="CommonStockValue" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="StockholdersEquity" xlink:to="CommonStockValue" xlink:title="calculation: StockholdersEquity to CommonStockValue" use="optional" order="1.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_AdditionalPaidInCapitalCommonStock" xlink:label="AdditionalPaidInCapitalCommonStock" xlink:title="AdditionalPaidInCapitalCommonStock" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="StockholdersEquity" xlink:to="AdditionalPaidInCapitalCommonStock" xlink:title="calculation: StockholdersEquity to AdditionalPaidInCapitalCommonStock" use="optional" order="2.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_RetainedEarningsAccumulatedDeficit" xlink:label="RetainedEarningsAccumulatedDeficit" xlink:title="RetainedEarningsAccumulatedDeficit" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="StockholdersEquity" xlink:to="RetainedEarningsAccumulatedDeficit" xlink:title="calculation: StockholdersEquity to RetainedEarningsAccumulatedDeficit" use="optional" order="3.0" weight="1" />
  <link:loc xlink:type="locator" xlink:href="http://xbrl.fasb.org/us-gaap/2012/elts/us-gaap-2012-01-31.xsd#us-gaap_AccumulatedOtherComprehensiveIncomeLossDefinedBenefitPensionAndOtherPostretirementPlansNetOfTax" xlink:label="AccumulatedOtherComprehensiveIncomeLossDefinedBenefitPensionAndOtherPostretirementPlansNetOfTax" xlink:title="AccumulatedOtherComprehensiveIncomeLossDefinedBenefitPensionAndOtherPostretirementPlansNetOfTax" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="StockholdersEquity" xlink:to="AccumulatedOtherComprehensiveIncomeLossDefinedBenefitPensionAndOtherPostretirementPlansNetOfTax" xlink:title="calculation: StockholdersEquity to AccumulatedOtherComprehensiveIncomeLossDefinedBenefitPensionAndOtherPostretirementPlansNetOfTax" use="optional" order="4.0" weight="-1" />
  <link:loc xlink:type="locator" xlink:href="tgt-20130202.xsd#tgt_AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax" xlink:label="AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax" xlink:title="AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax" />
  <link:calculationArc xlink:type="arc" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item" xlink:from="StockholdersEquity" xlink:to="AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax" xlink:title="calculation: StockholdersEquity to AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax" use="optional" order="5.0" weight="1" />
</link:calculationLink>

This data path should answer the user’s question from an XBRL perspective. How can all of this data be accessed by Gepsio? Two things need to happen here:

  1. Use Gepsio to find the correct role type
  2. Use Gepsio to find the calculation links

Finding Role Type Information Using Gepsio

Gepsio includes a class called RoleType, which defines all of the properties of a role type found in a schema. The RoleType class includes the following properties:

  • Definition: The definition of this role type.
  • Id: The ID of this role type.
  • RoleUri: The URI for this role.
  • Schema: The schema that references this role type.
  • UsedOnReferences: A collection of “UsedOn” references for this role type. Used to identify what elements may use a taxonomy defined role or arc role value.

In Gepsio, RoleType objects are available as a collection in a schema. Schemas are available as a collection in an XBRL fragment, and XBRL fragments are available as a collection in an XBRL document. Given that chain of objects, code can be written to find a role type object given its ID:

private RoleType GetRoleTypeById(XbrlDocument xbrlDoc, string roleTypeId)
{
    foreach(var currentFragment in xbrlDoc.XbrlFragments)
    {
        foreach(var currentSchema in currentFragment.Schemas)
        {
            foreach(var currentRoleType in currentSchema.RoleTypes)
            {
                if(currentRoleType.Id.Equals(roleTypeId) == true)
                {
                    return currentRoleType;
                }
            }
        }
    }
    return null;
}

Once that RoleType object is returned from the method, then its RoleUri property can be examined to find the role’s URI with something like this:

var xbrlDoc = new XbrlDocument();
xbrlDoc.Load(“http://www.sec.gov/Archives/edgar/data/27419/000104746913003100/tgt-20130202.xml”);
var balanceSheetRoleType = GetRoleTypeById(xbrlDoc, “BalanceSheet”);
var balanceSheetRoleUri = balanceSheetRoleType.RoleUri;

Now that we have the URI for the role, we should be able to use that URI to look through the loaded calculation links to find the links that use the same role URI.

Now that we know how to find role types, let’s find the calculation links.

Finding Calculation Linkbase Information Using Gepsio

Like role types, calculation links are available through the schemas which reference them. The XbrlSchema object’s LinkbaseDocuments property is a collection of LinkbaseDocument objects. Each LinkbaseDocument maintains a CalculationLinks property, which is a collection of CalculationLink objects.  Given that chain of objects, code can be written to find all of the calculation links for a document:

private void GetCalculationLinks(XbrlDocument xbrlDoc)
{
    foreach(var currentFragment in xbrlDoc.XbrlFragments)
    {
        foreach(var currentSchema in currentFragment.Schemas)
        {
            foreach(var currentLinkbaseDocument in currentSchema.LinkbaseDocuments)
            {
                foreach(var currentCalculationLink in currentLinkbaseDocument.CalculationLinks)
                {
                    // is this the calculation link we want?
                }
            }
        }
    }
}

The question now is: how do we know that the calculation link found is the one we want?

… And Here Comes The Problem …

At this point, code should be able to look at a calculation link loaded by Gepsio to see if its role URI matches the URI in the role type that was found by the GetRoleTypeById() code proposed above. Here is the problem, however: although although the XBRL <calculationLink> element includes an attribute called xlink:role to describe the link’s role URI, Gepsio does not expose that value as a property of the CalculationLink class. It would be ideal to write something like this:

foreach(var currentCalculationLink in currentLinkbaseDocument.CalculationLinks)
{
    if(currentCalculationLink.RoleUri.Equals(balanceSheetRoleType.RoleUri) == true)
    {
        // this is the calculation link we want!
    }
}

However, the problem is that Gepsio’s CalculationLink class does not implement a RoleUri property, so this code doesn’t work, because the role URI isn’t available for a calculation link.

The Way Forward

Fortunately, the lack of a RoleUri property on the CalculationLink class is the only thing missing from the original user’s perspective. Adding this property into Gepsio shouldn’t take long at all. Although I am currently involved in getting Gepsio to work on .NET 4.5, WinRT and Windows Phone 8 through the Portable Class Library technology, I can put that work aside for a bit and release a new CTP that exposes a RoleUri property for the calculation link class.

So, here is the current plan:

  1. Shelve my “Portable Gepsio” changes.
  2. Get back to the current Gepsio codebase (which is released as 2.1.0.7).
  3. Add support for the RoleUri property in the Gepsio CalculationLink class.
  4. Build and release a new Gepsio CTP as version 2.1.0.8.
  5. write a follow-up blog post describing how to find a calculation link based on a role type, which was the original question.
  6. Unshelve the “Portable Gepsio” changes and return to that work.

Wish me luck!

4 thoughts on “Searching for Balance Sheet Calculations with the Sep 2013 CTP

  1. Pingback: XmlResolver Patch Submitted | gepsio

  2. Pingback: The Need for Calculation Link Validation Results with Gepsio | gepsio

  3. Pingback: Better Support for Role Type Discovery and Calculation Link Roles Coming in Next CTP | gepsio

  4. Pingback: Change Log for Nov 2014 CTP | gepsio

Leave a comment