Custom expression using property control - spotfire

I would like to know how to create calculated columns in my data set I have month and year column and cost column available using property control like to create below columns;
1.full year 2015 - this column value be constant
2.ytd 2015 - this column total change based on selection
3.ytd 2016 - this column total change based on selection
4. Full year 2016 - this column total change based on selection
So I wanted to calculate these columns using custom expression and how to use property control in spotfire.

There really isn't enough information here for us to help you. We need to know two main things --
1) What your data looks like (I can grasp this from your explanation, but if you don't know what you're doing in Spotfire itself, it makes it harder for us to get the code we're giving you correct)
2) How you want to display your data. Ideally, this could be shown with a table or an image, with an example input and output.
MY BEST GUESS is that you want to display in a pivot table the full year's cost and the YTD cost for both 2015 and 2016. I don't know what you mean by "based on a selection".
If you really do want a calculated column, and not a custom expression, the general format would be something like this:
If([Month] < Month(DateTimeNow()) and Year([Year]) = 2015, [Cost], 0)
This would allow you to sum up the 2015 YTD.
If this is not what you are looking for, please provide more explicit information.

Related

Excel PivotTable create column based on summarised column data

I have the following Pivot Table:
I am trying to derive the number of cases created per resource for a given month. I.e. for Jan 2021 the formula would be 768/9 = 85.333...
I've tried to use a Calculated Field, but the issue I'm having is that the PivotTable uses the underlying data e.g. for a given case, create date is 1/1/2022 and the resources on that day is 8. It is then dividing the numeric value of 1/1/22 by 8 and coming up with a value in the thousands, for obvious reasons, and then working out the average/sum/etc for all of the cases within that month. What I need is a way of just doing B5/C5 but within the pivot table itself, rather than a column outside of the pivottable. Is this possible?
P.S. Sorry if this is a basic one that has already been answered, but I'm not always sure on the correct terminology for PivotTable functionality so I've likely been googling like a 6 year old.
Thanks,

Calculate average based on a value column (count) in a pivot table

I'm looking a way to add an extra column in a pivot table that that averages the sum of the count for the months ("Count of records" column) within a time period that is selected (currently 2016 - one month, 2017 - full year, 2018 - 5 month). Every month would have the same number based on the year average, needs to be dynamically changing when selecting different period: full year or for example 4 months. I need the column within the pivot table, so it could be used for a future pivot chart.
I can't simply use average as all my records appear only once and I use Count to aggregate those numbers ("Count of records" column).
My current data looks like this:
The final result should look like this:
I assume that it somehow can be done with the help of "calculated filed" option but I couldn't make it work now.
Greatly appreciate any help!
Using the DataModel (built in to Excel 2013 and later) you can write really cool formulas inside PivotTables called Measures that can do this kind of thing. Take the example below:
As you can see, the Cust Count & Average field gives a count of transactions by month but also gives the average of those monthly readings for the subtotal lines (i.e. the 2017 Total and 2018 Total lines) using the below DAX formula:
=AVERAGEX(SUMMARIZE(Table1,[Customer (Month)],"x",COUNTA(Table1[Customer])),[x])
That just says "Summarize this table by count of the customer field by month, call the resulting summarization field 'x', and then give me the average of that field x".
Because DAX measures are executed within the context of the PivotTable, you get the count that you want for months, and you get the average that you want for the yearly subtotals.
Hard to explain, but demonstrates that DAX can certainly do this for you.
See my answer at the following link for an example of how to add data to the DataModel and how to subsequently write measures:
Using the Excel SMALL function with filtering criteria AND ignoring zeros
I also recommend grabbing yourself a book called Supercharge Excel when you learn to write DAX by Matt Allington, and perhaps even taking his awesome online course, because it covers this kind of thing very well, and will save you significant head-scratching compared to going it alone.

Excel Pivot Table difference in columns of "shown as" values

