Calculate a % of a field - sql

Using quicksight, I'd like to create the % of my total revenues vs delta of loss.
Basically, I've a field, where inside there are all the economics (so not just revenues but also costs). I'm successfully filtering it to have 2 columns, one for Revenues and one for costs. Revenues came adding these filters to different categories field I've in the system:
Pl_cat --> filtered as "1-revenues" and "2-Expenses"
bu_F --> filtered as "1-work"
Report_super_category --> filters as "1-Coworking"
Act_Bud --> filtered as "Actual"
Applying all these filters to fy_total (field that held all my numbers), using a month field for the X axes, and multiplying costs *-1, I get the correct revenues and costs numbers in columns a table split by month.
Also, using fy_total withouth any calcs, I get the delta by month (leaving those filters applied of course).
What i'd to do now is, getting the % of that delta over those filter revenues.
Example: Total month revenues (all fields, no filters): 1M
Applying those filters and a calculated field where Expenses are multiplied by -1, I get the revenues and expenses for 1-Coworking under 1-Work in 2 columns, let's say 600K for Revenues and 400K for expenses.
Also Using fy_total withouth any calculated fyeld, I get its delta: 600K-400K = 200K
I want to transform those 200K in 200/600 = 33%
I've added an image of my current situation, I'm using quicksight which is also based on SQL presto language
Thank you guys!

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

Conditional Probability with Powerpivot

my major goal is to calculate Conditional Probability over a large number of rows. Hence the use of Powerpivot.
Attached is an excel file with 10 rows as an example of how I did it in Excel.
My challenge is the formula in column F which I will then be needing to calculate column G.
Tamir
Can you check the solution
Main Formulas:
Calculate a Total, without filtering BRAND and UPS (calculated measure)
=CALCULATE([Total],All(Brand),All(upc))
Sum IF UPC (calculated column):
=CALCULATE([Total],filter(ALL(Fact),Fact[UPC]= EARLIER(Fact[UPC]) ))

Quick Delta Between Two Rows/Columns in GoodData

Right now, I see there are quick ways to get things like Sum/Avg/Max/Etc. for two or more rows or columns when building a table in GoodData.
quick total options
I am building a little table that shows last week and the week prior, and I'm trying to show the delta between them.
So if the first column is 100 and the second is 50, I want '-50'
If the first column is 25 and the second is 100, i want '75'
Is there an easy way to do this?
Let’s consider, that the first column contains result of calculating of metric #1 and the second column contains result of calculating of metric #2, you can simply create a metric #3, which would be defined as the (metric #1 - metric #2) or vice versa.

MDX weighted values

I have a cube built on a fact which, amongst others, includes the Balance and Percentage columns. I have a calculation which multiplies the Balance by the Percentage to obtain an Adjusted Value. I now need to have this Adjusted Value divided by the sum of all balances, to get weighted values.
The problem is that this sum of all balances doesn't apply to the whole dataset. Rather, it should be calculated on a filtered subset of the whole data. This filtering is being done in Excel using a pivot table, so i do not know what conditions will be used to filter.
So, for example, this would be the pivot i'd like to see:
ID Balance Percentage Adjusted Value Weighted Adjusted Value
1 100 1.5 115 0.38 (ie 115/300)
2 50 2 51 0.17 (ie 51/300)
3 150 1 150 0.50 (ie 150/300)
300 is obtained by summing the balance of the rows that show in the filtered pivot.
Can this calculation be somehow done in OLAP? Or is it impossible to compute this sum with what i know?
Yes should be possible; e.g., assuming 1/2/3 are the children of a common parent, then the following calculated measure should do the trick :
WAV = AV / ( id.parent, Balance )
If not we would need more information about the actual data model and query.

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?