Total of LOOKUP function in SSRS - reporting-services

For each group in SSRS (Countries, cities...) I calculate sales divided by exchange rates:
Sum(Fields!Net_Sales_Amount.Value)/LOOKUP(Fields!Country.Value, Fields!Country.Value, Fields!RATE.Value, "Currency")
How I can create Total of this sum (sum for last group - countries)?
Each solution that I found show how to do it only for alone LOOKUP function. I need to divide field by it.
Here is layout of my report:
and structure:
To calculate sales for country I just need to sum sales and divide it by LOOKUP function, but I couldn't do it for Total. I need to some below values.

I think you just need to change which data you are summing together, as it looks like you are simply finding exchange rates?
If this is the case, you should be able to just use
=Sum(Fields!Net_Sales_Amount.Value/LOOKUP(Fields!Country.Value, Fields!Country.Value, Fields!RATE.Value, "Currency"))
in your total textbox, which needs to be outside the group you are using to show the individual values.
If you want to lookup a lot of values and then sum them all together however, this is a little more complex.
Rather than using lookup, you will need to use lookupset, which uses the same syntax but can return more than one value. There is, however, no built in function that can sum these returned values up, as the values that get returned in the lookupset function are actually objects rather than numbers. As such, you will need to use custom code.
Open up your Report Properties and then the Custom Code window, into which you can paste the following:
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
This can then be used in a textbox as an expression:
=Code.SumLookup(LookupSet(Fields!Country.Value, Fields!Country.Value, Fields!RATE.Value, "Currency"))
which you can use alongside other numeric values for aggregations or calculations.

Related

How to get the value of the selected cells that you pass through arguments as numbers?

When Doing This Add Total Function I Made When It Adds The Selected Cells It Says That The Result Was Not A Number, But The Cells Selected Only Have Numbers.
function ADDTOTAL(ref1, ref2) {
var Number1 = ref1;
var Number2 = ref2;
var Number = Math.floor(Number1+Number2);
return Number;
}
It returns #NUM! and says the result wasn't a number, I'm new to this and have no idea what it is.
Issue:
I managed to replicate your issue.
You are either passing strings instead of cell references:
or the values of the cells you use as references are strings. For example "3 "
is a string because it has an extra space but also 3 is formatted as string:
Either way you pass strings but the arguments need to be numbers since you are doing a mathematical operation.
To make sure that the value of a cell is a number, do =ISNUMBER(A1). If that returns TRUE it means that the value of A1 is a number. To convert a string number into an actual number select the cells and go to Format => Number => Number on the top menu.
Keep in mind that if you add two strings together like "3" and "1" you won't get 4 but 31. I deliberately changed the format to plain text. In this case again =isnumber(A1) would be FALSE:
Solutions:
Assuming that the cells are actual numbers, you have the following options:
You pass the cell references:
You pass number arguments:
Last but not least, you can use parseFloat to convert the input arguments into numbers:
function ADDTOTAL(ref1, ref2) {
var Number1 = parseFloat(ref1);
var Number2 = parseFloat(ref2);
var Number = Math.floor(Number1+Number2);
return Number;
}

Triggering a checkbox set based on multiple values in mulitple fields FM Pro 15 Adv

