Subtracting from current row to other previous rows in SSRS - ssrs-2012

I want to have the value of "ToTal Operation Income/(Loss)" by
subtracting the total value of "Other Operating Income" to "GROSS PROFIT/(LOSS)".
I don't know how to do it. The fact that "Revenue", "LESS:COST OF SALES" AND "Other Operating Income" is grouping.

Related

Repeating Cell Fill In Randomly Selected Rows

I want to auto-fill the text "SOLD" to column K in each row from a pre-chosen set of rows not necessarily in sequential order. For ex: I may select rows 1-3 & maybe rows 8 & 10. Upon selecting said rows, I want to run my macro to enter the text "SOLD" in each of them.
Here is my current macro, which works only on one row at a time:
Sub ItemSold()
Range("K" & ActiveCell.Row).Select
ActiveCell.FormulaR1C1 = "SOLD"
Rows(ActiveCell.Row).Select
End Sub
I assume there's a way to cycle through all of the selected rows with FOR EACH or maybe a REPEAT function/?

NetSuite saved search formula to multiply results of two other columns

I currently have a saved search that populates a list of items.
My current results are standard NetSuite fields which are "Name", "Description", "Type", "Average Cost" & "Available"
I am trying to add another column for a formula that multiplies the Average Cost by the Available to give me the Value of the Available SOH.
In your saved search results add a new field of type formula(numeric). In the formula popup window use this formula:
NVL({averagecost}, 0) * NVL({quantityavailable}, 0)
This will multiply the average cost and quantity available together and give you the result. I put the NVL in there in case an item doesn't have an average cost or quantity available you won't get an error.

DAX: calculate measure "without" current row

I want to calculate a DAX measure "without" the current row. Here is an example based on AdventureWorksDW2014.
evaluate
summarize(
'FactInternetSales'
, 'DimProduct'[ProductSubcategoryName]
Cell-level measures, these are defined as in https://learn.microsoft.com/en-us/sql/analysis-services/lesson-5-create-calculated-columns
, "Margin", [InternetTotalMargin] -- InternetTotalMargin := SUM([Margin])
, "Cost", [InternetTotalProductCost] -- InternetTotalProductCost := SUM([TotalProductCost])
I defined a new measure which is a composite (ratio) of existing measures:
, "Gross Margin", [GrossMargin] -- GrossMargin := DIVIDE([InternetTotalMargin], [InternetTotalProductCost])
Column totals:
, "Total Margin", calculate([InternetTotalMargin], allselected('DimProduct'))
, "Total Cost", calculate([InternetTotalProductCost], allselected('DimProduct'))
Column totals without current row, obtained by subtracting the cell value expression from the column total value expression:
, "Total Margin w/o Subcat", calculate([InternetTotalMargin], allselected('DimProduct')) - [InternetTotalMargin]
, "Total Cost w/o Subcat", calculate([InternetTotalProductCost], allselected('DimProduct')) - [InternetTotalProductCost]
This does all the aggregations before applying the formula:
, "Total Gross Margin", calculate([GrossMargin], allselected('DimProduct'))
I want to calculate "Total Gross Margin" without the "current row".
My first attempt yields the desired result but depends on explicit knowledge of the formula behind GrossMargin.
This is "explicit" because we essentially re-implement the calculation after subtracting the "current row" out of the numerator and denominator.
I want to be able to do this with measures where I don't know the formula, or the formula is potentially more complex than simple division.
, "Total Gross Margin w/o Subcat (Explicit)",
-- explicitly repeat the division formula
divide(
-- explicitly recompute the numerator
calculate([InternetTotalMargin], allselected('DimProduct')) - [InternetTotalMargin]
-- explicitly recompute the denominator
, calculate([InternetTotalProductCost], allselected('DimProduct')) - [InternetTotalProductCost]
)
-- next step/where this is meant to be used:
, "Gross Margin Impact (Explicit)", calculate([GrossMargin], allselected('DimProduct')) - divide(calculate([InternetTotalMargin], allselected('DimProduct')) - [InternetTotalMargin], calculate([InternetTotalProductCost], allselected('DimProduct')) - [InternetTotalProductCost])
I want a more general solution that does not require knowledge of the calculation, something like this:
/*
, "Gross Margin w/o Subcat", calculate([GrossMargin], allselected('DimProduct' Except Current Row)
, "Gross Margin Impact, calculate([GrossMargin], allselected('DimProduct')) - calculate([GrossMargin], allselected('DimProduct' Except Current Row)
*/
Different failed attempts (using Margin rather than GrossMargin since it is easier to check):
, "Trial 1", calculate([InternetTotalMargin], except(all('DimProduct'), 'DimProduct')) -- incorrect value
, "Trial 2", calculate([InternetTotalMargin], allexcept('DimProduct', 'DimProduct'[ProductSubcategoryName])) -- incorrect value
, "Trial 3", calculate([InternetTotalMargin], allexcept('DimProduct', 'DimProduct'[ProductCategoryName])) -- incorrect value
, "Trial 4", calculate([InternetTotalMargin], allexcept('DimProduct', 'DimProduct'[ProductKey])) -- incorrect value
, "Trial 5", calculate([InternetTotalMargin], 'DimProduct') -- incorrect
, "Trial 6", calculate([InternetTotalMargin], 'DimProduct'[ProductSubcategoryName] <> 'DimProduct'[ProductSubcategoryName]) -- illogical, and blank result
-- , "Trial 7", calculate([InternetTotalMargin], 'DimProduct'[ProductSubcategoryName] <> [ProductSubcategoryName]) -- invalid syntax
-- running out of ideas here
)
;
Is this even possible in DAX?
No, this is not possible in DAX.
If you want to calculate a measure you need to define it first. You can't create a place holder/insert formula here/ and hope for the best.
What you can do is use the keyword VAR to define your measure, calculate different measures at the time of calculation and pick the one that suits best. Alternatively and if possible, use the calling function to define the measure by a "replace" method.

