On Sunday 23 Mar 2014, Mike Willis posted a link to an article in the XBRL International group on Facebook. The article, with its intriguing title of “Why Investors Are Not Using XBRL“, argues that a data error in a 2012 10-Q filing from Applied Micro Circuits contained an error in its reporting of Warrants Compensation Expense and that, because of this error, the filing (and, by association, XBRL itself) cannot be used reliably.

(The filing referenced by the article is available from EDGAR here, and the raw XBRL data for this filing is available here.)

When I first read about the error, I considered two possibilities:

  1. The Warrants Compensation Expense fact was eligible to be a part of a calculation link, but was not authored as such. If this was the case, then the error was in the XBRL document’s creation process, because adding this item to a calculation link would have ensured that the calculation would be validated by XBRL validators like Gepsio. The calculation would have been flagged as an error by XBRL validators, which would have alerted validators to the error in the fact.
  2. The Warrants Compensation Expense fact was not eligible to be a part of a calculation link. If this was the case, then the fact did not contribute to a summation value and no calculation link would have been possible. In this case, then XBRL validators would have been unable to find the error in the value, since there would be no calculation link to validate.

I decided to use Gepsio to get some background on the issue. I was curious to see whether the article had pointed out an error with the filing, or if some other issue was involved with the filing.

The Investigation

I dug around in the filing’s XBRL instance and found the value in question:

<amcc:WarrantsCompensationExpense contextRef="ThreeMonthsEnded_30Jun2012" decimals="-5" unitRef="USD">1289000000</amcc:WarrantsCompensationExpense>

Then I dug around in the filing’s calculation linkbase document to see if the fact was referenced anywhere in a calculation link, and found this:

<calculationLink xlink:title="0130 - Statement - Condensed Consolidated Statements of Cash Flows (Unaudited)" xlink:role="http://www.appliedmicro.com/2011-06-30/role/StatementsOfCashFlows" xlink:type="extended">

    <loc xlink:href="amcc-20120630.xsd#amcc_WarrantsCompensationExpense" xlink:type="locator" xlink:label="amcc_WarrantsCompensationExpense"/>
    <calculationArc xlink:type="arc" priority="1" weight="1" use="optional" order="65" xlink:to="amcc_WarrantsCompensationExpense" xlink:from="us-gaap_NetCashProvidedByUsedInOperatingActivities" xlink:arcrole="http://www.xbrl.org/2003/arcrole/summation-item"/>

Ah ha! So, the fact is involved in a calculation of some sort.

The next step was to see if Gepsio considered the XBRL document to be valid or invalid, perhaps because of a broken calculation link driven by the bad value of the Warrants Compensation Expense fact. I downloaded all of the filing’s XBRL data to my local machine and wrote a small Powershell script to process the filing through Gepsio’s Sep 2013 CTP:

Add-Type -Path "C:\Users\Jeff\Desktop\amcc-20120630\JeffFerguson.Gepsio.dll"
$XbrlDoc = New-Object -TypeName JeffFerguson.Gepsio.XbrlDocument
$DocumentLocation = "C:\Users\Jeff\Desktop\amcc-20120630\amcc-20120630.xml"
Write-Host "+---------------------------------+"
Write-Host "+---------------------------------+"
Write-Host "Loading and validating" $DocumentLocation"..."
Write-Host "+-------------------------------+"
Write-Host "+-------------------------------+"
Write-Host "Loaded." $XbrlDoc.XbrlFragments.Count "fragments in document."
Write-Host "Is this document valid?" $XbrlDoc.IsValid
foreach($XbrlFragment in $XbrlDoc.XbrlFragments)
    Write-Host "+---------------+"
    Write-Host "| XBRL FRAGMENT |"
    Write-Host "+---------------+"
    Write-Host "Is this fragment valid?" $XbrlFragment.IsValid
    Write-Host $XbrlFragment.Facts.Count "facts in fragment."
    Write-Host $XbrlFragment.Units.Count "units in fragment."
    Write-Host $XbrlFragment.Contexts.Count "contexts in fragment."

The Powershell script gave me the following output:

Loading and validating C:\Users\Jeff\Desktop\amcc-20120630\amcc-20120630.xml...
Loaded. 1 fragments in document.
Is this document valid? True
Is this fragment valid? True
748 facts in fragment.
9 units in fragment.
180 contexts in fragment.

According to Gepsio, the filing is valid. Since Gepsio processes and validates calculation links, there are two possibilities:

  1. The document is indeed valid. If this is the case, then, by association, it follows that all of the calculation links are valid. This would imply that the calculation link involving the Warrants Compensation Expense fact is valid, and the value is not in error after all.
  2. The document is being incorrectly reported as valid. In this case, the document is invalid, perhaps due to the broken calculation link driven by the bad value of the Warrants Compensation Expense fact, and Gepsio has some sort of bug which is not finding, or correctly reporting, the error.

A Short Primer on Calculation Link Validation with Gepsio

Gepsio, as a part of its XBRL validation processing, examines all facts involved in calculation links and performs the math to ensure that values stored in facts reflect numeric data that reflects the mathematics specified by the link. If Gepsio finds an error in the math behind a calculation link, it creates a SummationConceptValidationError object, populates the object with all of the relevant information about the failed calculation validation, and stores the object in the ValidationErrors collection of the XbrlFragment object that contains the facts involved in the calculation.

 If Gepsio does not find an error in the math behind a calculation link, then no SummationConceptValidationError object is created, the variables created to validate the calculation link are discarded, and Gepsio moves onto validating the next calculation link. There is, in this case, no record of the validation.

The Case for Retaining Calculation Link Validation Results

