Difference between rows in the same coulm for values which met specific conditions - spotfire

here's my input and my desidered output. Problem Is: I have a columns for product, price, and date and I want to build a cross table where I can see the price of the day before for every product.
How can I calculate column d-1 (day - 1) in my data table? Should I use Intersect/Over functions? What If I want to calculate my d-1 column on-the-fly in a cross table?

You have some options here, depending on how you want to display everything.
If all you want is an overall snapshot of how it changed between Today and Yesterday, probably the simplest thing to do is the following:
Avg(If([DATE]=Date(DateTimeNow()),[Price],NULL)) as [Today's Price],
Avg(If([DATE]=Date(DateAdd("day",-1,DateTimeNow())),[Price],NULL)) as [Yesterday's Price],
Avg(If([DATE]=Date(DateTimeNow()),[Price],NULL)) - Avg(If([DATE]=Date(DateAdd("day",-1,DateTimeNow())),[Price],NULL)) as [d-1]
This can be very useful for a dashboard or summary, and if you replace the "DateTimeNow" component with a Document Property controlled by an Input field, this can quickly show your user the change on a specific day.
The Over functions could still be quite useful, especially if you're using a date hierarchy of some form.
It will update on the fly to accommodate the columns grouped across the top, so if you're displaying by date, you can see how it's been changing each day, and if you're displaying by month, you can see it that way instead.
Avg([Price]) as [Avg Price],
Avg([Price]) - Avg([Price]) OVER (PreviousPeriod([Axis.Columns])) as [Avg Price Change]

Related

Pivot tables in excel - showing last values

I am having an issue with showing last value.
I have a source table, where is every single day (once) and for each day I have for item 1 total amount in stock.
I put it in pivot table. Column for total item in stock, for each day in month July for example, shows me balance for every day. When I group the month, it shows cumulative amount - which is wrong. I need to show last value.
Therefore I searched for a solution, I found on webpage ExcelJet this.
But when I tried it, for some reason, the date 31/07/2020 shows value 0 on top first, and on top second place the correct value for the last day of month.
Does anyone know why that happens? In source data there is 31/7/2020 with only 9.546.
You are applying the filter in the wrong field. You must apply it to your AMOUNT field, and you are applying it to your ITEM field (the field that holds the value VEL).
This is happening because you are working in the compact view of Pivot Table, and I think it's easier to work in tabular design.
Design the layout and format of a PivotTable
My Pivot Table is like this:
As you can see, ITEM and AMOUNT field are in the rows section. And DATE field in the Values section, set to MAX DATE and renamed as LATEST.
The filter is applied in the field AMOUNT.
I know what you mean, but actually the filter is applied on the correct field/row. See the prtscrn.
For the references, I attached the source table too.
btw, if I tried filtered out the column Note it still doesn't work properly

Spotfire- limiting Information link colum expression

I have a column of data [Sales ID] that bringing in duplicate data for an analysis. My goal is to try and limit the data to pull unique sales ID's for the max day of every month in the analysis only (instead of daily). Im basically trying to get it to only pull in unique sales ID values for the last the day of every month in the analysis ,and if the current day is the last day so far then it should pull that in. So it should pull in the MAX date in any given month. Please how do i write an expresion with the [Sales ID] column and [Date ] column to acieve this?
Probably the two easiest options are to
1) Adjust the SQL as niko mentioned
2) Limit the visualization with the "Limit Data Using Expression" option, using the following:
Rank(Day([DATE]), "desc", Month([DATE]), Year([DATE])) = 1
If you had to do it in the Data on Demand section (maybe the IL itself is a usp or you don't have permission to edit it), my preference would be to create another data table that only has the max dates for each month, and then filter your first data table by that.
However, if you really need to do it in the Data on Demand section, then I'm guessing you don't have the ability to create your own information links. This would mean you can't key off additional data tables, and you're probably going to have to get creative.
Constraints of creativity include needing to know the "rules" of your data -- are you pulling the data in daily? Once a week? Do you have today's data, or today - 2? You could probably write a python script to grab the last day of every month for the last 10 years, and then whatever yesterday's date was, and throw all those values into a document property. This would allow you to do a "Values from Property".
(Side Note: I want to say you could also do it directly in the expression portion with something like an extremely long
Date(DateTimeNow()),DateAdd("dd",-1,Date(Year(DateTimeNow()), Month(DateTimeNow()), 1))
But Spotfire is refusing to accept that as multiple values. Interestingly, when I pull the logic for a StringList property, it gives this: $map("${udDates}", ","), which suggests commas are an accurate methodology, but I get an error reading "Expected 'End of expression' but found ','" . Uncertain if this is a Spotfire issue, or related to my database connection)
tl;dr -- Doing it in the Data on Demand section is probably convoluted. Recommend adjusting in SQL if possible, and otherwise limiting in the visualization

Change date format on category axis in my PowerPivot column chart

I'm trying to show values based on date on a PivotChart (column) in Excel. The problem is that the category label does not seem to follow the number formatting I set. Yes, the underlying table is formatted as date type. I've Googled a bit and the fix that seems to work for most people is to have complete data set (no holes or empty cells). My dataset is complete, so it doesn't help me.
Any ideas?
If you want guaranteed consistency of display format, make a display date string in your date dimension that is formatted the way you like. Use this for labels in pivot tables and charts.
You will also have to sort this field by your date field in the model to make sure they display in chronological order.
This is not possible with data linked from a PowerPivot data model. It is something Microsoft has been aware of for a long while but unfortunately they haven't implemented the functionality you desire.
There is, however, one work around: you can create a calculated column using =FORMAT(<date>,"<date format>"). If you use the formated column instead of your usual date column the axis will be formatted according to your needs.
This is old, but creating a calculated column using =FORMAT(,""), With this approach you lose the ability to sort the Axis in proper date order.

Calculating the difference between the count of two date fields

I have data that is provided to me that includes the routed date and the service restoration date. From that it's pretty easy to generate a pivot table that generates a table with the date of the month, then a count of received tickets (routed), and the count of closed tickets. I'm trying to generate a calculated field (Pivot -> Options -> Fields, Items & Sets -> Calculated Field) to derive the delta.
When I use =Received - Closed, I get the difference in date rather than the delta in the counts. Can anyone point me in a direction on how I may calculate it? If it was static content it would be easy peasy, but I'm not getting the knack of doing this with a pivot table. Also I could achieve something similar with a countif type command and run it from a static calendar type table (which is what I'll probably end up doing if this ends up being a dead end).
As a solution, you can copy the pivot table and paste it as values in the new sheet. Do you math on values instead of on pivot.
I don't know if formatting your results in the pivot as NUMBER would help.. But you can try that as well.
I was unable to determine a way outside of what was mentioned above by Andrew. I've set up a static date list for the calendar month and then use a series of countifs instead of a pivot table to generate the output. Thanks to all who reviewed the question and to Andrew for his responses.

