SSRS insert exact specific value in a cell of a Matrix using expression - sql

I'm not sure if my question is really stupid, but I found nothing on the internet...
Is it possible to insert a specific value in a cell of a matrix?
for example I have a dataset like below:
Month Prod Amount
2 X 34$
11 Y 12$
7 Z 150$
and a matrix like:
-------| Month |
Prduct |SUM(Amount)|
So the row group are products and column group are the months of a specific year.
If I want to add an extra column, with a specific value chosen dynamically from the amount (for xample 150$) so to have
-------| Month |columnName
Prduct |SUM(Amount)| 150
is that possible? also if the value is repeated through the column (it would be useful if I wanted the new column to have this specific value added for each value)
thanks a lot!! :D

You can insert a value directly in your matrix but it will be repeated for each record.
The best way is to add a new column with conditional values is to do this in your dataset query. Probably with a CASE statement if you are using SQL.
EDIT: If you can't adjust the query for whatever reason, you can add the new column and use SWITCH function inside your textbox to achieve the same.

Related

Conditional styles on a calculated value in Cognos

I have a report (Pivot table) for which I have a value everyday. My goal is to calculate the variance every day and highlight with conditional styles.
1 jan. 23
2 jan. 23
3 jan. 23
5
25
42
I have a query who calculates the variance between days in % (which I dont want to put in the report).
My conditional style rule is [Table].[Pourcentage variation D-1] between 0,05 and 10.
Since my request is not in displayed my report, I have this error :
RSV-VAL-0032 The following expression is not valid. If the item exists
in a query but is not referenced in the layout, add it to a property
list.
The problem is that I don't have the "Proprety list" in my pivot table like in can have in a Data table.
How can I highlight my variance based on a request that I dont display in my Pivot table ?
Thanks for helping
Add the calculated field to the pivot table (I know you do not want this in the layout, this is just to test if that removes the error). See if the conditional style works the way you expect.
If so, change the column for the percentage data item to property, set box type to none. This way it is still something that can be referred to, but is hidden from the final result

Populate NULL Values based on Array Formula

New user, so apologies in advance for bad formatting.
Essentially what I'm trying to do is be able to populate the staff_hours column where it equals NULL with the one value that IS NOT NULL. As you can see from the screenshot, there will only be one person who staffs an open cl_hole_staffing_no and as a result will have a start_dt (with time) and end_dt (with time) along with staff_hours. 16 people were offered a shift, and the person in row 15 accepted it is what is going on here.
The ideal output would be the staff_hours column is populated with the amount of time of the one person who ended up taking the open job, so 24.00 in this example. How can I write a formula to do this? I was thinking something like an array function in Excel, but am not sure how to do that in SQL.
Your explanation is a bit confusing about what you are really trying to achieve. However I think that what you really want is just to populate the staff_hours column, which can be achieved with the following:
UPDATE
your_table_name
SET
staff_hours = 24
WHERE
staff_hours is NULL;
EDIT
I get it now. You want to operate with the two dates and extract the amount of hours between them. Since you are in sql-server you can actually define a Computed Column in which you can use the values from other columns to compute the value you want.
You will need to create your table again. (The example below contains only the necessary attributes for it to work)
CREATE TABLE your_table_name
( id INT IDENTITY (1,1) NOT NULL
, staff_start_dt DATETIME
, staff_end_dt DATETIME
, staff_hours AS DATEDIFF(hh, staff_start_dt , staff_end_dt)
);
Now every time you insert a record on the table with both staff_start_dt and staff_end_dt, the column staff_hours will automatically compute the number of hours between the two dates.
[pre]
Code (vb):
A B C
1 10 X X
2 11 A Y
3 12 Y Z
4 13 B
5 14 B
6 15 Z
[/pre]
Assuming that the rows in Col A is Named "datarange"
And your criteria is in C1:C3
The following formula will return an array {10,12,15}
=SMALL(COUNTIF(C1:C3,B1:B6)*datarange, ROW(INDEX(A:A,SUMPRODUCT(--(COUNTIF(C1:C3,B1:B6)=0))+1):INDEX(A:A,ROWS(datarange))))
COUNTIF(C1:C3,B1:B6)*datarange returns {10;0;12;0;0;15}
The segment ROW(INDEX(....):INDEX(...)) returns {4;5;6}, indicating the number of non-zero values.
The SMALL() function then returns the 4th smallest, 5th smallest and 6th smallest values.
One disadvantage with this approach is that you get a sorted sub-list. Perhaps that would work for you.

SSRS stacked graph with missing x-axis values going to zero

