SSRS group total with semi dirty data - reporting-services

Data is Bill of Lading where I have to report items as well as lots and counts. Actual data is sent by other system that mixes total weight of an item on each line of lot details. I receive a textual generation of each Lot # and count from that lot per line on each line. Did I say dirty data?
I have grouped in a sub tablix to show only one item at a time just fine.
Now I need to get a total weight for the truck load. How do I Sum ONLY the first value for that item and skip all the second, third,... lots that comprise this item for my Tablix summary? Data below should show 8343 in the total weight.
Usually have 2 lots per item, may only be 1 lot 10% and may be more than 2 lots 15% of the time.
Will usually have at most 4 items per truck with most 75% of all trucks holding only 1 or 2 items.
item weight LotQuantity
ABC123 4655 4502052014 - 1200, 4512052014 - 2400
ABC123 4655 4502052014 - 1200, 4512052014 - 2400
ABC122 3688 4502052014 - 600, 4512052014 - 1200
ABC122 3688 4502052014 - 800, 4512052014 - 1400
TIA

Created functions in report code:
Dim wgt1 AS Double
Function addWgt(ByVal value AS Double)
wgt1 += value
End Function
Function getWT()
return wgt1
End Function
Dim Cnt AS Double
Function addCnt(ByVal value AS Double )
Cnt += value
End Function
Function getCNT()
return CNT
End Function
In an empty column I added the current weight as well as the current count via the addWGT()
For the report footer I just put in =Code.getWT()

Related

Dimensional error when i try to read month number from file

I'm new to Octave and I am trying to read the month number of a datetime values in order to do a equation with it. The problem is every time I try to read it I get the same dimensional error and i don't know why...
Here is my code:
clear
clc
pkg load io
pkg load financial
[num,date] = xlsread('EMA_VR 2019.xlsx','A184:A215');
num=datenum(date);
DataString=datestr(date)
m= month(num,DataString)
The result is always this:
DataString =
01-Jul-2019
02-Jul-2019
03-Jul-2019
04-Jul-2019
05-Jul-2019
06-Jul-2019
07-Jul-2019
08-Jul-2019
09-Jul-2019
10-Jul-2019
11-Jul-2019
12-Jul-2019
13-Jul-2019
14-Jul-2019
15-Jul-2019
16-Jul-2019
17-Jul-2019
18-Jul-2019
19-Jul-2019
20-Jul-2019
21-Jul-2019
22-Jul-2019
23-Jul-2019
24-Jul-2019
25-Jul-2019
26-Jul-2019
27-Jul-2019
28-Jul-2019
29-Jul-2019
30-Jul-2019
31-Jul-2019
01-Aug-2019
error: horizontal dimensions mismatch (1x1 vs 32x1)
error: called from
month at line 40 column 7
Teste at line 13 column 2
Also, when I try to return the year or day it always gives me the right value, hope someone can help me, it would be very appreciated.
The month function can only handle 1x1 data. That's what your error is saying. Since your date vector is 32x1, you can't use that function the way you are doing.
However, you can use a for loop, and store the values in a vector:
[num,date] = xlsread('EMA_VR 2019.xlsx','A184:A215');
Month = zeros(size(num)); % Month will have the same dimensions as num
for i=1:length(Month) % Loops through the length of Month
Month(i) = month(num(i)); % Applies the month function to the i-th entry of num
end

Code combination in microsoft access (yyxxxx format)

