Calculating Gross Profit Margin from COGS and Sales Revenue in XBRL - xbrl

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

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.

Related

How to count value with changing margin in WEBI?

​Hi Guys,
it sounds easy but it doesn't... Customer got several invoices in specific periods (months).
We want to calculate the final amount (total+margin). The problem is that margin is changing during the periods.
​I want to get 7142,76 in one cell (for summary). As you can see it's feasible in table but not in single formula as I am getting #MULTIVALUE
I guess the rootcause is margin which variable is quite simple:
=If([Doc Year]="2022" And [Doc Period]>=1 And [Doc Period]<=2) Then 0 Else If ([Doc Year]="2022" And [Doc Period]>2 And [Doc Period]<7) Then 4,5 Else 10
Thanks
The 6835,18 value is calcuated by:
​=Sum([Term Invoice Line Net Amount] ForAll ([Customer];[Doc Year];[Doc Period];[vMargin]))
​Cant figure out how to calculate total with margin...
Maybe someone will use my findings.
Finally I tried to focus just on counting the margin amount (307,58) and finally got it:
Sum([Term Invoice Line Net Amount]*[vMargin]/100)
Then final formula is:
=Sum([Term Invoice Line Net Amount] ForAll ([Customer];[Doc Year];[Doc Period];[vMargin]))+Sum([Term Invoice Line Net Amount]*[vMargin]/100)
and it works!
Previously I had #MULTIVALUE as I was counting amount with margin as below:
=Sum([Term Invoice Line Net Amount]*([vMargin]/100))
But the correct formula is:
=Sum([Term Invoice Line Net Amount]*[vMargin]/100)
small diffrence but crucial

SUM expression with column and row scope

I work in lending and we are trying to get the percentages of purchases and refis to show for the months. The problem that I am having is that I cannot get the scope correct.
Here is the current list
Andhere are the row groups
I know this is definitely a scope issue - I just can't figure out a way to have it take into account the month and the year. I have had success with it doing the percent of the year value. I am trying to simply show the percent of purchases and Refis for a given month for a given year.
For example, If we have 60 purchases and 40 Refinances for January of 2019 - I want it to show 60% and 40%.
I have tried messing around with the row and columns groups every which way and I still cannot seem to figure it out. Any help would be largely appreciated.
= SUM(Fields!TOTALLOANAMT.Value, "Grouped_Loan_Purpose5") /
SUM(Fields!TOTALLOANAMT.Value, "App_Sent_Year1")
I have a fairly simple solution that you could use to avoid any headache involved with grouping. I would suggest simply using the values in the textboxes to calculate your percentages. You can just do something like the following.
=(ReportItems!PurchasesTextbox.Value / ReportItems!TotalTextbox.Value) * 100
=(ReportItems!RefinanceTextbox.Value / ReportItems!TotalTextbox.Value) * 100
Then you can just format as percentages and leave everything else alone.

Calculate the average in SSRS 2016

