Excel - sumifs condition is true but result is 0 - excel

I try to sum all rows K30:K49 where with the same year and quarter in G30:H49 as in the header G1, G2. My formula is:
=SUMIFS(K30:K49;G30:G49;G30*10+H30=G$1*10+G$2)
But it returns 0. I tried Evaluation feature and I can see that the condition is evaluated to TRUE. So I expect that it will sum the column K. Where is my mistake?

Is your goal to sum all 2020 quater 1, 2020 q 2 and so on?
In that case you need more than one criteria range and criteria.
=SUMIFS(K30:K49;G30:G49;G1;H30:H49;G2)
This makes sure it's 2020 and q1, or 2020 and q2
(And 2020 q1 should return 0, if this is all the data there is, but q2 should return 27000)

In case a Pivot Table could work for you, I made a fake dataset to replicate yours:
And I have resume the data with a Pivot Table:
My Pivot Table setup is:
ROWS: Year field
COLUMNS: Quarter field
VALUES: Sum up Values field
Also, if you need an horizontal design, you can do it like in your image with a Pivot Table too, just taking Year field and Quarter Field into Columns Section:
If you use this second option, and you got Excel 2010 or higher, there is an option called Repeat item labels in a PivotTable to repeat all years values, like your original design.
Hope this helps.
UPDATE: Checked your example file. I made a Pivot Table with this setup:
ROWS: Source field
COLUMNS: Year field and Quarter Field
Changed form design to TABULAR
Deactivated all SUBTOTALS
Activated GRANDS TOTALS ONLY FOR COLUMNS
In the Pivot Table Options, option in empty cells show I said show a 0
This is the result, very similar to what you want.

Related

Lock Structured References to column names in Excel-formulas when data Query is updated and refreshed

I use references to other columns in my table with the following formula:
=TableName[#[ColumnHeaderName]]
And use the following as a Table array:
TableName[[#All];[ColumnHeaderName]] (this is used if I want to make a HLOOKUP to a specific cell given a row number in ColumnHeaderName)
I have the following Dataset with tablename Cars:
(A) (B)
(1)Brand Year
(2)BMW 2016
(3)Audi 2013
(4)Mercedes 2014
If I am to look up the value of the year column in Row 4 I say
=HLOOKUP("Year";Cars[[#All];[Year]];4;FALSE) (=2014)
If the dataset now looks like
(A) (B)
(1)Year Brand
(2)2016 BMW
(3)2013 Audi
(4)2014 Mercedes
then my formula in Excel says =HLOOKUP("Year";Cars[[#All];[Brand]];4;FALSE)
How can I make sure that my formula always says =HLOOKUP("Year";Cars[[#All];[Year]];4;FALSE) regardless of the position of the 'Year' column in my Cars table?
Try using the Absolute Reference form for Structured References. eg:
=Cars[#[Brand]:[Brand]]
Edit
Now that you have provided data, it seems the syntax of your formula is incorrect.
For the HLOOKUP function, you could be using:
=HLOOKUP("Year",Cars[#All],4,FALSE)
Original Table
Swap Car & Year
Insert some columns

How to get dynamically the last value from a pivot table in Excel

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.

Calculated Fields in excel pivot

I have column ('CSAT') in a sheet that has numbers 1 and 0 in each cell. '1' represents 'Satisfied' and '0' represents 'Disatisfied'. I want to make a pivot from this sheet and have a new calculated field in it ('CSAT %') that will give me the score by dividing (Total 'Satisfied') count by (Total 'Dissatisfied + Total 'Satisfied') * 100.
I tried with COUNTIF but i dont think we can use this formula in pivot
Calculated Fields and Items in PivotTables are tricky. The main tripping point is understanding that Calculated Fields and Items operate on the totals, not on the individual values in the underlying data.
For example, if you created a new Field that was equal to Field1 * Field2 and data is being summarized by SUM, Excel doesn't multiply all of the respective values in each field and then sum the results. It first sums the fields for each category and then multiplies those results. What it's really doing is SUM(Field1) * SUM(Field2) for each category.
You can use some worksheet functions in the calculated fields, but you have to remember you're still operating on the totals. So if you created a new Field that was equal to Count(Field1) * Count(Field2), you're (almost) always just going to get an answer of 1. This is because the calculation is actually doing Count(SUM(Field1)) * Count(SUM(Field2)) for each category. The sum of each field is a single number, so the calculation is just doing 1*1 for each category.
So for this reason, you can't use aggregating functions like SUMIF or COUNTIF which need to look at each individual elements. Since you need to look at individual elements, you actually can't use a Calculated Field for your solution at all.
What you can do is use a Calculated Item!
The main catch here is you can't use any field in more than 1 location when calculated items are involved. Excel just throws an error message saying you're not allowed.
So if you have a category column as well as the CSAT column, you need to create another dummy column full of 1's to operate on.
You can then set up pivot table as follows:
Category field to Rows.
Dummy field to Data area, summarized by Sum
CSAT field to Columns
Click on the CSAT column headers in the pivot table and choose: PivotTable Tools > Fields, Items, & Sets > Calculated Item
Set Name for your new Item to CSAT%
Enter the formula: ='1'/('0'+'1')
On the CSAT field, hide items 1 and 0, so only the CSAT% field is visible
Result:
A couple of notes:
When entering fields and items in calculated fields and items, do so by placing the cursor where you want in the Formula then double clicking on the field/item name from the lists below. This will add brackets and quotes as required in the correct format.
Note that the formula doesn't need SUM around the item names, because calculated fields/items always work on the total of values. They are totalled according to how the data is summarized in the pivot table.
The dummy column was added with all values of 1 so that summing these values gives you the count, from which the percentage can be calculated using the formula specified.
Answer without using calculated fields:
Assuming you have categories in the row fields, you can put CSAT as a column field as well as a data field then choose to summarize values by Count and show values as a percentage of row totals:
After putting CSAT in column and data fields, right click on the data and select Summarize Values By > More Options...
First choose to Summarize Values By Count:
Then click Show Values As tab and select % of Row Total:
You'll then have percentage of 1's under the CSAT=1 column:

Excel Pivot Table IF Statement

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).

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

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

Resources