Calculating Percentage of Percentage in SSRS - sql

Figure A
Figure B
Figure C
I have created the table (figure A) that is giving me the result (figure B) where the subcategory percentages are taken from the TOTALS (example: for 1/16/2016 | 3.04% + 11.13% + 0.02% = 14.19%).
I need the subcategory percentages to be taken from the respective category total making it the new 100%, as displayed in figure C: the desired result (example: for 1/16/2016 | 21.40% + 78.42% + 0.17% = 100%).

In your example you want to refer to that cell with a total of 584 for Category B. SSRS doesn't have the option for you to refer to a value within multiple groups like that. You can only provide one scope override. To get this functionality you can add a subquery to your dataset that aggregates those values in a new column.
So for example your dataset should end up looking like this:
CategoryName SubcategoryName Number CategorySubtotal
Category B subcategory a 125 584
Category B subcategory b 458 584
...
Now you can easily calculate the percent of total for each category in the report.

Related

SSRS: Summing Lookupset not working

I'm currently working on a report where I'm given 3 different datasets. The report essentially calculates the input, output and losses of a given food production process.
In dataset "Spices", contains the quantity of spices used under a field named "Qty_Spice". In dataset "Meat", contains the quantity of meat used under a field named "Qty_Meat". In dataset "Finished", contains the quantity of finished product used under a field "Qty_Finished".
I'm currently trying to create a table where the amount of input (spice+meat) is compared against output (finished product), such that the table looks like this:
Sum of Inputs (kg) | Finished Product (kg) | Losses (kg)
10 8 2
8 5 3
Total:
18 13 5
What I'm currently doing is using lookupset to get all inputs of both spices and meats (using lookupset instead of lookup because there are many different types of meats and spices used), then using a custom code named "Sumlookup" to sum the quantities lookupset returned.
The problem I'm having is that when I want to get the total sum of all inputs and all finished products (bottom of the table) using "Sumlookup" the table is only returning the first weight it finds. In the example above, it would return, 10, 8 and 2 as inputs, finished products and losses respectively.
Does anyone know how I should approach solving this?
Really appreciate any help
Here is the custom code I used for SumLookUp:
Public Function SumLookup(ByVal items As Object()) As Decimal
Dim suma As Decimal = 0
For Each item As Decimal In items
suma += item
Next
Return suma
End Function

Calculating Average based on Condition in SAP HANA GRAPHICAL VIEW

I need to calculate total average as well as average for each value of ColumnD, divided by number of unique values in ColumnA:
ColumnA ColumnB ColumnC ColumnD
A 10 xyz Ab
A 20 def Ab
A 5 mno Xy
B 10 pqr Ab
B 40 abc Xy
C 10 uvw Xy
Total Average (divided by unique ColumnA):
(10+20+5+10+40+10)/3= 31.66
Now I need Average for ColumnD = 'Ab':
(10+20+10)/2
Average for ColumnD = 'Xy':
(5+40+10)/3
I made Calculated Column in HANA:
Counter-> CA_Count on ColumnA(to get unique Count)
CA_Avg ->
ColumnB/CA_Count
for Avg of Ab:
CA_AVG_Ab :
if(ColumnD='Ab',CA_Avg,0)
but this Value is not coming correctly.
To model different aggregation levels in CVs you need to model separate data flows leading into separate aggregation nodes.
The output of these agg. nodes can then be joined together (outer join, obviously).

MDX weighted values

I have a cube built on a fact which, amongst others, includes the Balance and Percentage columns. I have a calculation which multiplies the Balance by the Percentage to obtain an Adjusted Value. I now need to have this Adjusted Value divided by the sum of all balances, to get weighted values.
The problem is that this sum of all balances doesn't apply to the whole dataset. Rather, it should be calculated on a filtered subset of the whole data. This filtering is being done in Excel using a pivot table, so i do not know what conditions will be used to filter.
So, for example, this would be the pivot i'd like to see:
ID Balance Percentage Adjusted Value Weighted Adjusted Value
1 100 1.5 115 0.38 (ie 115/300)
2 50 2 51 0.17 (ie 51/300)
3 150 1 150 0.50 (ie 150/300)
300 is obtained by summing the balance of the rows that show in the filtered pivot.
Can this calculation be somehow done in OLAP? Or is it impossible to compute this sum with what i know?
Yes should be possible; e.g., assuming 1/2/3 are the children of a common parent, then the following calculated measure should do the trick :
WAV = AV / ( id.parent, Balance )
If not we would need more information about the actual data model and query.

SSAS Cube showing irrelevant ID

I write a calculation MDX formula to show ID and the sum of any one ID. But its showing Sum of one ID and showing like bellow. Where I should show only 1 10.
After sum in the DB there are:
1 10,
2 30,
3 29,
4 97
I should show only 1 10
But its showing:
1 10,
2 10,
3 10,
4 10
I mean how many ID I have, its showing all of them. The ID is in Dimension.
anyone please help?
You writed calculation MDX formula with set of Dimension ID where this ID is equal 10. So MDX always show same value if yours "filtered" Dimension is inserted. If you try to insert Dimension which is not in mdx formula (must be connected to measure group) you will see what mdx calculation value is divided.

SPSS Compute Variable

Below is some data:
Test Day1 Day2 Score
A 1 2 100
B 1 3 62
C 3 4 90
D 2 4 20
E 4 5 80
I am trying to take the values from column 'day' and 'day2' and use them to select the row number for the column score. For example for Test A I would like to find the sum of 100 and 62 because that is the values of the first and second rows of score. Test B I would like to find the sum of 100, 62 and 90.
Is their anyway to do this in the Compute Variable window? Found in the menu Transform-Compute Variable?
I tried the following:
Score(MEAN(VALUE(Day1), VALUE(DAY2)))
This is not the proper way to call the cell location of Score and I received an error.
Can anyone help?
Thank you!
You really have two different datasets here. One is a dataset of scores numbered 1 through 5.
The other is a dataset that includes indexes into the score dataset. So the steps would be something like this.
First take the scores dataset and transpose it so that it has one row and 5 columns (Data>Transpose)
Then match that dataset to each case in the main dataset (Data>Merge Files>Add Variables).
Next you have to resort to using syntax directly.
You would declare a vector for the scores (VECTOR)
Finally, you use COMPUTE to index into the scores.
For your real problem, I suppose that you might have batches of scores and maybe there are some gaps. The Restructure Data Wizard can help you generalize this - convert cases into variables, but let's not go there yet.
HTH,
Jon Peck