Is there a way to let a pivot table calculate the difference between 2 columns automatically when the values are shown as a % of the parent column total?
Now I need to to manually but the table is dynamic and number of competitors may vary. Function seems so easy but can't find it after googling etc...
See example picture below of what I want to achieve.
(Column F automated by the pivot table is the goal)
If trying to solve this with PivotTables, you've got a couple of options:
Use a 'Traditional' PivotTable that's based on a range. This will give you percentage differences, but you can't get percentage point differences like you're asking for without using external formulas.
Use a 'OLAP' PivotTable that's based on data you've added to the Excel Data Model. This will give you both percentage differences and percentage point differences, without having to resort to using external formulas.
In both cases, I recommend that you unpivot your data first, so that it is in what's known as a Flat File. Currently you're using a cross-tabulated data source (i.e. your source has columns called Year 1, Year 2), and the type of percentage comparisons across years you want to do doesn't work if your data is a crosstab. Basically, PivotTables aren't meant to consume cross-tabulated data.
Instead, you really want your data laid out so that you have a column called Amount and a column called Year, and then you can use the Show Values As options available from the right-click menu to show as percentage differences across years. To transform your data into a flat file, see my answers at convert cross table to list to make pivot table
That said, you can still use the GETPIVOTDATA function on your existing (unpivoted) data layout in a way that is somewhat more robust to changes in your PivotTable structure than just subtracting one reference from the other:
But again, I recommend transforming your data into a Flat File. Then you can additionally do the following:
Using a 'Traditional' PivotTable:
You can kinda solve your problem entirely within a self contained 'Traditional' PivotTable if you drag the Amount column to the Values area, put the Year column in the Columns area, put your Competitors in the Rows area, and choose one of the percentage Show Values As options you'll see when you right-click a cell in the Values area.
I say kinda, because without using external formulas (or without calculating the percentages back in your source data), you can only get it to show percent increases (see far right column), not percentage point increase like you want (see far left column). That said, I think percent increase is less confusing. But I guess it depends on what you want to show. If you want to show say change in market share from one year to the next, then percentage points make sense.
Of course, you could always use the GETPIVOTDATA function to do the additional math for you like we did earlier, like I've done on that left hand side.
Using an OLAP PivotTable based on the DataModel
Calculating percentage point increases likely requires using PivotTables built using the Data Model. See my answer at https://stackoverflow.com/a/49973465/2507160 that explains a little about the Data Model (although it doesn't answer this specific question).
Here's the result:
Here's the measures I used to do this:
Total Year 1:
=CALCULATE(SUM(Table2[Value]),ALLSELECTED(Table2[Competitor]),Table2[Year] = "Year 1")
Total Year 2:
=CALCULATE(SUM(Table2[Value]),ALLSELECTED(Table2[Competitor]),Table2[Year] = "Year 2")
% Year 1:
=CALCULATE(SUM(Table2[Value]),Table2[Year] = "Year 1")/[Total Year 1]
% Year 2:
=CALCULATE(SUM(Table2[Value]),Table2[Year] = "Year 2")/[Total Year 2]
p.p. Diff:
= [% Year 2] -[% Year 1]
You can add Calculated Fields to Pivot Tables, of varying levels of complexity. Finding the difference between two fields is about as simple as it gets.
The example below is borrowed from contextures.com, where there are many more examples more further information.
To add a calculated field:
Select a cell in the pivot table, and on the Excel Ribbon, under the PivotTable Tools tab, click the Options tab (Analyze tab in
Excel 2013).
In the Calculations group, click Fields, Items, & Sets, and then click Calculated Field.
Type a name for the calculated field, for example, RepBonus.
In the Formula box, type =Total * 3%
Click Add to save the calculated field, and click Close.
The RepBonus field appears in the Values area of the pivot table, and in the field list in the PivotTable Field List.
(Source)
EDIT:
#jeffreyweir - I'm not gonna lie, I don't know off the top of my head how to make this work (and don't have time to experiment) but by the looks of these options, isn't a calculated field with a "straight subtraction" of existing fields (ie., 3$-2%=1%) very possible with Difference from? (as opposed to % Difference from which is also an option but for a different result).
In fact, automatic year-over-year difference reporting should be readily possible with the <previous> and <next> comparison operators...?
                                 (Click to Embiggen)
     
