Ignore non-empty values when aggregating - ssas

I have a cube I've built with three separate measures: "TY Sales", "LY Sales", and "% Change", what I'm trying to do is have special behavior for the aggregate rows, basically not including any "LY Sales" values when summing the total if "TY Sales" is 0. So currently my cube works like below:
LYSales TYSales %Change
Year 1 450 300 -33%
Week 1 100 125 +25%
Week 2 150 175 +14%
Week 3 200 0 +0%
The aggregate column "Year 1" in this example, is summing all values for each sales measure. What I want it to do instead, is only include values in LYSales if TYSales also has a non-zero value. So my ideal state would be below:
LYSales TYSales %Change
Year 1 250 300 +20%
Week 1 100 125 +25%
Week 2 150 175 +14%
Week 3 200 0 +0%
I'm new to SSAS, so any guidance is appreciated. Thanks

An easy and reliable way to achieve that would be to change the source column of LYSales to be zero if TYSales is zero. This would be done in the fact table on which the measure is based. You could implement that
either in the ETL process, changing the LYSales column values to be zero when TYSales is zero,
or in a view based on the fact table that is then used in the Data Source View instead of the original table,
or as a Calculated Calculation of the fact table in the Data Source View.
In the latter two cases, the calculation formula would be SQL like this:
case when TYSales <> 0 then LYSales else 0 end
Then switch the measure definition to use that column.

Related

DAX - Reference measure in calculated column?

I have data like this
EmployeeID Value
1 7
2 6
3 5
4 3
I would like to create a DAX calculated column (or do I need a measure?) that gives me for each row, Value - AVG() of selected rows.
So if the AVG() of the above 4 rows is 5.25, I would get results like this
EmployeeID Value Diff
1 7 1.75
2 6 0.75
3 5 -0.25
4 3 -1.75
Still learning DAX, I cannot figure out how to implement this?
Thanks
I figured this out with the help of some folks on MSDN forums.
This will only work as a measure because measures are selection aware while calculated columns are not.
The Average stored in a variable is critical. ALLSELECTED() gives you the current selection in a pivot table.
AVERAGEX does the row value - avg of selection.
Diff:=
Var ptAVG = CALCULATE(AVERAGE[Value],ALLSELECTED())
RETURN AVERAGEX(Employee, Value - ptAVG)
You can certainly do this with a calculated column. It's simply
Diff = TableName[Value] - AVERAGE(TableName[Value])
Note that this averages over all employees. If you want to average over only specific groups, then more work needs to be done.

how to calculate a rolling average based on a column in spotfire

