SSRS: Summing Lookupset not working - sql

I'm currently working on a report where I'm given 3 different datasets. The report essentially calculates the input, output and losses of a given food production process.
In dataset "Spices", contains the quantity of spices used under a field named "Qty_Spice". In dataset "Meat", contains the quantity of meat used under a field named "Qty_Meat". In dataset "Finished", contains the quantity of finished product used under a field "Qty_Finished".
I'm currently trying to create a table where the amount of input (spice+meat) is compared against output (finished product), such that the table looks like this:
Sum of Inputs (kg) | Finished Product (kg) | Losses (kg)
10 8 2
8 5 3
Total:
18 13 5
What I'm currently doing is using lookupset to get all inputs of both spices and meats (using lookupset instead of lookup because there are many different types of meats and spices used), then using a custom code named "Sumlookup" to sum the quantities lookupset returned.
The problem I'm having is that when I want to get the total sum of all inputs and all finished products (bottom of the table) using "Sumlookup" the table is only returning the first weight it finds. In the example above, it would return, 10, 8 and 2 as inputs, finished products and losses respectively.
Does anyone know how I should approach solving this?
Really appreciate any help
Here is the custom code I used for SumLookUp:
Public Function SumLookup(ByVal items As Object()) As Decimal
Dim suma As Decimal = 0
For Each item As Decimal In items
suma += item
Next
Return suma
End Function

Related

Can I use dataframes as Input for functions?

I am currently trying to find optimal portfolio weights by optimizing a utility function that depends on those weights. I have a dataframe of containing the time series of returns, named rets_optns. rets_optns has 100 groups of 8 assets (800 columns - 1st group column 1 to 8, 2nd group column 9 to 16). I also have a dataframe named rf_options with 100 columns that present the corresponding risk free rate for each group of returns. I want to create a new dataframe composed by the portfolio's returns, using this formula: p. returns= rf_optns+sum(weights*rets_optns). It should have 100 columns and each columns should represent the returns of a portfolio composed by 8 assets belonging to the same group. I currently have:
def pret(rf,weights,rets):
return rf+np.sum(weights*(rets-rf))
It does not work

How to sum data based on a boolean amount?

Created dictionary called items. Combined values for different keys and put into variable food_list.
items={'Food':['Ice Cream','Salad'],'Computer':['Laptop','Notebook']
food_list= '|'.join(items['Food'])
Description Amount
Lenovo Laptop 300
Chicken Salad 40
Dell Notebook 250
Chocolate Ice Cream 3
I tried to find a string based on dictionary values. If the string is in the dictionary, then the row in the dataframe contains the string. I take the amount it is associated with and add up the total row amounts that fit the condition.
total_amount=df.loc[df['Description'].str.contains(food_list,na=False)
==df['Amount'].sum()]
I usually run the code and get
Empty DataFrame
Columns: [Date, Description, Amount]
Index: []

Pandas - split columns and count occurrences

It's info for some purchases made by clients on phone accessories, my real data would look something like this:
Abstract Model 1 ~Samsung S6 | Sold: 4
I've got a dataset that looks something like this:
item sold
Design1 ~Model1 1
Design2 ~Model1 2
Design1 ~Model2 3
Design2 ~Model2 1
I want to break the item column into 2 columns , design and model, and count each time a design has been sold, and a model has been sold, individually, based on the selling data of design+model combinations in the input.
My expected output, based on the first dataset, would look something like this:
expected output:
design design_sold model model_sold
Design1 4 Model1 3
Design2 3 Model2 4
try this,
df[['Design','Model']]=df['item'].str.split(' ~',expand=True)
print pd.concat([df.groupby('Design',as_index=False)['sold'].sum().rename(columns={'sold':'Desgin Sold'}),df.groupby('Model',as_index=False)['sold'].sum().rename(columns={'sold':'Model Sold'})],axis=1)
Output:
Design Desgin Sold Model Model Sold
0 Design1 4 Model1 3
1 Design2 3 Model2 4
Explanation:'
1. .str.split() used to split your series into frame.
groupby model and design and perform sum on grouped object.
rename the column and concat your dataframe.

Calculating Percentage of Percentage in SSRS

Figure A
Figure B
Figure C
I have created the table (figure A) that is giving me the result (figure B) where the subcategory percentages are taken from the TOTALS (example: for 1/16/2016 | 3.04% + 11.13% + 0.02% = 14.19%).
I need the subcategory percentages to be taken from the respective category total making it the new 100%, as displayed in figure C: the desired result (example: for 1/16/2016 | 21.40% + 78.42% + 0.17% = 100%).
In your example you want to refer to that cell with a total of 584 for Category B. SSRS doesn't have the option for you to refer to a value within multiple groups like that. You can only provide one scope override. To get this functionality you can add a subquery to your dataset that aggregates those values in a new column.
So for example your dataset should end up looking like this:
CategoryName SubcategoryName Number CategorySubtotal
Category B subcategory a 125 584
Category B subcategory b 458 584
...
Now you can easily calculate the percent of total for each category in the report.

How to use SSRS to report using a custom, "matrix-ized" table

First up, my environment: SQL 2005 + MS DAX 2009.
We have made a table that gets used in a matrix-like fashion for entering in purchase orders via an AX form. So each row will have:
a column for item#
a column for color
columns 1-7 for size (size1, size2,...), quantity (qty1, qty2,...), and cost (cost1, cost2,...).
I am trying to create a report in SSRS that basically uses this data in a more list-like fashion for printing out a PO order form.
I have got it to show the sizing right, but the cost situation complicates it as the unit cost can, and does, differ depending on size (for instance 2XL is more than S-M-L).
For example in our table, item 10000 black has 3 for Small (this data would be qty1), 3 for Medium (qty2) and 4 2XL (qty5). The cost for qty1 and qty2 are the same at $2.50 (cost1 and cost2). The cost for qty5 (cost5) would be $4. I would like to have this broken out into 2 rows by the cost and associated size on the form. So one line would have 10000 black Small and medium info and the second row would have the same item and color, but only have 2XL and its cost data.
Is there a way to "match" fields or somehow cycle through them to get the correct cost without having to have an additional 7 cost columns? Or perhaps there is a more elegant solution that is escaping me?