I am working on an Excel pivot table that looks like the following:
Prj 30Days 60Days GreaterThan60
128139 0 0 118484.02
123123 0 0 10115.01
234232 0 0 4609.81
121313 0 0 314.33
343432 0 0 4000
232323 0 0 164.27
121212 164994.98 0 0
232323 0 0 1046.58
Grand Total 1075731.89 535507.27 199200.01
Here is my expected/desired result:
Prj 30Days 60Days GreaterThan60 GrandTotal
128139 0 0 118484.02 118484.02
123123 0 0 10115.01 10115.01
234232 0 0 4609.81 4609.81
121313 0 0 314.33 314.33
343432 0 0 4000 4000
232323 0 0 164.27 164.27
121212 164994.98 0 0 164994.98
232323 0 0 1046.58 1046.58
Grand Total 1075731.89 535507.27 199200.01 1810439.17
The Grand Totals at the bottom of the pivot table are Grand Totals for columns. I also need the Grand Totals for Rows as the right most Column. I am not able to do this, though I checked the option to SET Grand Totals for both rows and columns.
I researched this issue online and it says that we need to have at-least one field in Column Labels to get the Row Totals, I don't have a field that I want to put in the Column Labels.
Can I create a calculate measure to achieve this? I looked into creating a calculated field in Excel under PivotTable/Options/FieldItems and Sets/New Calculated Field. But the New Calculated Field option is disabled.
I have added some more 'data' to match up with your totals. A PT with Grand Total for rows seems feasible:
Since you have tried what I used for the GT for rows without success I'm guessing your data input (not shown) must not be in the same format as in my example. If for example you have dates rather than the (credit period?) bands then using these dates to calculate the appropriate bands in the source data may be all that you are missing.
Related
I have a pandas dataframe in python and I'm trying to modify a specific value in a particular row. I found a solution to this problem Set value for particular cell in pandas DataFrame using index, but it is still generating the SettingWithCopy error.
The name of the data frame is internal_df and it has columns 'price', 'visits', and 'orders'. Specifically, I want to add the number of orders and visits to a lower price point if we don't have a sufficient number of visits (100 in this example). Note that below the variable 'price' is a float, and the data types for 'price' within the internal_df data frame is float, while price and orders are ints.
if int(internal_df[internal_df['price']==price]['visits']) < 100:
for index, row in internal_df.iterrows():
if float(row['price']) > price:
internal_df.ix[internal_df['price'] == price, 'visits'] = internal_df.ix[internal_df['price'] == price, 'visits'] + row['visits']
internal_df.ix[internal_df['price'] == price, 'orders'] = internal_df.ix[internal_df['price'] == price, 'orders'] + row['orders']
Here is a sample of the data
price visits sales
0 1399.99 2 0
1 169.99 2 0
2 99.99 1 0
3 99.99 1 0
4 139.99 1 0
5 319.99 1 0
6 198.99 1 0
7 119.99 1 0
8 39.99 1 0
9 259.98 1 0
Does anyone have any suggestions, or should I just ignore the error?
Brad
Note that .ix is deprecated because it indexes by position or by label, depending on the data type of the index. Use .loc or .iloc instead.
This SettingWithCopyWarning might originate from a "get" operation several lines of code above what you've provided. A quick fix might be to find where internal_df is first assigned, and to add .copy() to the end of the assignment statement. For example, if you have internal_df = df[df['colname'] <= value], change that to internal_df = df[df['colname'] <= value].copy() and hopefully that resolves the error.
Also, I think you can do what you're trying to do without a for loop, which would be faster and more readable!
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.
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.
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).
Is there any way to caculate the average of the non zero rows only for a column of data in a table in an RDLC for Microsoft report viewer?
ie
0
0
0
5
5
= 5 not 2
I tried Count( fields.n.value > 0 ) to get the count of non zero rows, but it returned the
count of all rows.
Thanks!
Eric-
Try this:
=Sum(Fields!n.Value > 0) / Sum(IIf(Fields!n.Value > 0, 1, 0))
Notice how the average is computed manually by summing all values then dividing by another sum that mimics a specialized count mechanism.