I have a data set where you have a Document Property that Selects "items", each "item" has a particular "usage days". I want to calculate an output of "Moving Average" for 1 or more selected items. the data for the moving average lives under a column named "usage days".
How do I calculate this taking into account the "selected date of my choice" and the rolling average number of days of my choice.
Do you have particular ideas of how I can perform the calculation i.e. in a calculated column or a text field?
Car/ Trip / Start Date/ End Date / Days on trip
1 AB123 / 2 / 6/07/2013
1 AB234 / 29/07/2013 / 6/09/2013 / 42
1 AB345 /6/09/2013 /28/09/2013 /22
1 AB456 /29/09/2013 /21/10/2013 /23
2 AB567 / 26/10/2013 / 12/11/2013 / 22
2 AB678 /12/11/2013 /8/12/2013 /26
[The rows above have an example of the problem (sorry couldn't paste an image because im new), I want to calculate the %usage of the Car and or cars for a selected range of time e.g (Select date range JUlY to AUGUST then (#of days on trip for car 1and 2)/#on days in that period)/2*100]
As phiver said, it is still difficult to see what you expect as a result... but I think I have something that might work. First, I slightly altered the dataset you provided, like so:
car trip startDate endDate daysOnTrip
1 AB123 7/6/2013 7/29/2013 23
1 AB234 7/29/2013 9/6/2013 42
1 AB345 9/6/2013 9/28/2013 22
1 AB456 9/29/2013 10/21/2013 23
2 AB567 10/26/2013 11/12/2013 22
2 AB678 11/12/2013 12/8/2013 26
I then added 2 document properties, "DateRangeFirst" and "DateRangeLast", to allow the user to select beginning and ending dates. Next I made input box property controls for each of the aforementioned document properties in a text area so the user can alter the date range. I then added a datatable visualization with a "Limit data using expression:" of "[startDate] >= Date(${DateRangeFirst}) and [endDate]<= Date(${DateRangeLast})" so we could see the trips selected. Finally, to get the average you appear to be looking for, a barchart set to % of total (daysOnTrip) / car with the same data limiting expression as above. The below screenshot should have everything you need to reproduce my results. I hope this gives you what you need.
NOTE: With this method if you select a date in the middle of a trip, an entire row and all of the days on that trip will be ignored.

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.

SSRS 2008 display mutilple columns of data without a new line

I am creating a report in SSRS 2008 with MS SQL Server 2008 R2. I have data based on the Aggregate value of Medical condition and the level of severity.
Outcome Response Adult Youth Total
BMI GOOD 70 0 70
BMI MONITOR 230 0 230
BMI PROBLEM! 10 0 10
LDL GOOD 5 0 5
LDL MONITOR 4 0 4
LDL PROBLEM! 2 0 2
I need to display the data based on the Response like:
BMI BMI BMI
GOOD MONITOR PROBLEM!
Total 70 230 10
Youth 0 0 0
Adult 70 230 10
LDL LDL LDL
GOOD MONITOR PROBLEM!
Total 5 4 2
Youth 0 0 0
Adult 5 4 2
I first tried to use SSRS to do the grouping based on the Outcome and then the Response but I got each response on a separate row of data but I need all Outcomes on a single line. I now believe that a pivot would work but all the examples I have seen is a pivot on one column of data pivoted using another. Is it possible to pivot multiple columns of data based on a single column?
With your existing Dataset you could so something similar to the following:
Create a List item, and change the Details grouping to be based on Outcome:
In the List cell, add a new Matrix with one Column Group based on Response:
You'll note that since you have individual columns for Total, Youth, Adult, you need to add grand total rows to display each group.
The end result is pretty close to your requirements:
For your underlying data, to help with report development it might be useful to have the Total, Youth, Adult as unpivoted columns, but it's not a big deal if the groups are fairly static.

Excel Pivot table grouping Row Labels that are Percentages

Here is my data (apologies for poor formatting, maybe that should have been my first question!):
Customer Percentage Increase
1 2%
2 12%
3 -50%
4 87%
5 -20%
6 -1%
7 123%
8 -98%
9 10%
10 13%
I created a pivot table in Excel with Percentage Increase as the Row Labels and Count of Customer as the value.
Row Labels Count of Customer
-98% 1
-50% 1
-20% 1
-1% 1
2% 1
10% 1
12% 1
13% 1
87% 1
123% 1
Grand Total 10
I then wanted to group the percentages to something easier to read, but the percentage ranges do not show percentages, instead they show regular numbers.
Row Labels Count of Customer
<-0.5 1
-0.5--0.25 1
-0.25-0 2
0-0.25 4
0.75-1 1
>1 1
Grand Total 10
How do I get the number formatting of my percentage ranges to be percentages, i.e. 0% - 25%, etc?
Thank you.
The only way I know is to change them by hand, i.e., click into the cell with the label and change it to say what you want.
If you do this, I'd also create the labels for the categories that don't show up yet, e.g., 25% to 50% (and 50% to 75%) in your example. To do this, choose Field Settings>Layout & Print and check "Show items with no data". Change the labels for those ranges as well. Once you do, you can uncheck "Show items with no data", and in the future if there are counts in new ranges the new labels will still be what you entered. (At least it seems to work that way).