Spotfire Expression Value for Max(Row Count)

I'm trying to make a Calculated Value Control expression on the below columns:
Row Count | Date | Value
What I want to get is the Value for the 'newest' date, which will also be the highest row count. How can I write an expression to get this, it seems like it ought to be simple. I'm having trouble writing it in only expression language, without SQL.
Using the expression below you can limit the records in your table to those with the highest (aka most recent) date which should have your Value of interest.
[Date] = Max([Date])
You can do the same with row count since you mentioned the record of interest being the highest row count:
[Row Count] = Max([Row Count])
If you're looking to create a calculated column you can use a case statement to spit out the value:
case when [Date] = Max([Date]) then [Value] end
Lastly, should you want to display this value in a Text Area to show off your value you can utilize the calculated column above:
1) Create a new Text Area
2) Type some text about what it is: "Value for newest Date: " (optional)
3) Click "Insert Dynamic Item" -> "Calculated Value"
4) Under "Data" ensure the appropriate data table is selected. Note: You can uncheck the "Use Current Filtering..." box here if you do not want your value to update as you filter.
5) Under Values, utilize our calculated column with "Max" wrapped around it to avoid Summing duplicate values:
Max(CALCULATED_COLUMN)
Here is a screenshot of my work with random filler dates and values: http://i.imgur.com/hFapS8c.png
The larger text is to show the calculated value dynamic items. I used Max([Date]) for the date value.

Complicated Cube Query

I'm working on a fairly complicated view, which calculates the total cost of a guest's stayed based on data pulled from four different tables. The output however is not exactly what I want. My code is
CREATE OR REPLACE VIEW Price AS
SELECT UNIQUE
Booking.Booking_ID AS "Booking",
Booking.GuestID AS "Guest ID",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) AS "Room Price",
Add_Ons.Price AS "Add ons Price",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) + (Add_Ons.Price) AS "Total Price"
FROM Booking JOIN Room ON Room.Room_Num = Booking.Room_Num
JOIN Booking_Add_Ons ON Booking.Booking_ID = Booking_Add_Ons.Booking_ID
JOIN Add_ons ON Booking_Add_Ons.Add_On_ID = Add_Ons.Add_On_ID
ORDER BY Booking.Booking_ID;
Now, I'm trying to get this to return the total cost of all Addons, plus the cost of the hotel rooms as the total price, however it is returning the cost of the rooms + each of the addons on separate lines. As follows:
My question is, is it possible to use something like CUBE, or SUM to add up the rows, so that there is only one entry for each of the Bookings with the total price of all add-ons accounted for?

Resources