How can I get a variable with the count of A superior or equal to B and A inferior to B to make a pie chart with it ?
I created two var containing each of the count but I don't find how to aggregate them with a function.
You need to create a variable to determine the number that fall into each comparison category.
Column Comparison=If([a] >= [b]; "A >= B"; "A < B")
Then create another variable to count the number of rows that fall into each category.
=Count([Column Comparison]; All)
You need the optional "All" parameter in the count function so that the duplicate values are counted.
Now you can create a table with your two variables on it. I am not so great with charts so I just copied my table with Column Comparison and Count, click on the edge of it, right-clicked, and chose "Turn Into > Pie Chart".
Related
I have a cross table in business objects web intelligence which has customer IDs in the rows, items in the columns and quantity in the body. I am trying to create a variable (dimension?) that will flag whether a customer has bought one particular item plus any other item. So, if for example the set item is 'item1' then the flag would show if the customer bought that and also if they bought at least one other item which could be any from another 100 or so. I am trying to write something that is akin to looking at two Booleans returning opposite results in the same statement.
if([item]="item1" And [quantity]>0;"Y";"")
and combine it with something like:
if([item]<>"item1" And [quantity]>0;"Y";"")
At the moment I can only get one or the other working and I can't then seem to create any further variable that would combine them because I end up with "Y" for all rows which is not correct. This is how the table might look after (mock-up in Excel):
I want to then be able to filter based on the flag results variable. Can anyone advise how I might address this problem?
You are really close. I defined count (or quantity) variables with where clauses. I created Var Select Item Count as...
=[quantity] Where ([item] = [your selected item])
And Var Other Items Count as...
=[quantity] Where ([item] <> [your selected item])
Finally, define your FLAG variable as...
=If([Var Select Item Count] > 0 And [Var Other Items Count] > 0; "Y")
Then you can filter on your FLAG variable.
Certainly, you could embed the code from the first two variables into the last one. However, I like to create my variables such that they build upon one other for easier understanding and maintenance.
Here is my example with "173" being the selected item.
I am building a report(report server project) using the Data Tools. I have a column Quantity it has a Total.
I need another column that calculate the share(%) of each line in the Quantity comparing to the Total.
The expression would be: Line_1_Share = Quantity_of_line_1/Total.
I tried =[Sum(Total/Quantity)] but it does not even accept as a valid expression.
If you right-click the textboxes that contain your working 'Quantity' and 'Total' values and look at the expressions you will see the correct format.
For exmaple your 'Quantity' expression might be something like
=Fields!Quantity.Value
or if it is in a grouped row it might be
=SUM(Fields!Quantity.Value)
your 'Total' expression might also be
=SUM(Fields!Quantity.Value)
When you use SUM() (or any similar aggregate) then the scope of the expression decides what is included in the sum. The scope can be a single row, a row group or an entire dataset. If you do not specify a scope then the position of the textbox determines the scope.
So, if you have a simple table with no grouping other than the total line and your dataset name is dataset1 then your expression would need to be
=Fields!Quantity.Value / SUM(Fields!Quantity.Value, "dataset1")
The above reads .... "For the current row, take the Quantity and divide is but the sum of all Quantities that are within the entire dataset called dataset1"
If this does not help, post your current report design including and row and/or column groups.
In an existing ssrs 2008 report, I have added a few new columns to the existing report as requested by the user. In addition, the user wants to be able to sort the data on any column on the report by using a sort parameter value.
The data does not contain any summary values. The columns in the report include:
a. student number,
b. student name,
c. birth date,
d. age,
e. current grade level,
d. attendance code value.
The default value is to sort by student name alphabetically. Whatever field is to be sorted first, the student name will be the second.
I have tried to sort the data at the tablix level and the row group level and the logic has not worked yet. There is no row group setup right now.
Thus could you show me how to setup the sort by using the parameter value? Would you show how the ssrs report needs to look for me to accomplish this goal and/or point me to link(s) that will show me how to accomplish this goal?
On the row group's Sorting, set the Sort By to use the Sort parameter to determine which column to sort, like:
=IIF(Parameters!SORT.Value = "NUMBER", Fields!STUDENT_NUMBER.Value,
IIF(Parameters!SORT.Value = "NAME", Fields!STUDENT_NAME.Value,
IIF(Parameters!SORT.Value = "BIRTH_DATE", Fields!BIRTH_DATE.Value,
IIF(Parameters!SORT.Value = "AGE", Fields!AGE.Value,
IIF(Parameters!SORT.Value = "GRADE", Fields!GRADE.Value, Fields!STUDENT_ATTENDANCE_CODE.Value)))))
Set a second SORT to use the Student_Name field.
Did you try using interactive sort. That way users can sort on any column in the table. In my experience this has worked perfectly well.
Here is more info- (the first section is what i think you would need - Sorting Detail Rows for a Table with No Groups ) -
https://technet.microsoft.com/en-us/library/cc627509(v=sql.100).aspx
Let me know if that was helpful.
Select the tablix, right click and click on Tablix Properties
Go to the Sorting Tab. Click Add (below the Change Sorting Options)
Now select the order or click expression and write an expression to sort the columns based on parameters supplied.
Click Ok
In the order select A to Z ASC or Z to A for DESC
You need to select each column and select A to Z or Z to A
For example
In the expression,
IIF(Parameters!SORT.Value = "NUMBER", Fields!STUDENT_NUMBER.Value,"")
In the order column select A to Z or Z to A
This should be easy, but I am stuck.
I have a table listing some figures about Qualifications - to achieve which a dataset that is essentially a row per Student is being grouped on Qualification with a Parent Grouping on "Measure" (which is just a bucket of qualifications).
One of the columns is trying to work out the number of students (well, more properly the number of students with a value in a particular field, weighted by another field) in each Measure/Qualification. In the screenshot below, it's the "Pred. Avg" column on the right hand side.
So for the Qualification Row Grouping, that column is calculated by:
=CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP")
This works fine - the values of 35 and 11.5 in that rightmost column are correct for those rows. What the top row should be doing is simply adding up the values in the other rows to give me the number of students in this Measure, in this case to give 46.5. To do that the expression I am using is:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP"), "Measure")
However as you can see in the screenshot, this returns 2917 instead.
So my question is; Why doesn't that work, and given that it doesn't work how can I, within a parent group, aggregate the results of aggregates inside a child group?
EDIT:
OK so, I have determined that the following works correctly:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual"), "Measure")
The problem there is that the Qual row that returns 11.5 is weighted to 0.5. I.E. it actually returns 23, and the Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") is for that row returning 0.5 and altering it to 11.5...so the question becomes; "how do I force that ...*Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") into the "Qual" scope, like the CountDistinct() is already in?
The issue here is that you're trying to aggregate values using that Lookup function which only returns one value. There are a couple ways you could go about doing this. One option would be to use the LookupSet function to get the applicable weightings. An even better option is to combine the data in your dataset so that the weighting is available without using a lookup. That way the function can recalculate an any grouping level without you having to force a scope on it. Also, CountDistinct ignores "Nothing" so you can do without the extra IIf statement. Hope that helps.
I've been struggling with an IIF error when trying to create a variable aggregate.
I'm using Report Builder 3.0
I have a report where users determine what fields are in a report. These fields are passed as a multivalue parameter. I use a lookup from a different dataset to determine its placement in the report, and using the same order dataset to determine if the field is numeric or not (meaning I want to sum the value based on row-level grouping). The headers pull in using the same field lookup, which works fine. At the row level I'm trying to return either the sum of the field value based on row grouping, or if non-numeric, return the value. Based on similar posts I understand that both the true and false parts are processed. I attempted to offset this error by nesting another IIF. If I remove the sum function the data returns non-numeric data fine. However if I include the sum function numeric data is processed fine however non-numeric data returns #error.
What am I missing?
Here is a definition of the data I'm referencing below:
lookupvalue: returns the fields selected by the user based on predefined order in a stored procedure.
Fieldisnumeric: indicates if the field selected is numeric or not, 0 is false, 1 is true
Fielditem: the field item in the tablix being referenced
dtsselectedfields: the dataset I'm looking up the column order and numeric properties of a field.
The number 1 indicates the first position in the variable count of fields selected by the user. Additional fields are hidden based on the count of fields passed in the parameter and are incremental (e.g 1-n).
=iif(Lookup(1, Fields!LookupValue.Value,
Fields!FieldIsNumeric.Value,"dtsSelectedFields")=0,
Fields(Lookup(1, Fields!LookupValue.Value, Fields!FieldItem.Value,
"dtsSelectedFields")).Value,iif(Lookup(1, Fields!LookupValue.Value,
Fields!FieldIsNumeric.Value, "dtsSelectedFields")=0,
Fields!MV.Value,sum(Fields(Lookup(1, Fields!LookupValue.Value,
Fields!FieldItem.Value, "dtsSelectedFields")).Value)))
****edit 12/1/2015****
For additional clarity, I'm providing additional details. Below is 'dtsSelectedFields' dataset.
FieldItem_____LookupValue_____FieldIsNumeric
Item1Desc__________1__________________0
Item1Total__________2__________________1
Item2Desc__________3__________________0
Item2Total__________4__________________1
Let's say I have one column of data, and this column would first look for a LookupValue of 1. This would return the FieldItem, 'Item1Desc'. Because this field is not numeric, I would want to return the value of Item1Desc. However let's assume my first selection was actually 'Item1Total' and I don't want to return the non-numeric Item1Desc field. In this case, because 'FieldIsNumeric'=1 indicating a numeric field, I want to take the sum of this field.
Is it possible to nest an aggregating function in an IIF statement on only one part of an IIF statement? I.e. the true part or false part?
And if so, what am I doing wrong?
An example of the tablix:
sample layout
Column 1 Header____________Column 2 Header___________Column 3 Header
Column 1 Data______________Column 2 Data_____________Column 3 Data
Sample data
Product___________________Country of Origin_________________Units
ABC Envelopes___________________China______________________15
LMN Packets_____________________India_______________________30
In the example above, user selects 3 columns, 'Product', 'Country of Origin', and 'Units'. There are other fields available that would cause multiple rows if I grouped by them in the stored procedure (for example acquisition price). Based on the lookup I return the column description as a header. The row-level detail is described as above (e.g. Return the product name and country of origin, but sum up the units).
As a workaround for my issue above, I found an (ugly?) solution.
As mentioned above, a user can select any number of columns and the report organizes them in columns based on a predefined order according to a stored procedure. (E.g. a product description would come before the sum of the units if those two columns were chosen, but a product ID may come before the product description, but only if the ID was chosen.)
For every possible number of columns a user can select, I added two columns in the report (i.e. two for each field).
The first two columns will reference the lookupvalue=1. I then set the expression of each field in the detail to 1) a sum of the value, or 2) the value itself. I then set the column visibility to the results of the 'FieldIsNumeric' column. So the summed numeric column which would return an error for non-numeric data would be hidden when FieldIsNumeric=0, and the non-numeric column referencing the lookup value =1 would be shown, and vice versa.
Needless to say additional columns would follow the same logic in sets of two, each referencing the sequential lookup value (e.g. columns 3 and 4 would reference lookupvalue=2, columns 5 and 6 would reference lookupvalue=3, and so forth. Each column within the matching pair would be displayed or hidden based on the returned value of FieldIsNumeric in the same lookup dataset.
I'm definitely open to suggestions, but thought I'd post this as a workaround solution.