I have 3 columns (DateTime, GroupName, Value), some of these groups are closely related and I would like to display these in a stacked graph. The problem I am facing (I THINK) is that I don't have entries for all groups at all times.
(cannot find a decent way to add a table, so here is some code)
Datetime Groupname Value
1 a whatever
1 b whatever
1 c whatever
2 a whatever
2 b whatever
3 a whatever
3 b whatever
3 c whatever
4 b whatever
So in the example I don't have an entry for C at time 2. And I also don't have an entry for A and B at time 4.
Resulting in:
edit: added to onedrive link
With my limited SQL skills I am not sure how to fix this. How do I get the graph to connect the points from the DateTime points where we do have data, and ignore DateTime points where we do not have data?
11-07-2016 Edit
Ok, so here some pictures of the actual data
No rep - Onedrive it is
https://1drv.ms/f/s!AhKMFQBAmZ7GgYEMzdpTBvuXTi5gAQ
the graph looks different than my first example because I set the X-axis to scalar.
On 7/5/2016 and 7/6/2016 (month/day/year notation) the CH3 is low and 0. If I remove CH3 from results the graph looks ok.
#sqlandmore.com
This is the query. Very basic.
Data is coming from a database were the datetime is not in a proper datetime format so thats gets converted into the wimsview.
SELECT
WimsView.TagID
,WimsView.SampleDateTime
,WimsView.SampleValue
,WimsView.TagName
FROM
WimsView
WHERE
WimsView.SampleDateTime > N'07/4/2016 00:00:00'
AND ((WimsView.TagName LIKE N'%MBA%') OR (WimsView.TagName LIKE N'%MBB%') OR (WimsView.TagName LIKE N'%GF1_DPC%')OR (WimsView.TagName LIKE N'%KF1_DPC%')OR (WimsView.TagName LIKE N'%CH3_DPC%'))
AND WimsView.SampleValue IS NOT NULL
You can't ignore specific values on the graph.
you can either change your select statement not to include them
you can calculate an "average" (if possible) for the missing value in order to fill the missing "points" in your graph
or another calculation (i.e - same value as previous one on the graph)
whatever you decide - it should be handled on a query level, not on a drwaing level

Excel VBA data manipulation

My problem might be simple but i have been stuck on it for a while. I have a list of accounts in column B (XXXXXX). Then in column D i have a quantity of contracts traded. In the column E i have the prices of those contracts. The column next to it has the name of the product traded.
The way i get the raw data i sometimes get a trade split in 2 parts. For example i might have on one row for the same (column B) account XXXXXX , QTY(Column D) 2 and Price(column E) 5.23$ and security(column F) NKE. In the next row i have the same account XXXXX , QTY is 3 , Price is same and the security is same. I want something that will loop through the entire data and add the QTY to 5 and keep everything else the same. So at the end i should have one row with with account XXXXXX with QTY 5 Price 5.23$ and Security NKE. I have tried pivot tables but it adds the price of the security to 10.46$ and that messes up calculations. I cannot figure what sort of a macro i should use. Can someone please help. I am posting a picture to help understand the problem. THanks. enter image description here
A pivot should show you what you want. Don't put Price in VALUES. Account, Security and Price can go in ROWS then Sum of Quantity in VALUES. That should give you the breakdown you're after.
Choose the most unique column (probably F).
Filter your data by this column.
Make an infinite loop. Inside the loop:
declare a variable for row number
check if the current row has the same value in column F as the row below
if yes, add quantities in first row and delete second row
if no, add one to row number and check if there is something in the current row. If no, exit the loop.
To the person who posted a macro. Can you please repost? I was just writing a note to you and I see you deleted the comment

Average Distinct Values in a single column in Power Pivot

I have a column in PowerPivot that basically goes:
1
1
2
3
4
3
5
4
If I =AVERAGE([Column]), it's going to average all 8 values in the sample column. I just need the average of the distinct values (i.e., in the example above I want the average of (1,2,3,4,5).
Any thoughts on how to go about doing this? I tried a combination of =(DISTINCT(AVERAGE)) but it gives a formula error.
Thanks!!
Kevin
There must be a cleaner way of doing this but here is one method which uses a measure to get the sum of the values divided by the number of times it appears (to basically give the original value) then uses an iterative function to do it for each unique value.
Apologies for the uninspired measure names:
[m1] = SUM(table1[theValue]) / COUNTROWS(Table1)
[m2] = AVERAGEX(VALUES(Tables1[theValue]), [m1])
Assuming your table is caled table1 and the column is called theValue