I'm struggeling with a part of code that I want to implement in Microsoft Access.
The required code is used for project asignments.
The code format contains the last 2 numbers of the year + 4 digits which add up until a new year, then the last 2 numbers of the year add up with 1 and the 4 digits start at 1 again.
For example:
2019:
190001 = first task;
190002 = second task;
etc...
2020:
200001 = first task;
200002 = second task;
etc...
Could anybody help me out how to code this in Microsoft Access, preferably by VBA?
This way I can asign the code to a "submit" button to avoid similar numbers.
Thanks!
Formatting your code given an integer could be achieved in several ways, here is one possible method:
Function ProjectCode(ByVal n As Long) As Long
ProjectCode = CLng(Format(Date, "yy") & Format(n, "0000"))
End Function
?ProjectCode(1)
200001
?ProjectCode(2)
200002
?ProjectCode(100)
200100
You probably need to assign the next task id to a project.
So, look up the latest id in use and add 1 to obtain the next task id:
NextTaskId = (Year(Date()) \ 100) * 10000 + Nz(DMax("TaskId", "ProjectTable", "TaskId \ 10000 = Year(Date()) \ 100"), 0) Mod 10000 + 1
Nz ensures that a task id also can be assigned the very first task of a year.

Difference between two time values in SSRS report

I have the following select statement:
SELECT [TR_DATE]
,[TR_TIME]
,RIGHT('000000' + CONVERT(varchar,TR_TIME), 6)
,TIMEFROMPARTS(SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),1,2), SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),3,2), SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),5,2),0,0) as trtime
,[ET_TYPENO]
,[ET_NAME]
FROM [DB400].[dbo].[TRANSACTIONREPORT]
where DEPT_NAME = 'GIJIMA AST HOLDINGS (PTY) LTD'
/*and LOC_NAME = 'Front Door and Gate'*/
and TR_DATE between '20200120' and '20200130'
order by TR_DATE, MST_LASTNAME, MST_FIRSTNAME, TR_TIME
which returns the following data:
I would like to use this to calculate the time the was spent in the building.
Note that ET_TYPENO = 1 equates to "Allowed Normal In" and ET_TYPENO = 2 to "Allowed Normal Out"
I have the following expression inside an ssrs report
=iif(Fields!ET_TYPENO.Value=2,
DateDiff(DateInterval.Hour, previous(Fields!trtime.Value),Fields!trtime.Value),
"")
But it resolves to the following #Error.
UPDATE
Expected Result
Calculate the time difference between the "Allowed Nornmal In" event and the "Allowed Normal Out" event.
Take line 2 and 3 for example. "Allowed Nornmal In" occured at 07:23:19 and "Allowed Normal Out" occured at 08:55:48. I need it to return the time difference between these two times. I.E. 1:32:29.
The trtime needs to be converted to a DATE type with the CDATE() function to use the DATEDIFF function.
=IIF(Fields!ET_TYPENO.Value = "OUT",
DateDiff(DateInterval.Hour, CDATE(previous(Fields!trtime.Value)), CDATE(Fields!trtime.Value)),
NOTHING)
Also, shouldn't Fields!ET_TYPENO.Value = 1 ?
Taking the suggestion from Honnover Fist's answer that the parameter of the DateDiff need to be Dates instead of Times. (The Documentation does say that a Time will work). I have changed my query to a DATETIMEFROMPARTS() instead of a TIMEFROMPARTS().
Then I changed the condition to the below code so that the hours would be displayed more accurately.
=IIF(Fields!ET_TYPENO.Value = 2,
DateDiff(DateInterval.Minute, previous(Fields!TR_DATETIME.Value), Fields!TR_DATETIME.Value) / 60,
NOTHING)

Mean_squared_error output in function includes dtype and '0'

I want to calculate test statistics for a fb prophet forecast in a function because I want to average the test stats over different forecasts and cutoff points after using the fb-prophet cross_validation to get df_cv. I created a function that I apply to the dataframe after grouping by the cutoff points, in order to receive a measure per cutoff point. Then I calculate the mean over all these values.
The problem is that my function returns not only the value I am looking for but also a 0 as well as an information of the dtype. I can still do calculations with the returned value but when I want to plot etc. later it is very inconvenient. How can I strip these unnecessary values from the output?
def compute_avg_stats(df_cv,perf_measure):
measures = {'mse':mean_squared_error,'mae':mean_absolute_error,'mape':mean_absolute_percentage_error,'rmse':mean_squared_error}
performance_stats = {}
if perf_measure == 'rmse':
measure = np.sqrt(measures[perf_measure](y_true=df_cv['y'],y_pred=df_cv['yhat']))
else:
measure = measures[perf_measure](y_true=df_cv['yu'],y_pred=df_cv['yhat'])
return measure
df_cv.groupby('cutoff').apply(compute_avg_stats,perf_measure='rmse').to_frame().mean()
I think .mean() returns a Series. Try with .mean()[0]

