What I'm trying to do is, I have on the sheet of multiple dates (report dates) in column A and a transition date column in column E. From B - D I have numbers in each column corresponding with actual price then fees. What happens in this is sheet is reports come in and get transitioned on a specific date and switches fees from Column C (Before Transition Date) to Column D (After Transition Date). What I want to do with the Pivot table is this:
I want to be able to add column B & C but when the item hits the transition date to switch over to adding B & D and continues the SUM of it all. My thought process is it would have to do a IF statement, something along the lines of
IF(Transition Date >= Date, Add B & C, IF(Transition Date <= Date, Add B & D),0)
But I could be wrong, just trying to figure this part out on a Pivot Table. Again I am new with Pivot Tables so if my terminology is incorrect please correct me.
If i have understood you correctly you want to add a calculated field to your pivot.
Say your data looked like this Range("A1:E4") in image:
You would add a calculated field to the pivot (Starting row 13 in image) using the following formula:
=IF(Date < TransitionDate, Cost + 'Ore Fee', Cost + 'Mineral Fee')
This equates to:
=IF(ReportDate < TransitionDate, ColB + BeforeTransitionDate, ColB + AfterTransitionDate)
Your mileage on layout may vary as i am using an old mac which is not ideal for pivottables and i have hidden some irrelevant pivot fields.
Windows machine i think you add a calculated field by selecting a cell inside the pivot, the going to Analyze -> Fields, Items, & Sets -> click the little down arrow -> Calculated Field. Example here
Layout of pivot:
Where to enter calculated field:
And comparing with in sheet formulas without pivottable see Column H rows 14:16 (formula i gave from the comments):
There seems to be no need for a PivotTable here, as you can create an additional column (say, ActualPrice) that conditions on summing columbs B & D or C & D:
In the above example, TransactionDate and TransitionDate were made with =DATE(2017,12,randbetween(1,31)), with conditional formatting highlighting the TransactionDates that are on-or-after/before TransitionDate in red/green. The ActualPrice is calculated as =IF(A2<E2,B2,C2)+D2.
If you want you can create a PivotTable to aggregate all of this, or just return the total sum in some cell (outside Column F) as =SUM(F:F).
Related
I have list of IDs with warehouse stocks and list of shipments to customers which might have same ID.
Attached screen with example, so for 29.08.2022 with hour 08:00 we need to have 100 carrots, on warehouse we have 375pcs = 275pcs are left. Then few hours later we have shipment to other customer which requires 500pcs of carrots, 275-500 = -225pcs -> it shows info we need to harvest that much more untill 11:00.
needed vlookup for value from stock
then subtract every repeated value from top to bottom
carrots example screen
Looking for formula or vba which could handle this calculation without manual addition of many columns - currently I have something done with countif for as much as 10 duplicate ID - it just adds "1-"&ID then subtract this and takes it as "2-"&ID.. etc. It's very slow on performance.
As for VBA there is probably no possibility to dynamically declare ID from range as variable from stocks and then simply subtract in loop?
Something like this should work (paste in B2 and use autofill) :
=VLOOKUP($B2,$K$3:$L$17,2,FALSE)-SUMIF(INDIRECT("$B$2:$B$" & ROW()),$B2,INDIRECT("$C$2:$C$" & ROW()))
VLOOKUP($B2,$K$3:$L$17,2,FALSE) return the stock value of the item of the current row (777 for row 2)
SUMIF(INDIRECT("$B$2:$B$" & ROW()),$B2,INDIRECT("$C$2:$C$" & ROW())) return the sum of qty ship (of the current row and rows above) of the item of the current row (250 for row 2, 350 for row 5)
what about simple sumifs formula like below?
=L3-SUMIFS(C:C,A:A,J3)
place in cell M3 add drag/copy to the bottom
I have a pivot table like the one in the image:
The table updates every month.
The question is: how can I dynamically get the last value of the table with a function, without VBA?
For example, in this case the last value is -32, just above the "Grand Total" value.
I'm considering to use the function "GETPIVOTDATA" but I don't know how to change the dynamic reference to the last value inserted. At the moment, the formula looks like this:
=GETPIVOTDATA("[Measures].[Count of DESIGNER]";$A$3;
"[Components_Drawings_Data].[DATE (Month)]";
"[Components_Drawings_Data].[DATE (Month)].&[giu]")
Screenshot (below) / here refer.
Assuming:
You can isolate the pivot table so that there are no populated cells
beneath it (reasonable premise, given it's 'dynamic' and so variable
re: # rows)
You're not fixated upon using a PivotTable reference in formula
You do not anticipate any row labels = 'Grand Total' (which would be unusual to say the least, however see alternative function below)
Grand total for columns is displaying
Then the following will achieve what you have indicated:
...how can I dynamically get the last value of the table with a
function, without VBA?
=OFFSET(INDEX($F$4:$F$100,MATCH("grand total", LOWER($F$5:$F$101),0)),0,1,1,1)
Note: the formula in cell L3 in above screenshot includes a wrapper for presentation / ease of use only - i.e. 'Item' (col J) refers to the number of cells 'up' from the Grand Total at the very bottom of the pivot table... e.g. for item = 1 (one level up), 119 is returned (corresponding to 'woman'); for item = 2 (two levels up, 77 displays and so forth.
The corresponding label can be determined in a very similar fashion:
INDEX($F$4:$F$100,MATCH("grand total", LOWER($F$5:$F$101),0)-J3+1)
Alternative/direct (does not rely upon Grand Total for cols):
=OFFSET(F3,COUNTA(F3:F100)-2,1,1,1)
I elaborated this trick.
Suppose the column "Month" of the pivot table corresponds to column A, and the column "Delta" to column B.
I would use this formula:
=INDEX(B:B;MATCH("Grand Total";A:A;0)-1)
It could work.
I am using Excel from Microsoft Office 365 ProPlus.
Here's a really simple data table.
I want to build a Pivot Table around it to look like this...
... except that the "what I want" column (which is the count of items in Column C divided by the count of items in Column B) should be a part of the pivot table.
I have tried all sorts of things using calculated fields, calculations on fields, etc., to add the "what I want" column and just cannot make it work.
Can anyone help?
Calculated Fields only operate on the Sum of the elements in the data tables. Wherever you see a Field Name in the formula for a Calculated Field, picture it as meaning the sum of all elements for that field (that match any other row/column criteria in the Pivot Table).
Putting "= B / C" actually means "= SUM(B) / SUM(C)" for elements of columns B and C that fit that section of the Pivot Table.
The only way to achieve your goal is with two helper columns:
B Count: =COUNT([#B])
C Count: =COUNT([#C])
The sum of these columns then give you the count of columns B and C, so you can use these helper columns to give you what you want:
The Data Field based on the Calculated Field then says "Sum of What U Want", but it will always just be the result of your calculation, even if you change how the field is summarized through Value Field Settings. You can manually rename the Data Field, but it still needs to be different to the Calculated Field name you chose earlier.
Click in the Pivot Table, then go to the Analyze tab, click on Fields, Items, & Sets, then select Calculated Field. Your formula is probably
= B / C
I have a large set of data where I need to calculate the sum of groups for specific columns in a table. Here is an example of the table:
I need to sum up column H for each date group (column A) such that it will keep display this sum on the last row of the group. In other words, on the first group that we can visibly see here for 3/21/13, we would sum up 38 + 2 + 21 and display 61 to the right of cell H4930. This would be repeated throughout the data so as to display the sum of each group's H column entries at the lowest item in the group as aforenoted.
I am assuming that some VBA will be required here, but I am not sure how to attack this. How would this be done?
Yes as suggested by Idevelop ..you can get this done using pivot table
Select all the data -> goto Insert menu ->Pivot table > say ok
in Row field >Place A column title
in values field >place H column title
that's it
Let me know if you need more details.
Image :
I added 2 working columns before your Sum column.
Add: =NOT(ISNA(MATCH(C2,$Q$2:$Q$3,0))) to column N, where the Q2:Q3 are the numbers you wanted to check. Can be hidden.
Add: =IF(N2,COUNTIFS(A3:$A$7416,A2,N3:$N$7416,TRUE)=0,"") to column O. Can be hidden.
Add: =IF(AND(N2,O2),SUMIFS(H2:$H$2,A2:$A$2,A2,N2:$N$2,TRUE),"") to column P. This is your sum.
If you don't actually need to display all the data like this then a pivot table would be a lot clearer. You can filter based on numbers and so on easily.
edit: edited to check for specific codes in column C, per comment.
edit2: completely changed per comment. Requiring it to be inline with the last highlighted row is more complex.
I am a VBA Newbie and a first timer on this forum - I have followed all the instructions on the "how to ask" page - I may have missed something please do advise
I am creating an EV report for project tracking based on the following column headers (showing only a few for brevity)
"TaskName" "Status" "BaselineStart" "BaselineFinish" "BaselineEffort"
need to sum up the values in the BaselineEffort column in 7 day increments after checking if the value in the BaselineFinish column is less than or equal to the 7th day value
I believe the answer lies in using arrays, but need handholding with that concept to understand how it works
Pivot and Excel formulas dont work for me because the table is dynamic while the report is static and I need to remove user intervention in creating the report
Thanks in advance
say that the criteria column starts in A1 and the colume to be summed starts in B1
do while not isempty(range("a1").offset(x,0))
if range("a1").offset(x,0) = SomeValue then
sum = sum + range("a1").offset(x,0)
end if
x = x + 1
loop
this code will run until it has looked at each item in column A, and add the value in column B to a sum I called "sum" if the value in column A equals "SomeValue." I doubt you can actually use the variable name "sum."
I hope that's useful.