Home › Forums › The XBRL API › Connecting facts with statements (SQL)
- This topic has 0 replies, 1 voice, and was last updated 2 years, 3 months ago by David Tauriello.
-
AuthorPosts
-
-
Tuesday, August 30, 2022 at 3:50 PM #203100David TaurielloKeymaster
A Public Filings Database User writes:
I wonder if there is a flag that differentiates among the Balance Sheet, Income Statement and Cash flow statements in the data base?. Is there a way to tie each value in the fact table with one of the statements?
The relationship table holds information about the structure of the report (sections, order of line items as defined in the presentation linkbase), and the fact table holds the data corresponding to the concepts that are the report’s line items.
One of the recent enhancements to the XBRL Filed Data spreadsheet extension was the addition of a new custom function – =XBRL.showSQL() – that translates XBRL API queries back into SQL statements that can be used with the Public Filings Database.
You can use the Full ESEF or SEC Report template (https://xbrl.us/wp-content/uploads/2022/08/FullReport-DimensionPivot-Template.xlsx) to generate the following queries for facts and relationship. The data rows are ‘lined up’ in the report with a lookup on concept.local-name which is synonymous with relationship.target-name (fact.element_local_name and el_qname.local_name in the SQLs). Hopefully, that gets you on the path to a single SQL query that accomplishes your goal.
SQL #1
SELECT (fact.fact_value)::text AS "fact.value" , (fact.element_local_name)::varchar AS "concept.local-name" , (re.is_base)::boolean AS "concept.is-base" , (fact.fact_id)::int AS "fact.id" , (fact.fiscal_year)::int AS "period.fiscal-year" , (fact.fiscal_period)::text AS "period.fiscal-period" FROM fact JOIN element AS element ON fact.element_id = element.element_id JOIN report AS fact_report ON fact.accession_id = fact_report.report_id JOIN report_element AS re ON fact.element_id = re.element_id AND re.report_id = fact_report.report_id AND re.report_id = fact.accession_id WHERE fact_report.report_id in ('496120') ORDER BY (fact.element_local_name)::varchar ASC
SQL #2
SELECT (target_qname.local_name)::varchar AS "relationship.target-name" , (dts_relationship.to_element_id)::int AS "relationship.target-concept-id" , (label_uri.uri)::varchar AS "relationship.preferred-label" , (rel_dts_network.description)::varchar AS "network.role-description" , (dts_relationship.tree_sequence)::int AS "relationship.tree-sequence" , (dts_relationship.tree_depth)::int AS "relationship.tree-depth" FROM dts_relationship JOIN element AS to_element ON dts_relationship.to_element_id = to_element.element_id JOIN qname AS target_qname ON to_element.qname_id = target_qname.qname_id LEFT JOIN uri AS label_uri ON dts_relationship.preferred_label_role_uri_id = label_uri.uri_id JOIN dts_network AS rel_dts_network ON rel_dts_network.dts_network_id = dts_relationship.dts_network_id JOIN qname AS el_qname ON rel_dts_network.extended_link_qname_id = el_qname.qname_id WHERE rel_dts_network.dts_id in ('624413') AND LOWER(el_qname.local_name) in ('presentationlink') ORDER BY (rel_dts_network.description)::varchar ASC, (dts_relationship.tree_sequence)::int ASC
The raw output from =XBRL.showSQL() can be cleaned and ready to use by wrapping the formula in =CLEAN() – this will remove the beginning and ending quotes and change all double quotes to singles … just remove the offset and limit and you’re good to go.
-
-
AuthorPosts
- You must be logged in to reply to this topic.
Search Forums
Recent Topics
Recent Replies
-
Spreadsheet Commands: Query Worksheet and Query Workbook Query Workbook 1 month, 3 weeks ago
-
Query for multiple dimensions 3 months, 3 weeks ago
-
Query for multiple dimensions 4 months ago
-
Showdata function 6 months, 2 weeks ago
-
Showdata function 6 months, 2 weeks ago
Documentation & Discussion
- Get started with Google Sheets OR
- Get started with Microsoft Excel OR
- Get access to as-filed data from us for other tools or your own app
- XBRL API Interactive Documentation
- Ten Tips & Techniques
- The XBRL API
- XBRL Data Community
- 2024 US GAAP Taxonomy Viewer
- Live support - Monday, 3:30 - 4:30 PM ET
Who's using this free data?
API Use 2024 || API Use 2023 || API Use 2022 || API Use 2021 || API Use 2020 || API Use 2019 || API Use 2018
Join XBRL US
- Individual Options - Basic, Power User & Sole Practitioner
- For Your Team - Startup, Non-Profit, Academic & Corporate options
- Member Benefits Comparison Table
Using the XBRL API with the Public Filings Database
Unless otherwise agreed to in writing, any and all use of the XBRL API to authenticate and retrieve data from the XBRL US Database of Public Filings implies user consent and agreement with the XBRL US API Agreement. If you are unable to agree to these terms, do not use the XBRL API.
To use the XBRL API outside of Google Sheets, your account needs to be provisioned for OAuth2 access.