I'm using SSRS and have made a "pivot table". The pivot table has two calculated columns, and I want to use those values to get a third value, the difference between both values.
This is an example of what my table looks like:
*Edit: the percentages are averages of about 40+ values with those row/column attributes *
Category A B Difference
1 47% 57% B-A
2 45% 49% B-A
3 13% 73% B-A
4 27% 23% B-A
Total 23% 34% B-A
Each percent is an average of the category grouped by A and B. I need a function that will gather the average for A and subtract it from the Average of B for that row.
I've tried the following so far and have resulted in error:
=IIf(Fields!Log1.Value = "End", Avg(Fields!Log1.Value), Nothing) - IIf(Fields!Log1.Value = "Begin", Avg(Fields!Log1.Value), Nothing)
Any help is appreciated. Thanks
I believe the issue here has to do with how you are referencing the Log1 column within the Category group. Think about how the data looks behind the scenes. Within each category you have multiple rows that you want to summarize. Some rows might have a different value for Log1. The intent is to get the average of the rows that have a certain Log1 value.
What's actually happening is that it's arbitrarily picking the first Log1 value within each group and using that in the expression. In other words, you are getting the average of all the rows or none of the rows for that group based on what Log1 happened to be in the first row of the category group.
As a side note, in your expression, you refer to Log1 as a text field and in the Avg function, I'm assuming those should actually be two different columns and you're trying to average numbers in the A and B columns.
What we actually want it to do is check the value of Log1 for every row and then average those values. So, here's what I suggest:
Create two calculated fields on your dataset. Use expressions like this:
=IIf(Fields!Log1.Value = "Begin", Fields!ColumnA.Value, Nothing)
=IIf(Fields!Log1.Value = "End", Fields!ColumnB.Value, Nothing)
In column A of your table refer to this new calculated field. Repeat for column B.
=Avg(Fields!NewColA.Value)
To get the difference:
=Avg(Fields!NewColB.Value) - Avg(Fields!NewColA.Value)
In other words, we are forcing it to filter values row-by-row and then aggregating those filtered values.
Related
I need to get SUM for TOP 10 rows only by counting unique claim numbers. Not for the whole dataset.
for that in a group properties I set Filter with expression:
But the total sum reflected for the whole dataset, not for top 10.
I tried using RunningValue finction, but no success:
https://mkncreations.com/site/2012/05/filter-top-n-group-totals/
What would be the way to capture sum for only top 10 rows?
Create row inside the group
2.Enter expression referencing dataset name (not group name):
=RunningValue(Fields!IdemnityReserves.Value,SUM,"UnitedSpecialty")
Make this row invisible
Add total row
Enter expression in total row referencing cell created in step 2:
=reportitems!Textbox288.Value
I have a row group in SSRS that calculates totals by each group. However, I would like to get the percentage of each group out of the overall total. However, I do not know how to achieve getting the overall total to work within the same expression.
Right now I have this to get my total of each group:
=Sum(Iif(IsNothing(Fields!ID.Value),0,Iif(Fields!STATUS.Value = "Closed",1,0)))
But I am not sure how to divide that by the overall total. Would anyone have any ideas?
You will need to apply the same expression, but in a different Scope.
e.g. to get the total for the whole Dataset, you will need something like:
=Sum(Iif(IsNothing(Fields!ID.Value),0,Iif(Fields!STATUS.Value = "Closed",1,0)), "DataSet1")
Where DataSet1 is the name of the Dataset used by the Table.
Once you have this new expression, simply divide the Row total expression by the Dataset total expression to get the percentage.
so I'm using Microsoft access reports and I need to be able to sum only the rows in a column that are designated in a separate column by text. So column A has either a Y or N for every row and I need to sum the numbers in column B that have a Y in column A.
I just don't know how to designate which numbers should be summed using the other column.
Thanks
IIF(A='Y',Sum([B]/[B Grand Total Sum]), 0)
Wouldn't you want to evaluate the A criteria before you SUM anything up?
Honestly in this case I don't think it matters, but in general you will want to do evaluations of criteria before you do any aggregations or you're inevitably decreasing your performance. Also, your results may be inaccurate if you do IIF evaluations of columns outside of the summation.
Sum(Iif([A]="Y",[B],0))/SUM([B]) Should do the trick.
This will add B if A = Y and 0 if A <> Y, then divide that SUM by The overall total of Column B.
You could also do this in the underlying query...
I want to query the following table in access
Productid LowEnd MidRange HighEnd
1 10% 15% 25%
2 13% 18% 28%
3 14% 19% 30%
based on both the Productid and the CLass (Lowend,midrange,Highend) is there anyway to do it without manually creating a newtable?, I can do it easily by writing an excel macro to make a new table. I have used the crosstab to make tables like these.. can we undo them?
EDIT:
lets say the table name above is 'matrix'
The query I want to be able to do is SELECT * FROM matrix WHERE ((matrix.Productid = 1) and (column = 'LowEnd')) . I know column = lowend is not valid in sql so... I guess I'll have to use the Union of multiple queries which have the where caluse to identify the correct coulmn.
I guess I'll have to use the Union of
multiple queries which have the where
cause to identify the correct column.
I think you provided your own answer. The restriction is all the rows must be of the same data type or at least data types implicitly convertibles each others.
SELECT Productid, LowEnd AS Value
UNION
SELECT Productid, MidRange AS Value
UNION
SELECT Productid, HighEnd AS Value
My report is as follows:
One table provides financial information with sums at the group footer (Grouping is called "StockTable_Shipped"). The group is controlled by a boolean value (1=shows shipped data, 0 = shows received data)
The second table is a variance report for data that has been shipped (boolean value of 1) and has a sum at the bottom of the table.
My ultimate goal is to take the sum from table1 where shipped=1 and subtract it from the variance sum from table2.
This will be placed in a textbox at the bottom of the report.
I understand if this sounds confusing but I would be more then happy to provide more information.
If I were you, I would create a new calculated field which would hold the sum of all your Shipped Data (1's) not just the sum of all your data (1's and 0's).
After that, it should be as simple as putting in the expression that subtracts your calculated field from the Sum of your table2 field.