In our example above, there are no SummationConceptValidationError objects in the XbrlFragment (indeed, there are no validation error objects of any kind in the fragment). But, since all of the calculations have passed Gepsio’s inspection, and the variables involved in the calculation links have been discarded, there is no way to “debug” Gepsio at runtime to ensure that the calculation links were validated correctly. There is a need to retain these calculation link validation variables so that Gepsio can be easily debugged to ensure that it is performing the calculation link validations correctly.

If these calculation link values were available for all calculation links, then the results could be examined and compared against the expected results to see if there is an error in Gepsio’s calculation link validation code.

The Path Forward

I will create classes for Gepsio that will allow all calculation link validation data to be retained. Objects of these classes will be made available to the caller once Gepsio completes its load and validation work. I have previously written about other work that I would like to do to enhance Gepsio’s support of calculation links, so it seems like this work can be done at the same time.

Once these changes are in place, I can rerun this XBRL instance against the Applied Micro Circuits 10-Q, look at the Gepsio calculation link math by enhancing the PowerShell script to output each of the calculation link variables, see if there are any Gepsio errors that need to be debugged, and hopefully move closer to getting answers regarding whether or not the original error could have been caught by an XBRL validator.

XmlResolver Patch Submitted

Codeplex user MarkConway has submitted a patch for Gepsio which adds support for caching of common linkbases and schemas through an XmlResolver object. This has been a request from several users, and I am grateful to Mark for submittin the patch which will make Gepsio better for all users.

If you are interested in taking a look at the patches ahead of time, you can find them here. I am thinking of releasing an April 2014 CTP which includes this patch, which will make Gepsio more performant for all users, as well as the support for the exposure of role type information in calculation links, which I wrote about here. This proposed April 2014 CTP would not include my proposed support for .NET 4.5, WinRT/Windows Store and Windows Phone 8 but would remain a .NET 3.5 assembly. I envision the following workflow:

  1. shelve my Portable Class Library changes
  2. roll back to the Sep 2013 CTP code base
  3. apply this patch
  4. add the support for calculation link role types
  5. release a new CTP
  6. unshelve my Portable Class Library changes and continue the Portable Class Library work

The good news is that this page seems to imply that the XmlResolver class is available in the Portable Class Library, which would mean that this patch would seem to survive the migration of the Gepsio code base to the Portable Class Library.

Thank you to Mark for the patch submission!

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>

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" />

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();
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
  3. Add support for the RoleUri property in the Gepsio CalculationLink class.
  4. Build and release a new Gepsio CTP as version
  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!

XBRL Schemas: Back to Custom Implementation

When Gepsio‘s first implementation began, it used a custom implementation of XBRL schema support, under my mistaken assumption that XBRL schemas were somehow different from standard XML schemas. I reconsidered that idea, and wrote about it in this article. After thinking about it, I decided to ditch the custom implementation and instead leverage .NET’s XML schema support, courtesy of the .NET Framework’s XmlSchema class. Once that was in place, I wrote about my success in this article. Yay!

I should have stuck with my original plan.

As I have mentioned before, I am currently working to get some multi-platform support for Gepsio. Currently, this multi-platform support is set to include .NET 4.5, WinRT, and Windows Phone 8 (though I may also consider Xamarin.iOS and Xamarin.Android if there is interest in Gepsio on iOS or Android). As it turns out, while the XmlSchema class is still available in .NET 4.5, it is not available in WinRT or Windows Phone 8. That means that Gepsio’s Xml-Schema based implementation of the XbrlSchema class is no longer valid, and a custom implementation must be put back in place.

This need first came up as I was testing Gepsio’s Portable Class Library (PCL) support against the XBRL-CONF-CR3-2007-03-05 Conformance Suite. Test 304.08 in that suite uses the following XBRL instance:

<?xml version="1.0"?>
<!-- Copyright 2003 XBRL International Inc.  See www.xbrl.org/legal.  All Rights Reserved. -->
<xbrl xmlns="http://www.xbrl.org/2003/instance"
xsi:schemaLocation="http://www.someCompany.com 304-03-monetaryItemTypeUnitsRestrictions.xsd">

  <link:schemaRef xlink:href="304-03-monetaryItemTypeUnitsRestrictions.xsd" xlink:type="simple"/>

  <my:assets unitRef="u1" contextRef="c1" precision="1">120</my:assets>

  <context id="c1">
      <identifier scheme="http://www.someCompany.com">example</identifier> 

  <unit id="u1">
    <measure xmlns:ISO4217="http://notTheISO4217Namespace">ISO4217:USD</measure>


This instance references the following XBRL schema:

<?xml version="1.0"?>
<!-- XBRL 2.1 Tests -->
<!-- Copyright 2003 XBRL International Inc.  See www.xbrl.org/legal.  All Rights Reserved. -->
<schema targetNamespace="http://www.someCompany.com"

	<import namespace="http://www.xbrl.org/2003/instance"

	<complexType name="assetsItemType">
			<restriction base="xbrli:monetaryItemType"/>

	<element name="assets" type="my:assetsItemType"
	substitutionGroup="xbrli:item" id="Asset"


This document is invalid according to the XBRL specification. It is invalid because the assets fact is defined in the schema as using a type defined as a complex type that derives by restriction from xbrli:monetaryItemType, but the fact’s unit reference does not reference the ISO 4217 namespace required by monetary item types.

With .NET’s support for the XmlSchema class, this check was easy. After loading the schema into an XmlSchemaSet, Gepsio looked through the set’s GlobalTypes collection, searching for the correct type. Once the correct type was found, the retrieved XmlSchemaType contained a wealth of information about the type and held more than enough information for Gepsio, in this case, to determine that the type was derived from a monetary type and that Gepsio’s monetary type XBRL validation should be enforced.

Now it’s time to write a portable implementation of the XbrlSchema class … it’s never a dull moment!