Pivot tables in excel - showing last values - excel

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

Related

How can I transpose and summarize data appropriately in PowerQuery?

I'm working on achieving the following data transformation/wrangling within Power Query but can't seem to get there on my own. i have read a lof of different questions and answers on the forum but it seems just a bit beyond my grasp.
I have a table which has the ticker of a specific currency in the first column.
There is a second column with the date and time when a certain event, related to that specific currency, happens. This second column is basically the different 5-minute intervals which exist on any given day.
Finally there is a third column which describes the magnitude of the event.
The table therefore looks like this
What I would like to do in power Query is transpose the uniques name of the currencies as the first row of a new table. The first column of this table would be the largest time interval for any given currency. In this case, as you can see in the data I am attaching, the largest timeseries would be that of the currency ETH. Using the longest calendar as our first column I would then like to place the values described in item 3 above as rows in the new table.
The new layout would look like this
My steps to transform the raw data in the first table are detailed in this image. Basically just expanding a JSON file and getting all the data I need into that first format which I described previously.
What I then do is:
Pivot using the first column
Transpose
That gives me a whole bunch of new columns. Way more than I want. Any idea what I can do differently?
In powerquery,
click select pair column
Transform .. pivot column .. values column: basis advanced options: do not aggregate
code:
#"Pivoted Column6" = Table.Pivot(YourPriorStepName, List.Distinct(Source[pair]), "pair", "basis", List.Sum)
output:

Default date aggregation for Excel

What is the default behavior of adding a date, time, or datetime into an Excel pivot row/column? I have seen it sometimes add it as the "raw value", sometimes it will add it as a Year > Query > Value, and other times (?) perhaps in between. For example:
When does Excel add it without aggregating it, and when does Excel aggregate it? Does it have to do with value cardinality, date range, or something else?
First, every entry in the column has to be a date/time or you won't be able to group them. In that case, obviously, the default would be not grouped.
Assuming everything is groupable, the default is no grouping. Each date will show individually.
The exception is if a pivot cache already exists. In that case it will group based on what the pivot cache says - the last way that field was grouped. This happens when you have more than one pivot table on the same data. The first pivot table creates the cache and all subsequent pivot tables use that existing cache.
In a new workbook (2010), I add a date field to the Row Labels and they are initially ungrouped by default.
I group them by month
Now I go back to the original data and make a new pivot table. I add the date field to the Column Labels.
Because it uses the same cache, it automatically has them grouped the same way. Finally, I go back to the source data and replace one of the dates with a string. If I create another pivot table, it will look like the others. But when I refresh it ungroups them because I have a non-date in there.
And if I try to Group now, it says "Cannot group that selection"
That's why it works the way it does - shared pivot cache. There are ways you can give each pivot table it's own cache but that uses more memory. However, if you want to group the same data differently, that's what you have to do.

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

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]

Excel - De-cumulate data in pivot table

Hope you'll be able to help me.
I have a table with 11 columns, the first one is a date, the next 9 ones are a way of uniquely identifying data and the 11th is a certain amount of money.
What I'm doing in a pivot table is showing the added amount according to one of the identifiers (lines) and dates (columns).
All is well and quite easy to do in a pivot table. Today though I was told that the amounts in my source table are actually cumulative since the beginning of the year.
What I mean is that there are recurring entries in that table and that if I have an entry with the 9 identifiers in january and the same in february and march for example, the value of the one in february is actually (february-january) and for march (march-february).
I could through the unique identifiers just add a column in my source table to identify and calculate the real amount, but I was wondering if there was a way to do so in the pivot table directly ?
Thanks !
Edit :
Here is a screenshot of a simplified version (only two identifiers)
In the fourth column is the amount I have, and in the fifth the real one, that I have to calculate, it is quite easy with only two columns as identifiers.
The goal here is that the pivot table at the bottom shows the "real" amount without me having to create a new column in my source table.
My example table
You can do it using Calculated Items. But it is cumbersome.
A Calculated Item is just another item that a Pivot Table field can take. It is defined in terms of the other items in the same field. For example, the field Date might have values of Jan17, Feb17, etc. A new calculated item called Difference can be added to the Date field and defined as =Feb17-Jan17. This new Difference item will appear whenever the Date field is used to provide row or column labels and the values displayed for it in the main body of the pivot table will be equal to the corresponding values for Feb17 less those for Jan17.
The discussion below is based (loosely) on the pivot table in the picture accompanying the question.
Calculated Items cannot be calculated on grouped fields, so it will be necessary to ungroup the Date field in the pivot table. This will cause the items in the field to be displayed in the same dd/mm/yyyy format as the source data. Changing these to the custom format of mmmyy makes them easier to work with. In English (rather than French) they get displayed as Jan17, Feb17, etc. using this format.
To add a new Calculated Item to the Date field, select any item in this field and locate the Calculated Item option via the ribbon. This has changed across versions of Excel, in Excel 2010 it is accessed via the "Fields, Items & Sets" button of the "Pivot Table Tools/Options" tab of the ribbon. In later versions it accessed via the "Calculations" button of the same tab. A dialog box will appear as illustrated below.
In the Name: box insert a suitable name such as Feb17Xand in the Formula: box enter =IF(Feb17=0,0,Feb17-Jan17). Click "Add" then "OK". The new Date item labelled Feb17X will appear in the pivot table and will show values of 20, 0 and 0 against projects A, B and C respectively.
Feb17X is the decumulated Date item for February. The IF is necessary because although the Amountvalues are cumulative, they only appear in the source data whenever a new Amount occurs in the month (for example Project B and Department IS has data showing for April and June but not for May).
Similar decumulated Date items can be defined in the same way for the other months.
For March, Mar17X is defined as
=IF(Mar17=0,0,Mar17-(Jan17+Feb17X))
and a new Mar17X item is added to the Date field. Unfortunately, this shows values of -28, 0 and 0 against projects A, B and C, respectively. To get the correct values displayed, it is necessary to add the Department field to the row labels in the pivot table (below the Project field) and then to use the "Collapse Entire Field" operation to stop the detail of the Department field from being visible.
The calculated items for the remaining months are added as expected - that for June is Jun17X and has formula
=IF(Jun17=0,0,Jun17-(Jan17+Feb17X+Mar17X+Apr17X+May17X))
Once the new items have been defined for the Date field, a filter is applied in the pivot table to remove the cumulative items ie, Feb17, Mar17, Apr17, May17 and Jun17. This results in the pivot table displaying the sum of the decumulated values as shown below.
A few points:
The zeroes in the pivot table can be suppressed from display by setting the number format of the Amount field to #
In the larger problem where each Amount is defined by a Date, Project and 8 further field values, the row labels of the pivot table will need to include Project and all 8 of the attribute fields. The latter 8 fields will need to be "collapsed out" of the display.
It is much, much simpler to add a decumulated Amount column to the
source data range rather than using the Calculated Item approach set
out here. Sorting the source data by the 9 attributes (Project
first then the remaining 8) and then by Date makes the task
of decumulation very easy. Simply compare the 9 attributes in a row
with the previous row: if the values are unchanged between the two
rows, subtract the previous row's Amount from the current row's,
otherwise leave the current row's Amount unchanged.

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.

Categories

Resources