We have a situation whereby we need to establish a clausal function querying data from two fields.
We have an 'Item Purchased' field, and five second hand item fields (SH Item 1, SH Item 2, etc). If either (or both) of these fields contain one of a list of specific products by name, a checkbox is enabled (ticked) which in turn triggers conditional formatting.
We have the checkbox and the formatting in place, but I can't find an eloquent means to make an IF query using Case or PatternCount etc to trigger the checkbox - I'm a little out of my depth!
I've attempted (successfully) to use a simple nest of IF statements to trigger the checkbox
but there must be a better way to trigger a 'true' result over a list of values, rather than copying repeating it i.e (Item Bought="Roland"; "Yes"; (sh item 3="Roland"; "Yes"; etc:
If(Item Bought="Orla"; "Yes"; If(sh item 1="Orla"; "Yes"; If(sh item 2="Orla"; "Yes"; If(sh item 3="Orla"; "Yes"; "No")))
I was hoping to learn of a better way to query the presence of a dozen or so discrete values over several discrete fields.
The quick fix for your issue could be:
Let (
values = List ( Item Bought ; SH Item 1 ; SH Item 2 ; SH Item 3 ; SH Item 4 ; SH Item 5 )
;
not IsEmpty ( FilterValues ( "Orla" ; values ) )
)
This will return a result of 1 (True) if any of the listed fields contains the value "Orla", 0 (False) otherwise - so you can use it directly as the formula for conditional formatting.
However, as I stated in a comment above, this is not a good solution overall.
Sounds like you can easiest use an OR operator between the criteria in your IF or CASE statement to get what you want. Also, check out the Filtervalues function as it looks to be relevant to your need.

How to Auto-Populate Dates Between Two Given Dates in Google Sheets

I have been trying to achieve what has been explained on this link.
I have two dates in a Google Sheet. One start date and another end date (in a cell). I want now to populate all the dates between these two dates in a row. The link above explains how to do it in a column but doesn't explain how to do in a row.
I have tried many things. I learnt about R1C1 notation and my last attempt was with:
=ArrayFormula(edate(B2,COLUMN(R[0]C[0]:indirect("R[0]C[" & datedif(B2,B3,"M") & "]", false))))
But it returns parsing error. What is possibly wrong with my code?
I recommend to use custom function alternative:
where DATES_BETWEEN is defined as follows:
function DATES_BETWEEN(dateFrom, dateTo) {
Logger.log(dateFrom);
Logger.log(dateTo);
var t = dateFrom.getTime(),
tMax = dateTo.getTime(),
values = [];
while (t <= tMax) {
values.push(new Date(t));
t += 24000 * 3600;
}
return [values];
}
The function should return 2d-array to fit as a single row cells.
Does the folloing work for you?
Place "transpose" in the formula from the link you referred to:
Original formula at link: =ArrayFormula(TO_DATE(row(indirect("A"&A2):indirect("A"&B2))))
With TRANSPOSE: =ArrayFormula(TRANSPOSE(TO_DATE(row(indirect("A"&A2):indirect("A"&B2))))

How to get specific cell value in SSRS grouping?

I am making an SSRS report using SQL Server Report Builder. I have column and row grouping as follows :
I want to pick up the row that is highlighted in the red box below. How do I access that specific cell and display its value in some other table in the report? As you can see the value that I want to access is a column grouping total.
Use 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
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
return suma
End Function
Then in the cell where you want to reference the value:
=Code.Sumlookup(lookupset("2073/074",Fields!FiscalYear.Value,Fields!Value.Value,"DataSet"))
*
lookup("2073/074",Fields!FiscalYear.Value,Fields!Alfa.Value,"DataSet"))
As the cell you want does not have a specific design time name, you won't be able to reference it directly. You'll have to recalculate the value in your second table. You'll have to determine the criteria but assuming it always the last fiscal year and Particular = fixed percentage... then...
You should be able to do it with something like (untested)...
=SUM(IIF(Fields!FiscalYear.Value = Last(Fields!FiscalYear.Value) AND Fields!.Particular.Value = "Fixed Percentage of Gross Income [c=(axb)]", Fields!Value.Value,0))

Find result then range and copy

I'm having some trouble trying to make a function that acts like vlookup but returns a range rather than a cell
The data to search through looks like this
Sometimes there is a space separating sometimes not
What I would like to do is to look up 16 from my main page and return all the values in that range.
the code I currently am using will only return the first line in a messagebox
Public Function findrulepos(target) As Range
Dim ruleStart, ruleEnd, ruleEnd2 As String
Dim RuleRange As Range
'Dim ruleEnd As Range
MaxRule = 100000
MaxRow = 100000
Set target = Sheets("main").Range("E2")
Sheets("ResRules").Select
For i = 3 To MaxRow
If CStr(ThisWorkbook.Sheets("ResRules").Range("A" & i).Value) = _
CStr(target.Value) Then
ruleStart = _
ThisWorkbook.Sheets("ResRules").Range("A" & i).Offset(0, 1).Text
Exit For
Else
End If
Next i
End Function
If we can assume that the numeric group labels in col A are sequential, then I think this will achieve what you need:
Enter the numeric label you are wanting to extract (16 in your example) into cell E1
Note that =MATCH(E1,A:A,0) gives us the row number where group 16
starts, which is the first row we want to copy. Similarly,
=MATCH(E1+1,A:A,0) gives us the row number where group 17 starts,
which is one row below the last row we want to copy. (Unfortunately
that's not true for the very last group of code, but to rectify that
you just need to add a dummy number at the very bottom of the data
in col A.)
Enter the formula =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1),"") in F1. That should copy the first value of the selected code block -- [DO] ADD TO QUEUE P in your example.
Copy F1 down as many rows as the largest code block is likely to be.
The one problem with that is that it will put 0 whenever it copies a blank row. So you have to explicitly check for that case, e.g. by changing the formula in F1 to =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),IF(ISBLANK(INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"",INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"")