Legend changing when report is deployed or exported

I have a 100% Stacked Bar chart. Students are banded based on their attendance,and the report simply tracks changes in the band populations as a percentage of the total student population. In Report Builder, this works totally fine (except in that it highlights our rubbish attendance of course...)
The problem arises when:
The report is exported from Report Builder to PDF/Word/Excel/whatever
The report is deployed to an SSRS server and run through the browser
You change to a subsequent page of the report, and then change back to the page with the graph.
In all case although the actual chart remains unchanged, the Legend loses its mind a little bit and shows the top three items as 100%:
I can't think of any reason that that should happen...the report was particularly finicky to make as a result of the underlying data structure (which regrettably is based on a Report Model, meaning I can't tweak it with SQL) and I had to use custom vb code in the end to get it to do what I wanted, but I can't see why any of that should change its behaviour either on the server or when exported.
So my question is; why does this happen, and how do I stop it happening?
EDIT: By Request:
The dataset inherently returns data in the format below. There's a row per learner ID per "Week Start Date".
The custom code I am using is pasted below (inept I know - no laughing!):
Private attendance_table As New System.Collections.Hashtable()
Private last_added_table As New System.Collections.Hashtable()
Public Function band_calc(ByVal attendance As Double) As String
REM Define the bands that I want to track
If attendance = 1 Then
Return "A"
ElseIf attendance >= 0.975 Then
Return "B"
ElseIf attendance >= 0.95 Then
Return "C"
ElseIf attendance >= 0.925 Then
Return "D"
ElseIf attendance >= 0.90 Then
Return "E"
ElseIf attendance >= 0.85 Then
Return "F"
ElseIf attendance >= 0.8 Then
Return "G"
Else
Return "X"
End If
End Function
Public Function get_attendance_band(ByVal week_start_date as String, ByVal learnerID As Integer, ByVal possibles As Integer, ByVal presents As Integer) As String
If attendance_table Is Nothing Then
Dim attendance_table As New System.Collections.Hashtable()
End If
If last_added_table Is Nothing Then
Dim last_added_table As New System.Collections.Hashtable()
End If
REM check if attendance_table has the Learner already
If attendance_table.ContainsKey(learnerID) Then
REM check if we've already added this week's data in
If attendance_table(learnerID).ContainsKey(week_start_date) Then
REM just return the band_calc for those data
Return band_calc(attendance_table(learnerID)(week_start_date)(1) / attendance_table(learnerID)(week_start_date)(0))
Else
REM Add in this week to the hashtable. Add this weeks data to the last weeks data
attendance_table(learnerID).Add(week_start_date, New Object() { possibles + attendance_table(learnerID)(last_added_table(learnerID))(0), presents + attendance_table(learnerID)(last_added_table(learnerID))(1)})
REM record that this is now the last date updated for this learner
last_added_table(learnerID) = week_start_date
REM show the band!
Return band_calc(attendance_table(learnerID)(week_start_date)(1) / attendance_table(learnerID)(week_start_date)(0))
End If
Else
attendance_table.Add(learnerID, New System.Collections.Hashtable())
attendance_table(learnerID).Add(week_start_date, New Object() {possibles, presents})
last_added_table.Add(learnerID, week_start_date)
Return band_calc(attendance_table(learnerID)(week_start_date)(1) / attendance_table(learnerID)(week_start_date)(0))
End If
End Function
For the series properties; The sort, group and label (which defines the Legend obviously) are all set to this: