Excel pivot table calculated fields - referring to other dimensions in equation? - excel

I'm struggling to find much useful documentation on Excel 2013 pivot table calculated fields.
My pivot table is fairly simple. I have a 'Company' dimensions as rows (e.g. 'A', 'B' etc) and calendar weeks as columns ('1' --> '52'). The value in the grid shows a date based status value. For example, for Company 'A' there are date based state source rows that are shown under 'week 6', 'week 14' and so on.
What I'm trying to do is inject a value into this pivot table to replace blank/null values. For instance, for Company 'A' there are no values for weeks 7 thru 13. In this case I want to inject a calculated field that looks for the last known value for Company 'A' and then uses that last know value. In this case the calculation for week 7 would detect that the value is null and find the last non-null value (week 6) and use that. The equation might be something like:
derived state = if(State=0, if(previous non null value > 0, previous non null value,0),0)
However, I can't find any docs that explain how to set up an equation that uses multiple dimension references and uses some form of lag or last known value finder function.
Any suggestions?
Thanks in advance!

One workaround is to fill in your null values. Then use the new data as the source for your pivot table. Below is a method of "copying" your data without modifying the original.
If this is your source data starting in cell A1:
1 2 3 4 5
1/1/2014 1/8/2014 1/15/2014 1/22/2014 1/29/2014
1/2/2014 1/9/2014 1/16/2014 1/23/2014 1/30/2014
1/3/2014 1/10/2014 1/17/2014
1/4/2014 1/11/2014 1/18/2014
this formula in cell F2 and pasted across will fill in your blank cells in for week 4 and 5.
=IF(A2<>"",A2,MAX(OFFSET(A2,0,-1*(A$1-1)):A2))
Step by step through the formula
check that A2 is not blank
if it isn't blank, copy the value in A2
if it is blank, choose the max (most recent) date from that row
the max should suffice for getting the last non-null value if the week columns are chronologically ordered

Related

Recursive Function & Looping In Excel

I am looking for some guidance in looping through a function in Excel within a table without running into a circular reference error. I've spent quite some time trying out COUNTIF, MATCH, Essentially, I need to create a function/formula for the "Desired Date" column so that it takes value from the "Original Date" column and changes the value based on the following parameter:
If a date in the Original Date column does not exist within the previous values of the Desired Date column, it will list the exact date. I've already solved this part with IF and COUNTIF functions.
If a date in the Original Date column already exits within the previous values of the "Desired Date" column, it will add +1 day(s) until all the values within the Desired Date column have unique dates.
Here's what I would like the function to do:
Row 1 contains the original date value as 8/1, since no other values exist in the desired row column, it will return 8/1.
Row 2 contains the original date value as 8/1, but since row 1 of the desired date value already contains value 8/1, it will add +1 day so it becomes 8/2.
Row 3 contains the original date value as 8/1, but since row 1 & row 2 of the desired date contain the value, it will add +2 days, so it becomes 8/3.
Row 6 contains the original date value as 8/3, but since row 3 of the desired date contain the value, it will add +1 day so it becomes 8/4.
If at any given point a date within the original date changes, the values in desired dates should change accordingly by adding a variable amount of days until all values within the Desired Dates column are unique.
Row
Original Dates
Desired Dates
1
8/1/2021
8/1/2021
2
8/1/2021
8/2/2021
3
8/1/2021
8/3/2021
4
8/12/2021
8/12/2021
5
8/12/2021
8/13/2021
6
8/3/2021
8/4/2021
7
8/4/2021
8/5/2021
8
8/3/2021
8/6/2021
9
8/13/2021
8/14/2021
I've spent well over 9 hours on this issue so any help at this point would be very much appreciated. I wouldn't mind using VBA but a function would be preferred for compatibility purposes.
Thank You!
One approach might be to generate dates starting with the date in the first column but ignoring any dates that have already been used (countif>0), then pick the lowest of these:
=LET(maxdate,$D$2,
startdate,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
MIN(IF(COUNTIF(E$1:E1,seq),maxdate,seq)))
or slightly shorter
=LET(maxdate,$D$2,
startdate,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
MIN(IF(COUNTIF(E$1:E1,seq)=0,seq)))
If you don't have Excel 365, you can use Row instead of Sequence:
=MIN(IF(COUNTIF(E$1:E1,ROW(INDEX(A:A,B2):INDEX(A:A,$D$2)))=0,ROW(INDEX(A:A,B2):INDEX(A:A,$D$2))))
entered as an array formula using CtrlShiftEnter
EDIT
If you wanted to concatenate as in your comment, you wouldn't be able to use Min (because the values wouldn't be numeric) but you could use index/match to find the first available date for a particular person:
=LET(maxdate,$D$2,
startdate,A2,
name,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
seqName,seq&name,
INDEX(seqName,MATCH(0,COUNTIF(H$1:H1,seqName),0)))
If you wanted to make the dates appear as a date rather than a number, you could wrap them in Text:
=LET(maxdate,$D$2,
startdate,A2,
name,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
seqName,TEXT(seq,"mm/dd/yy")&name,
INDEX(seqName,MATCH(0,COUNTIF(H$1:H1,seqName),0)))

