I have a month parameter called DimTiempoMes So I when I run preview of report I select that month in combo box it can be from 1 to 12.
If I select 1 it return value of Fields!InventarioDirecto_Monto.Value of month 1
If I select 3 it return value of Fields!InventarioDirecto_Monto.Value of month 1,2 and 3 etc...
Now I want to get Average depending of selected Fields!InventarioDirecto_Monto.Value
For Example: If I selectDimTiempoMes with value10, formula will be for example:
InventarioDirecto_Monto Value / DimTiempoMes.Value
Execution: Sum(1,2,3,4,5,6,7,8,9,10) / 10
So I try next expression:
=SUM(Fields!InventarioDirecto_Monto.Value) / CINT(replace(left(Split(Parameters!DimTiempoMes.Value,"[").GetValue(3),2),"]",""))
Problem is SUM(Fields!InventarioDirecto_Monto.Value)always come with sum of 12 months values, so it always sum values of 12 months
Question is, How can I get only values that Fields!InventarioDirecto_Monto.Value return depending of selected parameter DimTiempoMes?
Some Data:
In this image I have 3,719 in first column because I use DimTiempoMes as 1: so my colum Acum who have expression should be 3,719 too because SUM(Fields!InventarioDirecto_Monto.Value) equals to 3719 and divisor equals to 1 because I search 1. So 3,719/1 = 3791 and I getting 40,593
Other Example: if I use DimTiempoMes as 4
There I should get 3719 + 3639 + 3378 + 2999 / 4 = 3433.73 and I receive 10148
Update:
I also try adding custom code like:
Function Promedio(ByVal items As Object(),ByVal meses As Object(), ByVal Valor1 As integer) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
For Each mes As Object In meses
IF CINT(mes) <= Valor1
Then ct = 1
For Each item As Object In items
If (ct = CINT(mes))
Then suma += Convert.ToDecimal(item)
End If
ct += 1
Next
End If
Next
suma = suma/valor1
If (Valor1 = 0) Then return 0 else return suma
End Function
And Expression something like:
=Code.Promedio(LookupSet(Fields!Dim_ConceptosInventario_.Value, Fields!Dim_ConceptosInventario_.Value, Fields!InventarioDirecto_Monto.Value, "DS_SubInventarioDirecto"),LookupSet(Fields!Dim_ConceptosInventario_.Value, Fields!Dim_ConceptosInventario_.Value, Fields!nPeriodo.Value, "DS_SubInventarioDirecto"),CINT(replace(left(Split(Parameters!DimTiempoMes.Value,"[").GetValue(3),2),"]","")) )
But I donĀ“t get desire results
Related
I have this Loockup custom code:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
Now I want to use in expression like:
=Code.SumLookup(LookupSet(Fields!sJerarquiaNivel2.Value,Fields!Unidad.Value,Sum(Fields!InventarioSobreVentas.Value, "DS_DataInventarioDosAniosAnterior"))
Problem is when I run project I getting:
Expression has an incorrect number of parameters for the function 'LookupSet'
What am I doing wrong? Regards
You need to close the parentheses at the end of the SUM
Try
LookupSet(Fields!sJerarquiaNivel2.Value,Fields!Unidad.Value,Sum(Fields!InventarioSobreVentas.Value), "DS_DataInventarioDosAniosAnterior")
I want to get the month name from a Do Until......Loop and display in a CheckedListBox.
I have two tables.
1. Month_Count
2. Fees_Ledger
My month name function...
Function mnthName(ByVal mnth As Integer)
Dim name As String = String.Empty
name = MonthName(mnth, False)
Return name
End Function
To get the Month Details
"SELECT FromMonth,ToMonth,MonthCount FROM Month_Count WHERE SemesterNumber='1'"
And to get the Paid Count
"SELECT COUNT(*) AS TotMonthPaidCount FROM Fees_Ledger WHERE SemYear='1' AND FeeId='1'"
So...
' Got the values from queries
FromMonth = 7 '(July)
ToMonth = 6 '(June)
MonthCount = 12 '(Loop will rotate 12 times)
TotMonthPaidCount = 1 '(FeeId 1 paid one time)
'Declaring an integer variable
Dim StartM As Integer = 1
FromMonth = FromMonth + TotMonthPaidCount
' For the first month
CheckedListBoxMonth.Items.Clear()
CheckedListBoxMonth.Items.Add(mnthName(FromMonth))
' Now the loop to achieve the goal
Do Until StartM = (MonthCount - TotMonthPaidCount)
If FromMonth >= 12 Then
FromMonth = 1
CheckedListBoxMonth.Items.Add(mnthName(FromMonth))
Else
FromMonth += 1
CheckedListBoxMonth.Items.Add(mnthName(FromMonth))
End If
StartM += 1
Loop
This Subroutine results exactly what I want.
But the problem occurs when the StartMonth = FromMonth (6) + TotMonthPaidCount (7) value >12. As 13 or 14 or 15 has no Month Name, it is showing error.
Argument 'Month' is not a valid value.
I want it like below.
What should I do ?
I have a listbox set to Multiselect property of Simple.
The listbox is populated by using a table.
There are 4 columns in the listbox
1 3/23/2014 4/5/2014 2014
2 4/6/2014 4/19/2014 2014
3 4/20/2014 5/3/2014 2014
The columns are PayPeriod, StartDate, EndDate, FiscalYear
What I want to be able to do is highlight a chunk of dates and have the first selected StartDate and the last selected EndDate populate two hidden text boxes so I can use them for my queries/reports.
I've tried a couple different ways. Each time what happens is it only uses the last item I have selected in it's calculations.
Dim ItemIndex As Variant
For Each ItemIndex In Me.lstPayPeriods.ItemsSelected
If Me.lstPayPeriods.Selected(ItemIndex) And Me.lstPayPeriods.Selected(ItemIndex - 1) = False Then
Date1.SetFocus
Date1.Text = Me.lstPayPeriods.Column(2, Me.lstPayPeriods.ListIndex)
End If
Next
In this example I tried to have it go through each Item of the listbox. I wanted to check to see if the current row was selected and the row before it wasn't. That way I could determine it was the first item selected in the group of selected items. It would always only use the last item I had selected.
Dim CurrentRow As Integer
Dim FirstDate As Date
For CurrentRow = 0 To Me.lstPayPeriods.ListCount - 1
If Me.lstPayPeriods.Selected(CurrentRow) Then
Date2.SetFocus
Date2.Text = Me.lstPayPeriods.Column(3, Me.lstPayPeriods.ListIndex)
End If
Next CurrentRow
For CurrentRow = 0 To Me.lstPayPeriods.ListCount - 1
If Me.lstPayPeriods.Selected(CurrentRow) And Me.lstPayPeriods.Selected(CurrentRow - 1) = False Then
Date1.SetFocus
Date1.Text = Me.lstPayPeriods.Column(2, Me.lstPayPeriods.ListIndex)
End If
Next CurrentRow
I tried to do something similar with this code. Again, it only uses the last item I have selected.
I am running into a wall figuring out how to accomplish my goal.
I think the issue is in your approach. I'm personally not keen on the approach you're using to determine the earliest start and latest end, though the issue might just be your column numbers: the first column in a listbox is column 0, and the last column (of 4 columns) is column 3. Accordingly in your code above, you're setting Date2 = fiscal year, not enddate.
I would however recommend a different approach to determining (a) the earliest selected StartDate, and (b) the latest selected enddate. You could have a loop for each operation, or your can encapsulate both in a function:
private function GetPayPeriodDate(baseValue as Date, findLater as boolean, colNo as long) as Date
'baseValue is the default date to test against
'findLater tells the function whether to look for < or > the baseValue
'colNo tells the function which column of data to test
Dim vv as variant
For each vv in lstPayPeriods.ItemsSelected
if lstPayPeriods.Selected(vv) then
if findLater then
if lstPayPeriods.Column(colNo, vv) > baseValue then
baseValue = lstPayPeriods.Column(colNo, vv)
end if
else
if lstPayPeriods.Column(colNo, vv) < baseValue then
baseValue = lstPayPeriods.Column(colNo, vv)
end if
end if
end if
next vv
GetPayPeriodDate = baseValue
end function
Then you can set your start and end date textboxes by calling this function:
me.StartDate = GetPayPeriodDate(CDate("31/12/2099"), false, 1)
'since startdate looks for the earliest date, the base date must be in the future
me.EndDate = GetPayPeriodDate(CDate("01/01/1900"), true, 2)
'similarly, looking for the latest date, base date must be in the past
How can I select the maximum value from a column in a listbox, and display that value in a textbox on the same form? The listbox itself is populated by a query that depends on user inputs, so its values are unknown in advance.
I could sort the listbox by value and select the first value, but it is already sorted by date on another column, for a different purpose. What I want to know is the Date on which that maximimum value occurred in column 2.
The next step is to display or all the values in column 4 which occure before that date as blank or N/A.
You may find the following VBA code helpful. It scans values inside the .Column data for a list box named List0, for example...
2013-04-18 | 123
2013-04-17 | 77
2013-04-16 | 345
2013-04-15 | 34
...finds the date (first column) corresponding to the maximum value in the second column of the list box, and puts that date into a text box named Text3. Note that the CompareNumeric flag controls whether the comparison is string-based ("77" would win), or number-based (345 would win).
Private Sub Command2_Click()
Const DateCol = 0 '' column numbers start with 0
Const MaxCol = 1 '' second column has column index of 1
Const CompareNumeric = True '' convert strings to numbers for finding maximum
Dim RowIdx As Long, MaxItem As Variant, MaxIdx As Long, CurrItem As Variant, NewMaxFound As Boolean
MaxIdx = -1
MaxItem = Null
For RowIdx = 0 To Me.List0.ListCount - 1
CurrItem = Me.List0.Column(MaxCol, RowIdx)
If CompareNumeric Then
CurrItem = Val(CurrItem)
End If
If IsNull(MaxItem) Then
NewMaxFound = True '' first one
Else
NewMaxFound = (CurrItem > MaxItem)
End If
If NewMaxFound Then
MaxItem = CurrItem
MaxIdx = RowIdx
End If
Next
If MaxIdx >= 0 Then
Me.Text3.Value = Me.List0.Column(DateCol, MaxIdx)
End If
End Sub
i have report that generates number of policies from 2 datasets.
the table is linked to dataset1.
i used the formula
CountDistinct(Fields!Policy_ID.Value)
my problem is how to get distinct count for the field Policy_ID from the second dataset "AccountingV10Dataset", specially that i have grouping Contract_Start_Month, Contract_Cover_Type, and Primary_LOB.
below a screen shot to the report design to help you to understand my request
the report should be generated as below:
I would derive the Distinct Count back in the Dataset layer e.g. in SQL. The SSRS Aggregate Functions only go so far.
I managed to solved this way:
i created the below code to calculate disting count from another dataset:
Dim suma As Decimal = New Decimal()
Public Function SumLookup(ByVal items As Object(),ByVal CountSum As String) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim ct as Integer = New Integer()
Dim PolId as Integer = New Integer()
suma = 0
ct = 0
PolId = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
If (CountSum = "SUM") then
ct += 1
Else If (PolID <> Convert.ToInt32(item)) then
ct += 1
END If
PolId = Convert.ToInt32(item)
Next
If (ct = 0) Then return 0 else If(CountSum = "SUM") then return suma else return ct
End Function
Public Function GetMyVal() as Decimal
GetMyVal = suma
End Function
and i call this function by:
=code.SumLookup(Lookupset(Fields!Contract_Start_Month.Value & "-" & Fields!Contract_Cover_Type.Value & "-" & Fields!Primary_LOB.Value,Fields!Contract_Year_Start_Month.Value & "-" & Fields!Cover_Type.Value & "-" & Fields!LOB.Value,Fields!Layer_ID.Value, "AccountingV10Dataset"),"COUNT")
Hope my solution will helpfull for other users as it did for me.
Regards,