Get the average monthly value from 2 SP List columns and display in new column

I need to calculate the average value for each month. Currently I have 2 columns "DATE" (date value e.g 01/01/2010) and AccOpen (number value). So for all dates within January I need to return the average value of all numbers contained in the corresponding AccOpen rows for January dates.
Is it possible to use the CALCULATED option and input a FORMULA that will return the average for all itmes within each months period (when adding a column to the list ?
DATE ACCOPEN AVERAGE
01/01/2010 2 2
02/01/2010 2
03/01/2010 2
04/01/2010 2
01/02/2010 2 2
02/02/2010 2
03/02/2010 2
04/02/2010 2
You're not going to be able to do this OOTB without writing event receiver code (or other custom code running in a batch mode).
To get you started
MSDN - How to: Create an Event Handler Feature
Event Handlers : Everything you need to know...
This will need to hook into the list item update and then consolidate your list into a separate summary list with the calculations you need.
The brute force approach would be to run the calculation afresh for every item in the group when an item is inserted/updated.
A smarter approach would be to just update the delta (the difference between the old and the new record) which is easier to do if you store components of the calculation - so in your case
Month - NumRecords - TotalValue
and work out the Average on the fly (as its easy to delta the NumRecords/TotalValue but impossible to apply it directly to the average)
One 3rd party web part which may fit your need is PivotPoint - it allows you to do things like sum/count/avg over groups like Month & Year (disclaimer - I work for the company)
It is not possible to query anything other than the current item when creating a formula field.
The only way to do this is to create custom code either within an event handler for the list or external code that processes items in the list and updates a "average" field when required.
Create a calculated field to give you the year and month, for example: 2011-07. Then modify your list view to group on the calculated field. When editing your view, there is also an option to display totals, I believe you can set this to average for your AccOpen column. If you're not interested in the details, you can choose to collapse all groups by default.

Resources