I have a query that gives me the daily status of an item based on desired date range (parameters). This status will vary and can repeat. For example, it can chronologically be: Operational, Repair, Inspection, Operational, Inspection. As you can see Operational & Inspection are represented twice but at different times. While this is true, I cannot seem to get this represented graphically in a Range Bar Chart because it will only display one instance of each status (as shown in the picture). The picture indicates where the remaining status should be presented.
Range bar Chart Error
The data set I am working with is as follows:
Range bar Chart Error Data
As you can see, the chart should represent 4 status in the following order: Inspection, Operational, Repair, Operational but does not display the 2nd Operational status.
Can anyone assist me to overcome this particular hurdle or is this not possible?
This should point you in the right direction... This is how I would probably approach it.
You need to add an additional column to your dataset. I replicated your dataset into a table variable and then used the following to get the additional column
-- this just replicates your data..
DECLARE #t TABLE(StatusDate DATE, StatType varchar(20), statStart DateTime, statEnd DateTime, StatusDays int)
INSERT INTO #t VALUES
('2017-02-16', 'Inspection', '2017-01-30 12:49:14', '2017-02-21 12:49:14', 22),
...
...
('2017-03-14', 'Operational', '2017-03-01 11:49:11', '2017-04-19 15:19:48', 49)
-- the important bit
SELECT
*
, DENSE_RANK() OVER(ORDER BY statStart) as Sort
FROM #t
This gives us the following output.
We can use this extra field in SSRS to group and sort the data correctly.
I then used the following expression for the chart series color property to make sure that the colours are consistent with the statType
=SWITCH(
Fields!StatType.Value = "Inspection", "Tan",
Fields!StatType.Value = "Operational", "Green",
Fields!StatType.Value = "Repair", "Red",
True, "Blue"
)
(the Blue line is there in case we are missing a type, it'll show on the chart n blue.)
This gives us..
Hopefully that will give you enough to go on.
Related
I would like to display plan and fact cumulative data series in a dashboard with a bar and line combined chart and a table next to each other using Power BI Version: 2.59.5135.781 64-bit (2018. June) edition.
My DAX formula looks like this:
CUMULATIVE_FACT = CALCULATE(
SUM('FACT_TABLE'[FACT_VALUE]);
FILTER(
ALL('DATES');
'DATES'[YEAR]=MAX('DATES'[YEAR]) &&
'DATES'[DATE]<=MAX('DATES'[DATE])
)
)
Which works fine and gives a result as such (bars displayed as TÉNY refer to cumulative fact)
The cumulative plan (line referred to as TERV) series is identical to this but with plan figures. Also you can change the year so the aggregation only runs for the current year.
However, I would like to display either null (blank) or zero values for the fact series after a certain date which is given as a parameter. This parameter value is stored in a table with a single column and single row in a date type value.
So I modified my formula as such
CUMULATIVE_FACT = IF(VALUES('DATES'[DATE])<= MAX(PARAMETER_TABLE[PARAMETER_DATE]);
CALCULATE(
SUM('FACT_TABLE'[FACT_VALUE]);
FILTER(
ALL('DATES');
'DATES'[YEAR]=MAX('DATES'[YEAR]) &&
'DATES'[DATE]<=MAX('DATES'[DATE])
)
); 0)
The formula works fine for the chart but my table visual gives an error.
So the chart looks okay, perfectly the way I would like to display it, but the table gives back a 'A table of multiple values was supplied where a single value was expected' error message
Error message:
The column referred to in the message is basically the CUMULATIVE_FACT measure, I just changed it for ease of understanding. I tried with BLANK() instead of 0, but it looks the same.
No idea why it is not working with the table visual. Any ideas?
The problem is coming from this piece:
VALUES('DATES'[DATE])
This returns all values in the current filter context, not just a single one. That's why you're getting
A table of multiple values was supplied where a single value was expected
when you try to compare it to MAX(PARAMETER_TABLE[PARAMETER_DATE].
It works in the chart since VALUES('DATES'[DATE]) is always a single value that corresponds to the month on the axis, whereas the table has a total line that encompasses multiple months.
I think if you just turned off the total line, it would be OK. Otherwise, change VALUES('DATES'[DATE]) to an expression that returns a single date in the way you want. For example, MAX('DATES'[DATE]) might work.
I need to create a SSRS report to present actual start date vs. planned start dates for milestones of a project (selected as input parameter)
The chart should look like this:
I have created the table in a separate table. However, I don’t know which chart type should I use and how do I have to set up the chart? (Chart Data, Category Groups and Series Groups).
(Data comes from SQL Server, SSRS Version 14.0.1016.285; SSDT 15.6.4)
Many Thanks in advance
This might look a bit long winded but it's fairly simple so stick with it :)
To start with I did not know your data structure so I've just made some assumptions. You may have to rework some of this to get it to fit but I've tried to keep it simple.
The approach will be to use a subreport to plot the dots and a main report to show the overall table. With this in mind, as we will have more than one dataset referencing our data I added some tables to my sample database before I started wit the following.
The first is a simple table containing months and years, you could a use view over a date table if you have one but this will do for now.
CREATE TABLE prjYearMonth (Year int, Month int)
INSERT INTO prjYearMonth VALUES
(2018, 8),
(2018, 9),
(2018, 10),
(2018, 11),
(2018, 12),
(2019, 1),
(2019, 2)
Next is the project milestone table
CREATE TABLE prjMileStones (msID int, msLabel varchar(50), msPlannedStart date, msActualStart date)
INSERT INTO prjMileStones VALUES
(1, 'Milestone 1', '2018-10-30', '2018-12-13'),
(2, 'Milestone 2', '2018-11-12', '2018-12-10'),
(3, 'Milestone 3', '2018-10-21', '2018-12-25'),
(4, 'Milestone 4', '2018-10-18', '2018-11-28'),
(5, 'Milestone 6', '2019-01-08', '2019-01-29')
OK, Now let's start the report...
Create a new empty report then add a dataset with the following query
SELECT
*
FROM prjYearMonth d
LEFT JOIN prjMileStones t on (d.Year = YEAR(t.msPlannedStart) AND d.Month = Month(t.msPlannedStart))
or (d.Year = YEAR(t.msActualStart) AND d.Month = Month(t.msActualStart))
Now add a matrix item to the report. Add a Row Group that groups on msLabel.
Next add two Column Groups. First a group that groups on Month and then add a parent group that groups on Year.
Add columns on the row group so that you end up with 4 columns msID; msLabel; msPlannedStart; msActualStart.
Finally (for now) set the Expression of the Month field (the one in the column header) to be
= Format(DATESERIAL(2017, Fields!Month.Value, 1), "MMM")
This will just give us the month name rather than the number (the 2017 is irrelevant, any year will do). Now just format as required.
You report design should look something like this..
If we run the report now we will get this..
Now to plot the dots...
For this we will create a small subreport. The subreport will accept 3 parameters. Year, Month, msID (the milestone ID from your main table). We will need the data in a slightly different structure for this sub report but the work can be done in the dataset query so nothing new is required in the database itself.
So, create a new report, let's call it _subMonthChart.
Next add a dataset with the following query..
DECLARE #t TABLE(msID int, msLabel varchar(50), PlannedOrActual varchar(1), msStartDate date)
INSERT INTO #t
SELECT msId, mslabel, 'P', msPlannedStart FROM prjMileStones
UNION ALL
SELECT msId, mslabel, 'A', msActualStart FROM prjMileStones
SELECT
1 AS Y, Day(msStartDate) as Day, PlannedOrActual
FROM prjYearMonth d
LEFT JOIN #t t on (d.Year = YEAR(t.msStartDate) AND d.Month = Month(t.msStartDate))
WHERE [Year] = #Year and [Month] = #Month and msID = #msID
Your report should now have 3 parameters that were automatically created, edit all three to Allow Nulls.
Note: The Y in the dataset is just some arbitrary value to help plot on the chart,. I will set the Y axis to range from 0 - 2 so 1 will sit in the middle.
Next, add a line chart with markers. Don't worry about the size for now...
Set the Values as Y
Set the Category Groups as Day
Set the Series Groups as PlannedOrActual
Right click the horizontal Axis, choose properties and set the Axis Type to Scalar, switch off 'Always include zero' then set Min = 1, Max = 31, Interval = 1, Interval Type = Default.
Note that for data in months that don't have 31 days the plots points will not be accurate but they will be close enough for your purposes.
Right click the Vertical Axis, choose properties and set the Mn=0, Max=2, Interval = 1, Interval Type = Default
Next, right click on one of the series lines and choose properties. Set the marker to Diamond, the marker size to 8pt and the Marker Color this expression =IIF(Fields!PlannedOrActual.Value = "P", "Blue", "Green")
The report design should look something like this... (check the highlighted bits in particular)
Now let's quickly test the subreport, based on my sample data I set the parameters to 2019, 1 and 5 and get the following results....
As we can see, our two dates that fall in January for this milestone were plotted in roughly the correct positions.
Nearly there...
Next right click on both Axes and turn off 'Show Axis' so we hide them.
Now resize the chart to something that will fit in the main report cell. In my example I set the size to 2cm, 1.2cm and moved it top left of the report. Then set the report to be the same size as the chart (2cm,1.2cm again in my case).
Save the sub report and go back to your main report...
For the 'Data' cell where the rows and columns intersect, set the size to match the subreport size (2cm, 1.2cm) then right click the cell and insert subreport.
Right click the newly inserted subreport item and choose properties.
Choose _subMonthChart as the subreport from the dropdown.
Click the parameters tab. Add an entry for each parameter (Year/Month/msID) and set its value to be the corresponding field from the dataset.
FINALLY !!!! Set the border on the cell containing the subreport to have borders all round, just so it matches your mock-up..
Your report design should now look like this...
Now when the report runs, it will pass in the month, year and milestone ID to the subreport in each cell which in turn will plot the dates as required.
When we run the report we should finally get this...
This may need some refining but hopefully you can get this going based on this. If you have trouble I suggest you recreate this example in its entirety, get it working and then swap out the database parts to fit your current database.
i have a stored proc returning inventory amounts between a start and end date.
the QTY field shows on-hand inventory adjustments by date, either IN or OUT.
i have a "run balance" field that needs to show the total QTY each day. if the InOut field is 0, it's QTY in. if it's a 1, its QTY out. the values reflected in In and Out are coded that way.
EXAMPLE. if i start on 4/1/14 with 5216. then 1061 of product is made on 4/1/14 i need the run balance to take 5216 and add 1061 on the next line. the next line should read 6277 instead of 1061. then if some is shipped, take 6277 and subtract, and so on.
i tried the running value on QTY, but it just repeats the QTY. doesn't calculate anything.
=RunningValue(Fields!QTY.Value,Sum,"Details")
i tried to post an image of my report preview, but i don't have the reputation ;-)
any help would be MUCH appreciated.
EDIT: OK, i tried this code block:
= Switch(RunningValue(Iif(Fields!InOut.Value = 0, Fields!QTY.Value,0),Sum,"Details"),
RunningValue(Iif(Fields!InOut.Value = "1", Fields!RunBalance.Value - Fields!QTY.Value,0),Sum,"Details"))
and i am getting a 0 on the sum fields, and #Error on the subtraction fields. but, i think this is more the direction i need to go (i hope)....but i am still not getting it.
There are a couple of things to look at here.
First, you specify the Scope of "Details" in your RunningValue expression... By default this group will have no grouping value, i.e. each row in the dataset will be in its own group. Which means the RunningValue will only ever be applied to one row only. Change the Scope to "MyDataset" or Nothing, whatever is appropriate.
Secondly, you need to consider how the InOut field affects the RunningValue.
I have created a simple Dataset:
And a simple table:
The Balance expression is:
=RunningValue(IIf(Fields!InOut.Value = 0, Fields!QTY.Value, Fields!QTY.Value * -1)
, Sum
, Nothing)
You can see this changes the Scope from your original statement, and also applies a multiplier to QTY based on InOut.
Works OK for my sample data:
I have a table in SSRS, with income from two campaigns.
My columns are:
serialnumber
DateOfPayment
PaymentAmount
DaysSinceCampaign
Campaign
I want my chart to plot a running total of paymentamount by DaysSinceCampaign for each campaign (bs13 and bs12). I'm pretty close, as shown above - but for some reason, the BS13 campaign starts at 20,000, appearing to be adding on to BS12 - when it is supposed to start at 0.
In the Values section for Chart Data, I have used this formula:
=RunningValue(Fields!PAYMENTAMOUNT.Value,SUM,nothing)
I have tried changing 'nothing' to "campaign", and have tried defining 'Campaign' as a row group and a column group - but it keeps returning the same error: that the scope parameter must be set to a string constant equal to a containing group.
The scope here needs to be the name of the Series Group you set up in the chart, not the Column Group of the Tablix that is set up below, something like:
I created a simple test based on:
With the Chart data expression set to:
=RunningValue(Fields!PaymentAmount.Value, Sum, Nothing)
I got the following:
Which is incorrect, but similar to what you're seeing.
If I change the expression to:
=RunningValue(Fields!PaymentAmount.Value, Sum, "Chart1_SeriesGroup1")
I get the following:
Which is correct, so it seems like you're just going to have to set the Scope to the correct Series Group name.
Okay so let's walk through a problem I have and see if someone can help me out. I am creating a matrix report in SSRS 2012 (VS 2010). I am choosing to collapse a column group and have the default 'visibility' of columns as 'Hide' and can be toggled by a text box. Now I have the rows containing states and the data field containing a value field. Now the default of SSRS is to sum up the data field when the the 'Column Group' is collapsed.
Part 1 issue:
That is great, however I would like it to say: 'Totals' instead of showing a blank. When I apply an expression to the field to be something like
=IIF(Fields!Code.Value = "", "Totals", Fields!Code.Value)
It then applies it ONLY to the column I expand, NOT the totaled parent group header. Any ideas how to get around this?
Part 2 issue:
The default of SSRS is to show BLANK CELLS AND BLANK HEADERS if part of your dataset DOES not have a column you specified in your collection. You can easily solve this by clicking the 'Column Grouping' property. Clicking Visibility and changing 'When the report is initially run:' to an expression like:
=IIF(IsNothing(Fields!Code.Value), false, true)
Now I have gotten rid of my blank headers and cells but now my main grouping when collapsed is now gone.
All I want is this with my data:
COLLAPSED
Place|Total(s)
AL|2
AZ|1
OR|
WA|7
EXPANDED
Place|A|B
AL| |2
AZ|1 |
OR| |
WA|5 |2
THE DEFAULT OF GROUPING IS SO FAR LIKE THIS:
Place|(BLANK)
AL|2
AZ|1
OR|
WA|7
EXPANDED
Place|(BLANK COLUMN)|A|B
AL| | |2
AZ| |1|
OR| | |
WA| |5|2
You can make a simple test data sample for this example loading up SSRS with any datasource you choose and just populating a table variable for this example:
declare #Temp table ( Place char(2), Code char(1), Value int)
insert into #Temp values ('AZ', 'A', 1), ('AL', 'B', 2), ('WA', 'A', 5),('WA','B',2),('OR', null, null)
select *
from #Temp
Okay so basically I scoured the internet and am finding that SSRS wants things it cannot equate to be there. EG: Headers that have null values are where the problem lies in that SSRS assumes a null you do not want to have values for and thus when you do the totals it wants to show an unknown. You can trick it in the backend though, however it takes some work.
Essentially in the simplest terms you want to take your data collection and identify the nulls as zeros so they can be recognized. Therefor I do a grid layout accounting for the nulls to be then shown as zeros in a CTE, I then take that CTE and unpivot it to get back essentially what I originally had. However the key difference is now that the values for nulls are represented as zeros. You may say: "But then you get zeros on your grid and why would I want that?" Well you can do some formatting principles in SSRS to trick that too.
Let's walk through my example above and change some things to show how the whole process works and I will add color background expression formatting too as that is something someone wanted as well.
_1. Lets take our code and show a before and after for our data set.
SQL CODE
declare #Temp table ( Place char(2), Code char(1), Value int)
insert into #Temp values ('AZ', 'A', 1), ('AL', 'B', 2), ('WA', 'A', 5),('WA','B',2),('OR', null, null)
select *
from #Temp
order by Place
;
with a as
(
Select
Place
, sum(Case when Code = 'A' then Value else 0 end) as A
, sum(Case when Code = 'B' then Value else 0 end) as B
from #Temp
group by Place
)
select
Place
, Code
, Value
from a
unpivot(Value for Code in (A, B)) as unpvt1
order by Place
_2. Ignore the first set but use the second (remove the select * from #Temp order by Place) in an SSRS report as your data set
_3. Set up a matrix report with the Place being the rows, the Code being the column, and the Value being the data
_4. Set up an expression to hide the columns if there is nothing in them now by right clicking the 'Columns Groups'(Should be Code showing example)> Click Group properties>Click Visibility>Click Function tab under first section: (You can also toggle this if you want as well as I did on another text cell)
=IIF(IsNothing(Fields!Code.Value), false, true)
_5. Click the 'Code' Column then Click the gray bar above it. Click insert column to the right and then populate the header with 'Totals' and the cell with '[Sum(Value)]' to give you a totals. I could not for the life of me get an expression to show the totals header different if it summed up in place. This method just shows the totals either collapsed or not.
_6. Now if you preview the zeros may show and we do not want that in all cases so let's manipulate the text value a little bit. Right Click the 'Value' under 'Code' and select 'Text Box Properties'. Click 'Number' on the left pane. Check the checkbox for 'Show zero as: ' and select ' ' (nothing). Now your zeros are gone.
_7. Now I have pretty much what I originally wanted but want to dynamically color code the cells based on what the header shows. Get the properties of the cell value under the code header and select 'background color'>Hit the dropdown and choose expression. Put in this expression:
=IIF(Fields!Code.Value = "A", "Wheat",
IIF(FIelds!Code.Value = "B", "LightBlue", "White"))
I now can get something that for some reason most people on the internet make sound almost impossible. I can set my columns to be a consistent color as the positioning is now tied to a value that is there as a zero but hidden now to the end user.
But you may say: "Great but I want money values not simple ints". I can do that too. Hit the properties for 'value' cell under 'Code' and look at the 'format' property. It should default to this:
0.00;(0.00);''
If you want money do this instead:
$###,##0;0.00,''
I hope this helps someone and keep in mind too if you are saying: "That is great for small data sets but I have a million or more rows I want to do something like that on." Well I would replace my cte for a temp table or permanent table and dump your data to either memory or a permanent table to massage it first.