xbrlus / xule

An open-source XBRL processor for business rules, rendering and custom data reporting. See https://xbrl.us/xule for documentation and https://xbrl.us/xule-editor for a VS Code syntax highlighter.
Apache License 2.0
24 stars 9 forks source link

How to properly include the namespace us-gaap? #12

Closed BrittMcDanel closed 1 year ago

BrittMcDanel commented 1 year ago

I am trying to get all the parent-child relationships in an xsd file. When I run my xule file (using the Arelle command line python file):

output example
navigate parent-child descendants

I get the expected list of results back (us-gaap:InterestAndDividendIncomeOperating, us-gaap:InterestExpense, us-gaap:NoninterestIncome, gs:InvestmentManagement, us-gaap:BrokerageCommissionsRevenue, etc).

I want to get the full hierarchy of these values, and am planning on going one at a time, getting their respective children and building a tree. I am trying to start this process by getting the children of us-gaap:NoninterestIncome by doing:

output example
navigate parent-child descendants from us-gaap:NoninterestIncome

I get an empty list back. The VSCode extension is saying that us-gaap is an unknown namespace. I try to include it like so:

namespace us-gaap=https://xbrl.fasb.org/us-gaap/2021/

output example
navigate parent-child descendants from us-gaap:NoninterestIncome

And get an empty list back again. When hovering over us-gaap:NoninterestIncome, the VSCode extension gives:

Unknown local name: NoninterestIncome in namespace https://xbrl.fasb.org/us-gaap/2021/ (built-in)

How do I properly include the us-gaap namespace? Thanks for making xule!

davidtauriello commented 1 year ago

Hi @BrittMcDanel - use http://fasb.org/us-gaap/2021 to define the namespace for the filing and the XULE should process without an issue.

BrittMcDanel commented 1 year ago

Thanks @davidtauriello. I have a quick clarifying question. I am trying to get the children nodes for a given parent. Running:

navigate parent-child descendants

Gives me all the nodes in a list as expected. However, when trying to retrieve the children for a given element with:

navigate parent-child descendants from us-gaap:NoninterestIncome

I get an empty list. This tag does have children in the actual source. Is this the correct way to get the children for a particular node?

davidtauriello commented 1 year ago

Hi @BrittMcDanel - it sounds like you're trying to list the elements in the calculation for us-gaap:NoninterestIncome.

If that's the case, use summation-item instead of parent-child in your expression. The former evaluates based on the calculation linkbase, and the latter on the presentation linkbase. The full list of navigation role options is on page 34 of https://xbrl.us/wp-content/uploads/2019/10/XuleV1.1.pdf

If I've misunderstood your goal, please post an example of a report where the element appears as a parent to children.

BrittMcDanel commented 1 year ago

Hi @davidtauriello. Thanks for all the help. You are correct, I am trying to list the elements for the us-gaap:NoninterestIncome calculation. Here is the motivating example for GS:

https://www.sec.gov/ix?doc=/Archives/edgar/data/0000886982/000088698222000002/gs-20220930.htm The first table with the title PART I. FINANCIAL INFORMATION. The row title is Total non-interest revenues (concept value is us-gaap:NoninterestIncome). There are 5 summation-item children for this value: [Investment banking, Investment management, Commissions and fees, Market making, Other principal transactions]

The corresponding cal file url is: https://www.sec.gov/Archives/edgar/data/886982/000088698222000002/gs-20220930_cal.xml

looking for NoninterestIncome will show this summation-item relationship. Running:

namespace us-gaap=http://fasb.org/us-gaap/2021

output query-test
navigate summation-item descendants

Returns a list of all concepts. Trying to find just the children of us-gaap:NoninterestIncome with:

namespace us-gaap=http://fasb.org/us-gaap/2021

output query-test
navigate summation-item descendants from us-gaap:NoninterestIncome

Returns an empty list. Trying the option children instead of descendants also returns an empty list. I have tried the label in the cal file as well: loc_us-gaap_NoninterestIncome_185e8536-1a68-4e7e-bbdf-122527a05fee but I get the same result.

The script call is:

python3.9 arelleCmdLine.py --plugins xule -f https://www.sec.gov/Archives/edgar/data/886982/000088698222000002/gs-20220930_cal.xml --noCertificateCheck --xule-compile "sample.xule" --xule-run --xule-rule-set "compiled_rules.zip" --xule-compile-type="json"
davidtauriello commented 1 year ago

@BrittMcDanel - the GS filing uses the 2022 US GAAP taxonomy. Switch to that year in the namespace and your expression works as expected.

I'm terribly sorry I wasn't clearer about the fact that the namespace defined needs to match the taxonomy used for a filing.

image

BrittMcDanel commented 1 year ago

@davidtauriello No worries, it works as expected now. I am getting the same output that you show. Thanks again for all your help!

BrittMcDanel commented 1 year ago

Hi @davidtauriello, I have another question (I am not sure if I should raise another issue or not so I am just continuing in this thread). I am trying to get various information about a concept such as:

{
    "tag": "us-gaap:LiabilitiesCurrent",
    "fact": "464,000,000",
    "period": "As of 09/30/2022",
    "measure": "USD",
    "scale": "Millions",
    "decimals": "Millions",
    "balance": "Debit",
    "sign": "Positive",
    "type": "Monetary Item Type",
    "label": "Cash and Cash Equivalents, at Carrying Value",
    "terseLabel": "Cash and cash investments",
    "weight": "Added to parent (1.00)",
}

I have tried:

navigate summation-item descendants from us-gaap:LiabilitiesCurrent returns (target, weight)

but it seems like this has a limited number of values that can be retrieved (though it does work).

I see that some of this information is in the $fact variable, but am not sure how to extract this for a given concept. For example, trying to extract values for us-gaap:LiabilitiesCurrent using the xule:

{@concept.local-name = 'us-gaap:LiabilitiesCurrent'}

doesn't seem to output anything. How does one go about accessing the $fact variable for a given concept (as well as its numeric value)?

BrittMcDanel commented 1 year ago

I think it was just a mistake on my end. I was passing various xml files as the -f param in the arelle cmd line python script instead of htm files. Now that I am passing htm files it retrieves fact as as expected.

davidtauriello commented 1 year ago

Hi @BrittMcDanel - thanks for following up. If you're still looking to get fact details for concepts that you've returned as a list, you can do something like this:

namespace us-gaap = http://fasb.org/us-gaap/2022 constant $period = date('2021-12-31')

output example1 {$allitems = navigate summation-item descendants from us-gaap:Liabilities @concept in $allitems @period = $period}

message "{$rule-value.concept} {$rule-value} {$rule-value.unit} {$rule-value.period}"

This puts the summation-item descendants in a list, then populates the @concept filter with those elements and applies the period defined by the constant as 2021-12-31 to return facts. The message uses XULE's default $rule-value variable (literally, the value in the report that was found by the filter) with dot-notation to include fact attributes.