I am using SSRS 2016 application to pull data from SharePoint list.
My task is to calculate the average DaysUsed and the average Percentage from a column.
It is a Matrix report which has two columns:
Sum(Fields!Days.Value)
Sum(Fields!Percentage.Value)
The task is to show the average days and average percentage.
I have tried the =Avg(Fields!Days.Value) but this shows wrong result.
UPDATE
Yes, the matrix is grouped by the Month to show each relevant month.
See the screenshot below what I have tested so far.
The DaysUsed is a calculated between 2 fields [FromDate] and [UntilDate] by summarising the total days minus the weekends. see below:
=(DateDiff(DateInterval.day,CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")), CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")))+1)
- (DateDiff(DateInterval.WeekOfYear,CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")), CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")))*2)
- IIF(Weekday( CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")),1) = 1,1,0)
- IIF(Weekday( CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")),1) = 7,1,0)
- IIF(Weekday( CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")),1) = 1,1,0)
- IIF(Weekday( CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")),1) = 7,1,0)
Furthermore, the [DaysUsed] row then consists of IIF(value is null then show 0 otherwise show the total value of days used).
=IIF(IsNothing(Sum(Fields!Days.Value)), "0", Sum(Fields!Days.Value) )
Sum(Fields!Days.Value)/CountRows()
Shall give you average days. Similarly goes for others as well.
If you has a field called Fields!Days.Value, I guess your data in the screenshot is already grouped by month. This means the expression
=Avg(Fields!Days.Value)
gives you the average over all Days (sum of all days / count of all days).
If you want to use the grouped values (by mounth) you either can use the following expression when you are inside the scope (the monthly socpe; indicated by the brackets on the most left side on your tablix)
=Sum(Fields!Days.Value) / Count(Fields!Days.Value)
If you are not in the scope you have to tell the tablix that is should use your monthly grouping. For this you can use the following:
=Sum(Fields!Days.Value, "YourMonthGroupName") / Count(Fields!Days.Value, "YourMonthGroupName")

SSRS percentage of a total with column groups

I apologize in advance if this is not enough info or if it is confusing (This is my first post to the forum and it's a little hard to explain what i'm trying to do). I have been researching this for a couple days now. This article comes really close to what I need, but this person did not have column groups, just a a single column with an output: SSRS percentage of a total.
Consider this layout and groups:
The idea is to provide the percentage of the total records per PrimaryPayor per Company and then break it out by Year-Month.
This expression:
=CountDistinct(Fields!ID.Value, "Primary_Payor") / CountDistinct(Fields!ID.Value, "Company")
Results in this output (The first image is my output, the second is the desired output):
As you can see, the percentages do NOT group by Year-Month, instead just provides the total percentage of IDs per Payor per Company and repeats it for every Year-Month column. How can I get the percent of Total IDs per payor, company, and month as it shows in the second result image?
After editing my question, I thought of something I hadn't tried.
If I just use =CountDistinct(Fields!ID.Value), this gives the total count for each payor, company, month, plus, I added a Total row.
Then, if I reference those textbox values (instead of trying to calculate the percentage on the fly) divided by the total row, I get my results. I just had to add a column inside of the column group. I should then be able to just Hide my "total" column and display only the percentages.
=ReportItems!Textbox50.Value / ReportItems!Textbox35.Value
Here is the output (with the total counts and then after hiding the "count" column):
Final Results
Try:
=CountDistinct(Fields!ID.Value) / CountDistinct(Fields!ID.Value, "Company")
I removed the Primary_Payor scope leaving the function calculate the count in the cell scope Primary_Payor and DOS_YrMo.
UPDATE:
=CountDistinct(Fields!ID.Value) / CountDistinct(Fields!ID.Value, "DOS_YrMo")
Let me know if this helps.

Using running totals in MS access report cumulatively

I am developing a db (MS access 2010) to support a school with a well-defined model for tuition quotation. The list of products is assembled for each quote, then various discounts are applied. The discounts may be a percentage or an absolute dollar amount. So far, so easy. The problem is that their business logic requires:
No limit on number of discounts.
Specific discounts to be applied in a defined sequence (implemented in my case with a "discount ordinal" column, values 1 (first applied) to 100 (last applied).
Each sequential application of a discount is to the running total of the quote. Eg: Total products $1000. Discount: 50%. Value: $500. Subtotal $500.
Subtotal: $500. Discount: $25. Value: $25. Subtotal: $475.
Subtotal: $475. Discount: $10%. Value: $47.50. Subtotal: $427.50.
This appears to be a variation of the "get the value of the field in the previous row" problem, but with the added twist that the "value of the field" is actually a cumulative calculation. It has the flavor of recursion: while discounts remain, subtotal(previous subtotal).
I have no clear idea how to implement this in a report, because the calculation as noted above is self-referential. I'm not looking for code here, just guidance on the general approach to the problem (ie, some kind of global variable, using VBA - in which case, I'm not sure what the "glue" between the query in VBA and the report would be - or some trick with a calculated field although I've spent a lot of time trying to figure one out). Any thoughts?
In that kind of situations, I always create a new table, that will get filled up when the report opens, and base the report in that table, not the original one. That way I can do all the calculations I need, even making several passes. The report then is simply a "dump" of the table. Complex totals can be additional columns, that will be shown only in the totals section.
You could have table for purchase history using an integer to link each purchase since an autonumber by itself will not link each discount stage.
So in excel I would use something like this:
v = Starting Value
i = 1
Do Until i = Last Discount
d = ws.Cells(i, 9).Value
v = v * (1 - d)
ws.Range("B2").Value = v
i = i + 1
Loop
At each stage you could write to the table (using docmd.runsql) the discount applied (d) and the value (v) but it could be quite slow. You could then order the table by purchase identifier then descending by value since sequential discounts will inherently order correctly.