Calculating Gross Profit Margin from COGS and Sales Revenue in XBRL

568 views Asked by At

Let me start by saying thank you for taking the time to read this.

I am creating an XBRL document using Altova Stylevision. I have properly brought in the XBRL Taxonomy and so on. I am creating some pie charts to show 1, sales revenue for three companies and % of sales revenue each company holds of the entire amount. I am doing the same thing with gross margin.

My COGS account is 400020 and my Sales Revenue account is 800000.

The following code is used to break up the three companies that I am comparing:

for $i in distinct-values($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail/gl-cor:identifierReference/gl-cor:identifierCode) return $i

The following code calculates Sales Revenue

sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='800000' and gl-cor:identifierReference/gl-cor:identifierCode=current() ]/gl-cor:amount)

The following code calculates % of Total Sales Revenue for each company

round-half-to-even(sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/
gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='800000' and  gl-cor:identifierReference/gl-cor:identifierCode=current() ]/gl-cor:amount) 

div sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='800000'  ]/gl-cor:amount)
* 100, 1)

The following code calculates Gross Profit

sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='800000' and gl-cor:identifierReference/gl-cor:identifierCode=current() ]/gl-cor:amount)
-sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='400020' and gl-cor:identifierReference/gl-cor:identifierCode=current() ]/gl-cor:amount)

The code is essentially the sum of my sales revenue account per company at the current time - the sum of my Cost of Goods Sold account per company at the current time.

All of this code above works, yay me!

When I go to calculate the Gross Profit Margin my head explodes, haha. I thought I could do something similar to the % of Total Sales Revenue code but I just can't seem to get it.

This is the code I have but does not properly calculate Gross Profit %

round-half-to-even(sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='800000' and gl-cor:identifierReference/gl-cor:identifierCode=current() ]/gl-cor:amount)
-sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='400020' and gl-cor:identifierReference/gl-cor:identifierCode=current() ]/gl-cor:amount))

div sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='800000' ]/gl-cor:amount)
- sum($XBRL/xbrli:xbrl/gl-cor:accountingEntries/gl-cor:entryHeader/gl-cor:entryDetail[gl-cor:account/gl-cor:accountMainID='400020' ]/gl-cor:amount) * 100, 1

I think the issue is because I am dividing the sum of my Revenue account - the COGS account but the div tag is only in front of if the Revenue portion of the statement. However, no matter how I try to write the statement I get an error that won't even return a result unless I type it this way. The results it outputs is a % in the hundred thousands and a second percent of 1 for each company. Obviously, it should only be outputting one percentage for each company for a total of three percents.

I am not really sure what to try next and I really hope it is just a syntax error but any help with syntax, or rewriting the statement is greatly appreciated!

Thanks, Joel

1

There are 1 answers

1
Bill Velasquez On

In the predicate of your XPath expressions you should use the variable =$i instead of =current() to compare with the actual company in the for loop.

Hope this helps.