How to transpose a dynamic width table in Alteryx - alteryx

I have several CSVs with dynamic width and I need to address the last, second last column of every csv to transpose them.
That's how my file looks like:
Product | 2015-08-01 | 2015-09-01 | 2015-09-01 | 2015-10-01| Comment
ABC | 13 | 12 | 15 | 14 | Strong
CDE | 69 | 70 | 71 | 67 | Weak
FGH | 25 | 25 | 26 | 27 | Stable
With every new release of that excel file a date column is added and the comment adjusted for the last date:
Product | 2015-08-01 | 2015-09-01 | 2015-09-01 | 2015-10-01| 2015-11-01| Comment
ABC | 13 | 12 | 15 | 14 | 12 | Weak
CDE | 69 | 70 | 71 | 67 | 67 | Stable
FGH | 25 | 25 | 26 | 27 | 29 | Strong
For now I transpose two different sets, firstly I choose the comment and last date manually and secondly all other prices. Afterwards I join them and all is good. The problem is that I have a big set of files from the last years and I would need to set the last date dynamically to have a transposed table like this:
Product | Date | Comment | Price
With Product, Date and Price filled for every record and Comment just filled for the last reported date. Is there a way to do this?
related to this post:
How to resolve duplicate column names in excel file with Alteryx?

It seems that what you want to do is to split that Comment column into it's on data stream?
After the transpose, you can crosstab into a form that contains the products as headers and the dates and comments as individual rows. Then a filter can pull the comment row out. A sort on the Name field would also let you grab the last row in that dataset to know which one was the last date.
For the crosstab:
- Grouping Fields: Name
- Header Field: Product
- Data Field: Value
Methodologies: Concatenate

Related

Adding fields to Pivot Table from another datasource using VBA

I've created Pivot Tables before using VBA but my professor recently gave us a bonus that although is not necessary, is driving me nuts.
Use a VBA Macro to write Region, District, and Store Name to your first report to create a new report
1) My first report looks like this:
Location | Sum of ActNetSales | Sum of PlanNetSales
----------|--------------------|---------------------
1 | $76,170 | $65,172
100 | $163,691 | $140,057
101 | $34,724 | $29,710
104 | $70,501 | $60,322
106 | $113,826 | $97,391
2) Below is the data source for the above report.
Division | Year | Week | Location | SchedDept | PlanNetSales | ActNetSales | AreaCategory
----------|------|------|----------|-----------|--------------|-------------|--------------
5 | 2018 | 10 | 520 | 541 | 1943.2 | 2271.115 | Non-Comm
5 | 2018 | 10 | 520 | 608 | 4378.4 | 5117.255 | Non-Comm
5 | 2018 | 10 | 520 | 1059 | 1044.8 | 1221.11 | Comm
5 | 2018 | 10 | 520 | 1126 | 6308 | 7372.475 | Non-Comm
3) My professor wants me to add the following information to the above table: Region, District and Store Name. However, these 3 fields are from a different data source then the above report. Below is the data source for the 3 fields I've listed.
Division | Location | LocationName | Region | RegionName | District | DistrictName
----------|----------|--------------|--------|------------|----------|--------------
5 | 1 | Location 1 | 3 | Region 3 | 18 | District 18
5 | 4 | Location 4 | 5 | Region 5 | 32 | District 32
5 | 5 | Location 5 | 3 | Region 3 | 19 | District 19
5 | 6 | Location 6 | 5 | Region 5 | 28 | District 28
I've created what he's asking above by joining the 2 tables (created a key by concatenating the foreign keys - location and division: to make a unique key and using a basic index/match ) and just creating a Pivot Table from that but I want to try my best to solve the bonus! Unfortunately, I don't have Power Query so I had to do it this way. I've tried searching up the above and I can't find any good resources. Is there anything you can suggest or just point me in the right direction? Thank you!
Is it cheating to modify your table under (2) to add the columns region, district, and storename using VLOOKUP on the third table? The second table would then have raw data, and extra columns of constructed data, effectively joining it to the third table using the Excel VLOOKUP trick rather than an actual SQL table join.
Then you can just use the expanded, joined table as your one Pivot Table source.
Cheating is legal in love, war, and IT solutions.

Can I use COUNTIF function with or in GETPIVOTDATA?