Get row-column coordinates of all matches in Excel table

I have a table of dates and a variable date range and need to find all matches for rows and columns where a date in the table lie within the range of my start/end date range.
As a (downscaled) example of my case:
Start date: 01Jan2018
End date: 30Jun2018
Table with dates:
{01Jan2018; 01Feb2018; 01Apr2018}
{17Mar2018; 05Jun2018; 16Aug2018}
{11Apr2018; 01Jul2018; }
Some fields in the table may be blank if no date has been entered yet. I believe I can make a comparison array by running the start/end dates against the date array, e.g. with
=--(array>=start_date)*(array<=end_date)
which would output
{1;1;1}
{1;1;0}
{1;0;0}
But what's the next step to get from here to a vertical list of row-column sets where row and column number is in separate cells? From the example above I would need a list like:
1 1
2 1
3 1
1 2
2 2
1 3
I have other arrays sized like the date array that I need to match the found coordinates against to look up other data using the found coordinates.
Try:
=IF(AND(A4>=$B$1,A4<=$B$2),"In","Out")
Results:
A bit of a long formula, but basically this one formula will:
Get the relevant date using index (based on the row() ) and the matrix (3x3)
Conversion to 1 & 0's based on whether it's between the dates
Return the Column / Row number if 1
For Column:
=IF(--(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))>=$B$1)*(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))<=$B$2)<>0,ROUNDUP((ROW()-1)/3,0),"n/a")
For Row:
=IF(--(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))>=$B$1)*(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))<=$B$2)<>0,IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)),"n/a")
Image of the excel solution
Based on the size of you array, you need to create list of all coordinates (formulas to generate it at the end of the post). Then bring the value from this coordinate, check against your condition (column "C") and filter where TRUE (column "D").
And with formulas shown:
Result (highlighted with green):
Here are two formulas generating the list of columns and rows based on data range size:
A9: =IF(B9="end";"end";MOD(ROW(C1)-1+COLUMNS($A$1:$C$3);COLUMNS($A$1:$C$3))+1)
B9: =IF(1+INT((ROW(C1)-1)/COLUMNS($A$1:$C$3))>COLUMNS($A$1:$C$3);"end";1+INT((ROW(C1)-1)/COLUMNS($A$1:$C$3)))

EXCEL - SUM column if date matches TODAY()

I've tried using SUMIF to obtain my results but it doesn't work properly.
I have a row of dates (XX/XX/XXXX format) and I would like to check this row for the current date.
If the row contains the current date, then I would like to sum the total of that column and row 5-20.
For example - today is 10/13/2016. I would like to search for TODAY() in a certain row (Row 1 for example), and if TODAY() is found, then total this column from row 1 down to row 3.
--A-- --B--
10/13/2016 10/14/16
1 50 10
2 10 4
3 5 6
The result should be 65 only IF the date matches TODAY().
I've also checked on giving the column letter based on the date but with no luck.
Any tips are appeciated! Thank you.
I think you can achieve this with a simple IF and a SUM
i.e. in your example above if you want the result to appear on the bottom row you can just use:
=if(B2=today(), sum(B3:B5), "")
This will display the sum at the bottom of the column for columns where the date = today and a blank in the other columns
You need to use the OFFSET function. You can find the documentation here: https://support.office.com/en-us/article/OFFSET-function-C8DE19AE-DD79-4B9B-A14E-B4D906D11B66
In your particular example the following formula will work:
=SUM(OFFSET(D2, 1, MATCH(B2, $D$2:$F$2, FALSE) - 1, 20))
You can see the formula working below. Assuming you know what the SUM formula is doing, I will explain what the OFFSET formula is doing:
First Parameter: Says start at cell D2
Second Parameter: This is how many row up/down do you want to do. In your case you need start at row below the date so '1' it is.
Third Parameter: This is how many columns to the right do you want to
go. Well the number of columns you want to go is based upon where
your date is. So this uses the match formula to figure out how far
to the right to go.
Fourth Parameter: This is how many row do you want to include. I just picked 20 to include the 20 rows below the selected cell.
You obviously need to modify the parameters a little bit to fit your exact data shape.
So I'll give it a shot:
{=SUM(HLOOKUP(TODAY(),Table_With_Dates_and_Three_Rows_Cell_Reference,{2,3,4}))}
NB: Don't type {} but put the formula inside it and then hit Ctrl+Shift+Enter to create what is called an array formula (it does array calculations element by element then submits the aggregating function value---in this case that is sum).

the result of calculated new column is not right