Also, did you see the link where I got the example? Kind of a hoakey site but it has some more complex pivot table instructions.

Creating a sum based on a category within a date range

I'm trying to make a spreadsheet that I can easily take an export from Mint.com's CSV outputs and get them into my Excel budget.
To do so, I need a way to populate each field within a date range. I'd like to avoid macros if possible (I don't know how to make them).
I'm happy to share my finished .xls with the public!
I've imported Mint.com's data in a manner that has column S for the date (3/30), column V with the cash value that I need to add up, and column X for the spending category.
I need to tally each month's spending ($V) by category (column X).
Through research, I devised this (for my January "Gas & Fuel" spending):
=SUMIFS($W$2:$W$900, $T$2:$T$900, ">="&W$12, $T$2:$T$900, "<"&(EOMONTH(D$1,0)+1), $Y$2:$Y$900, "="&$B5)
However, it required that I reformat my Dates, which is an issue because this would become specific to each year and I would need to change the fields every year. I'd like the document to be usable without adjustment using my spending data from the past and future.
Is there a way to take the year out of the equation? To make that formula above work, I renamed my column from "January" to "1/14".
Here is what the spreadsheet looks like
Thanks!
A pivot table would work best with that data.
Initial set up would show each day separately, but by using Grouping
(here) ^^^
you can group the data by month/day/year/however

apply two nested sub-totals to a table in Excel 2007

I would like to apply two nested sub-totals to a table in Excel 2007, but I find that the "SubTotal" button does not seem to work consistently.
Imagine the following table
Year Colour Amount
2011 Red 10
2011 Green 20
If I select all the rows and click on "SubTotal" with the following parameters
At each change in - Year
Use Function - Sum
Add subtotal to - Amount
Replace current subtotals - No
Page break between groups - No
Summary below data - No
I then do exactly the same but
- At each change in - Colour
I get the following nice table which is exactly what I want
Year Colour Amount
Grand Total 30
2011 Total 30
Red Total 10
2011 Red 10
Green Total 20
2011 Green 20
Imagine though that I change "Green" to "Red" in the original table
Year Colour Amount
2011 Red 10
2011 Red 20
If I follow the above steps, then I would expect to see the table looking in the same format. However I get the following
Year Colour Amount
Red Total 30
Grand Total 30
2011 Total 30
2011 Red 10
2011 Red 20
As you can see the Red Total is at the top whereas I would like it to be after the row "2011 Total" just as it is in the first table.
Is there any way of working around this. [I know I can do this manually, but would like to use the SubTotal button]
To summarize, I need both the 2011 and the Colour to be sub-totaled, but in a way that first the 2011 is sub-totaled, and then the Colour (as in the first table I show above). This needs to work whatever the data that makes up the table. For me, it only works with the first data set, but not the second data set.
QUESTION UPDATED
Here is an example. The example includes an extra ten "Price" columns not mentioned in the problem. The reason why I have shown these ten columns is to show why PivotTables are not my ideal solution. I did not think it is possible with PivotTables to show the "details" of the rows inline with the subtotals - in the manner depicted in the picture.
I agree with d--b - you are going to want to use pivot tables - they provide alot more intuitive features(in my opinion) than the subtotal system does:
The subtotal system is dependent on the initial sorting and organization of the data for what it produces. Whereas pivot tables do not care whether/how your initial data is sorted.
Good Luck.
EDIT:
You can still manipulate the subtotal table using standard copy/cut and paste features - it will maintain its tree structure:
So basically feel free to move the rows around using cut and paste however you want it to look - you can even move individual cells around within a row - it will still maintain it's structure/look. Good Luck.
Try to play with Replace current subtotals - YES
Had a bit to play around until i could reconstruct your problem, but this solved it.
It worked, when I had your example reconstructed, then marked the whole thing and did subtotal again, with replacement of current subtotals.
It worked also when I did your example on a clean pure data table.
And to reconstruct your example I had to use subtotal without replace on a subtotaled table grouped by color.
Hope this helps ;)

Resources