I have a pivot table something like this...
Duration
Run#| Product A | Product B | Product C |
01 | 2:01:00 | | 2:45:00 |
02 | 2:02:00 | | 2:45:00 |
03 | | 2:04:00 | 2:45:00 |
04 | 2:03:00 | 2:02:00 | 2:45:00 |
...
SUM | 6:06:00 | 4:06:00 | 11:00:00 |
I would like to use use GETPIVOTDATA to find an average of the times in the pivot table (not the source data)
So, my averages would be...
Product A | Product B | Product C |
2:02:00 | 2:03:00 | 2:45:00 |
Can accomplish that with GETPIVOTDATA? If so, how?
If not, is there another function available?
I have already built the average in a 2nd table using the Sum and a "count" function but it uses table references (i.e., COUNT(B4:B49)) which are a bit clunky since my pivot table will grow over time as more "runs" are completed (past row 49 which is the row of the latest run).
Something like this will grow with the Table:
=AVERAGE(B4:INDEX(B:B,MATCH(1E+99,B:B)-1))
It basically finds the range starting in B4 to the last row with number minus one so it does not include the total.

SUMIFS on filtered data?

I am looking for a way to do a SUMIFS that uses a filtered list. I would like to:
Grab all the sales from Sheet "Sales" where Group = "Flowers", AND
Store # on Sheet "Sales" matches the Filtered Store # list on sheet" Report
The following code will work only when there is no filter on the Store #'s:
=SUMIFS(Sales!C:C,Sales!B:B,"=FLOWERS",Sales!A:A,Report!A:A)
Sheet 1 Name = Report
Row (filtered) Store # (A)
====================|==============|
| 21 | 13 |
| 36 | 28 |
| 81 | 75 |
| 84 | 78 |
Sheet 2 Name = Sales
Store # (A) Group (B) Sales (C)
===========|==============|=============|
| 21 | Flowers | $100 |
| 36 | Flowers | $200 |
| 81 | Bread | $500 |
| 1 | Flowers | $600 |
| 3 | Flowers | $100 |
| 36 | Bread | $200 |
| 8 | Bread | $100 |
| 84 | Flowers | $300 |
Is there any way for me to accomplish this? So if when the filtered list changes, the total figure changes, similar to that of a subtotal.
Seems much the easiest way is with a PivotTable: Group (B) for FILTERS, Store # (A) for ROWS and Sum of Sales (C) for VALUES, then filter Group (B) to select 'Flowers` and filter rows to suit.

How to return the header by value in a PivotTable

I have a PivotTable like this:
Sum of Gf_Amount | Column Labels
| 2015 | | | | Grand Total
Row Labels | 17-Mar | 18-Mar | 19-Mar | 20-Mar |
3601 | 20 | 20 | | | 40
10386 | 35 | | | | 35
76301 | 5 | | | | 5
80941 | | | | 10 | 10
205738 | | | 5 | | 5
219576 | | 15 | | | 15
Grand Total | 60 | 35 | 5 | 10 | 110
What I want do is find the last non-empty column and return the date according to the value. For example: for ID 3601 the result should be 2015 18-Mar.
Currently I know how to find the last non-empty column by using =LOOKUP(9.99E+307,B6:E6). For ID 3601 it gives me 20 which is correct. However when I use:
=INDEX($B$5:$E$5,MATCH(LOOKUP(9.99E+307,B6:E6),B6:E6,0))
to find the header, it gives me 17-Mar which is the corresponding header for the first 20. Besides, the formula I wrote can't even give me the year.
Can anyone help me out so I can find the date and year? (It doesn't have to be in PivotTable. You can copy and paste it in a normal table.)
I'm guessing that your column labels are date indices formatted as dd-mmm so there is no need to find the 2015 that is displayed hence:
=INDEX($5:$5,MATCH(1E+100,A6:E6))
formatted as say dd-mmm-yyyy and presumably copied down may suit.
It is a peculiarity (perhaps never really intended) of the MATCH function that, without the optional argument, where it can’t find a match in a list it returns the index of the last entry in the list – very useful, as here, at times! So all the “big number” (there are lots of versions of it – for example the one you used 9.99E+307) does is feed MATCH a number so large it is never likely to find it (to force selection of the last entry).
I like 1E+100, a googol, as short and easy to remember, and for its ‘derivation’. 9.99E+307 is theoretically better as closer to the largest number Excel can handle:
9.99999999999999E+307
but
10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
for me is big enough – I don’t expect ever to want to work with a number bigger than that and smaller than or equal to 9.99E+307.

Convert Rows into Columns with same values

Let's say I've a table
ID | Item | Purchased
17 | Chocolate | 1304
17 | Biscuit | 1209
17 | Jelly | 657
17 | Milk | 2234
18 | Chocolate | 1000
19 | Jelly |2387
I want to convert the rows into columns for each Item through Pivot tables in Excel
ID | Chocolate_Purchased | Biscuit_Purchased | Jelly_Purchased | Milk_Purchased
17 | 1304 | 1209 | 657 | 2234
18 | 1000 | | |
19 | | | 2387 |
How do I do that in Excel?
One simple way is with a Pivot table, although you may need to do some massaging to get exactly the output format you want.
With ID-->Rows; Itme-->Columns and Purchased--> Values, you can easily produce a Pivot looking like:
And you can do all kinds of different things with the formatting.

Resources