There is a table of 12 columns. I would like to add an extra column, where each entry stores the average value of the corresponding row across those 12 columns. I use the feature "Calculated new column" to fulfill this task. After getting the result, I noticed that the average value was returned as zero when one of the 12 columns has zero value on that specific row. For other rows, the calculation is just OK if none of the entries in those 12 columns is zero. I attached the screenshot of resulting table and the calculation procedure in the data table properties for your reference. Would you like to let me know the possible reason?
average value was returned as zero when one of the 12 columns has zero
Actually you don't have zero values, but null values, which is different! Use SN() function to manage null values (need to use for all the columns)!

Excel: If Cell in Column = text value of X, then display text (in the same row, but different column) on another sheet

This is a confusing request.
I have an excel tab with a lot of data, for now I'll focus on 3 points of that data.
Team
Quarter
Task Name
In one tab I have a long list of this data displaying all the tasks for all the teams and what Quarter they will be on.
I WANT to load another tab, and take that data (from the original tab) and insert it into a non-list format. So I would have Quarters 1,2,3,4 as columns going across the screen, and Team Groups going down. I want each "task" that is labeled as Q1 to know to list in the Q1 section of that Teams "Block"
So something like this: "If Column A=TeamA,AND Quarter=Q1, then insert Task Name ... here."
Basically, if the formula = true, I want to print a list of those items within that team section of the excel document.
I'd like to be able to add/move things around at the data level, and have things automatically shift in the Display tab. I honestly have no idea where to start.
If there is never a possibility that there could be more that 1 task for a given team and quarter, then you can use a formula solution.
Given a data setup like this (in a sheet named 'Sheet1'):
And expected results like this (in a different sheet):
The formula in cell B2 and copied over and down is:
=IFERROR(INDEX(Sheet1!$C$2:$C$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$B$2:$B$7=B$1),),0)),"")
I came across this situation. When I have to insert the values into a table from an Excel sheet I need all information in 1 Column instead of 2 multiple rows. In Excel my Data looks like:
ProductID----OrderID
9353510---- 1212259
9650934---- 1381676
9572474---- 1381677
9632365---- 1374217
9353182---- 1212260
9353182---- 1219361
9353182---- 1212815
9353513---- 1130308
9353320---- 1130288
9360957---- 1187479
9353077---- 1104558
9353077---- 1130926
9353124---- 1300853
I wanted single row for each product in shape of
(ProductID,'OrdersIDn1,OrderIDn2,.....')
For quick solution I fix it with a third column ColumnC to number the Sale of Product
=IF(A2<>A1,1,IF(A2=A1,C1+1,1))
and fourth Column D as a placeholder to concatenate with previous row value of same product:
=IF(A2=A1,D1+","&TEXT(B2,"########"),TEXT(B2,"########"))
Then Column E is the final column I required to hide/blank out duplicate row values and keep only the correct one:
=IF(A2<>A3,"("&A2&",'"&D2&"'),","")
Final Output required is only from Column E
ProductID Order Id Sno PlaceHolder Required Column
9353510 1212259 1 1212259 (9353510,'1212259'),
9650934 1381676 1 1381676 (9650934,'1381676'),
9572474 1381677 1 1381677 (9572474,'1381677'),
9632365 1374217 1 1374217 (9632365,'1374217'),
9353182 1212260 1 1212260
9353182 1219361 2 1212260,1219361
9353182 1212815 3 1212260,1219361,1212815 (9353182,'1212260,1219361,1212815'),
9353513 1130308 1 1130308 (9353513,'1130308'),
9353320 1130288 1 1130288 (9353320,'1130288'),
9360957 1187479 1 1187479 (9360957,'1187479'),
9353077 1104558 1 1104558
9353077 1130926 2 1104558,1130926 (9353077,'1104558,1130926')
You will notice that final values are only with the Maximum Number of ProductSno which I need to avoid duplication ..
In Your case Product could be Team and Order could be Quarter and Output could be
(Team,Q1,Q2,....),
Based on my understanding of your summary above, you want to put non-numerical data into a grid of teams and quarters.
The offset worksheet function will work well for this in conjunction with the match or vlookup functions. I have often done this task by doing the following steps.
In my data table, I have to concatenate the Team and quarter columns so I have a unique lookup value at the leftmost column of your table (Note: you can eventually hide this for ease of reading).
Note: You will want to name the input range for best formula management. Ideally use an Excel Table (2007 or greater) or create a dynamically named range with the offset and CountA functions working together (http://tinyurl.com/yfhfsal)
First, VLOOKUP arguments are VLOOKUP(Lookup_Value,Table_Array,Col_Index_num,[Range Lookup]) See http://tinyurl.com/22t64x7
In the first cell of your output area you would have a VLOOKUP formula that would look like this
=Vlookup(TeamName&Quarter,Input_List,Column#_Where_Tasks_Are,False)
The Lookup value should be referencing cells where you have the team names and quarter names listed down the sides and across the top. The input list is from the sheet you have the data stored. The number three represents the column number the tasks are listed in your source data, and the False tells the function it will only use an exact match in your putput.

Resources