How to specify a column field in a calculated field formula when you have the same value evaluated as a count and a sum? - pivot-table

I am using a pivot table to summarize our status of completion of a project. The first value of the pivot table gives me a count of the entries in the spreadsheet column that have a value greater than 0. The next value of the pivot table gives me a count of the total estimated quantities from the spreadsheet. The third value gives me the sum of the entries from the same column of the spreadsheet that the first value uses in the pivot table. The final value of the pivot table is a sum of the total estimated quantities from the same column from the spreadsheet the second values uses for the pivot table.
My current working formula will only evaluate the SUM columns in the pivot table and is the following:
=iferror('Quantities Complete'/'Total Est Quantities',0)
This gives me a percent complete based on the SUM of those two columns from the spreadsheet. These values can differ because the first is a real value and the second is an estimated value. What I want is the below formula which I will put how the data is summarized in parenthesis for simplicity of understanding.
=if('Quantities Complete'(COUNT)='Total Est Quantities'(COUNT),1,iferror('Quantities Complete'(SUM)/'Total Est Quantities'(SUM),0))
This formula would allow me to evaluate if the count of complete items matches the total estimated items, if so the calculated field value is 100% regardless of actual sum values. Otherwise, it gives a percent complete based on sum value which is more accurate because each item can have vastly different values.
How can I refer to the 2 different uses of the columns in a calculated field formula?
I have tried the renaming the column headers to 'Items Complete' and 'Item Values' but the formula does not accept those and gave a parse error. I have tried using the "COUNTA of" or "SUM of" prefix for the column fields. I also tried typing the name as shown when I hover over the value field in the edit window which I tried in these methods: 'Quantities Complete' (Items Complete) and 'Quantities Complete (Items Complete)'. All of these yielded a parse error. I can't share my spreadsheet due to confidentiality requirements, but all I need to know is how to refer to the two different column headers that have the same name from what I can tell.

Related

Arrays, SUM + INDEX/MATCH

Note: tried in Excel and Google Sheets, but I have a preference for Sheets.
Basically I want to get the sum of a group of data using INDEX and MATCH (because the parameters are going to be drop-down dependent):
The desired result is:
So this will require a few things:
Converting the cell D13(April) to a Month
Converting the "weekof" column to a Month
Using INDEX and MATCH and MATCH again, I'm assuming because it's multiple cell references.
Here's my solution currently below:
=SUM(INDEX(D5:I9, MATCH(MONTH(D13&1),ARRAYFORMULA(MONTH(C5:C9)),0), MATCH(E12,D4:I4,0)))
This returns the NEAREST value:
270
Instead of:
804
Why this value?
270+500+34 = 804
If you are not strict to use INDEX and MATCH, you may use the following solution:
Add extra column name it "Month", this column will extract the month name from the date column using TEXT function as the following:
=IF(C3<>"",TEXT(C3,"mmmm"),"")
The if statements ensures that only filled dates will have a month value, since you have to fill this column with the above formula for a certain amount of cells.
Now you can simply use the SUMIF function in cell E13 or where ever you want:
=SUMIF(B:B,D13,D:D)
If you don't want the Month column to appear within your data table you may put it at the end of your table and hide it.
You could directly use FILTER then SUM the result instead to simplify your formula to this one:
Formula:
=SUM(FILTER(D:D, TEXT(C:C,"MMMM") = E13))
Output:
UPDATE:
The above formula should also update when the value is dropdown. Dropdown is just data that can be changed with predetermined values, aside from that, it should be the same when using a normal cell.
To match columns, use MATCH and INDEX together with the formula above. See modified formula below.
Be careful of the circular dependency. make sure your ranges doesn't interfere with the actual cell where you put your formula.
Column Matching:
=SUM(INDEX(FILTER(D:E, TEXT(C:C, "MMMM") = E13),,MATCH(F12, D4:4, 0)))
You can use pivot table and group dates by year and month.

Google Data Studio, how to get a sum of all Max or Min values

I am working with a data set where i have to get Min or Max for different text fields. My dataset can have thousands of rows so below is a simpler example. So I have 3 categories having multiple values and I can put this dataset in GDS to build a table where I select Category as dimention and Value as Max(Value) in metric.
Now I need to see the sum of all those values too. But like the pivot table in excel, the subtotal in GDS shows the Max out of all the max listed above. So instead of 65, it shows 30 in GDS. Is there a way I can get it to show the sum?
To reach the desired result you will need:
Make a data combination, not being necessary to insert a second base, just so that a current base is defined as a data combination.
In the combination use the Category dimension and define the Max Value metric. The combination is only necessary for the metric to be used in the table as a dimension (this is a property resulting from the combination of data).
Configure the table with the Category dimension and Include the metric with the Value sum option. Remember that now Value is the maximum value (as defined in the data combination).
Finally, display the Summary line. And the desired result is obtained

SSRS - Sum of an aggregated field

I have a report, that shows the individual sales commission for each employee.
The expression for the Sales Commission is:
=Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value
Now I want to add a total for this field. If I just right click the cell and click on Add Total, it works but gives out the wrong total.
If I try to sum the field like this:
=Sum(Reportitems!GO_Prov.Value)
I get the error:
The Value expression for the textrun 'Textbox93.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers.
Is there a workaround to sum the aggregated field of this tablix? Maybe with a code?
Thanks in advance.
Update1:
Unfortunately i don't know how to write custom codes. But I found this code:
Public Total_lookup_Sum As Integer = 0
Public Function Lookup_Sum(ByVal value As Integer) As Integer
Total_lookup_Sum = Total_lookup_Sum + value
Return value
End Function
The expression i used for the Sales Commission is now:
=Code.Lookup_Sum((Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value))
And the expression for the field where i would like to get the sum is:
=Code.Total_lookup_Sum
Now i get the error:
There is an error on line 0 of custom code: [BC30205] End of
statement expected.
Is there a way to solve this?
Scenarios like these can be tricky in SSRS. From your description (even though the screenshot doesn't really show everything), I'm guessing that you've got rows grouped by salesperson. In your column that's calculating the commission, you've got a sum of "Total_commission", but you've just got the "Individual_Factor" value not aggregated. Again, having a guess, but each underlying row (by employee) must have the same "Individual_Factor" value (so actually using Min(Individual_Factor) would give the same result).
But then, when you try and just take the same formula (or even a derivation of the formula), and make an overall aggregate of all of the rows, how does SSRS know which "Individual_Factor" value to use? You don't want Min() or Max(), because that would just be the lowest or highest value across all of the salespeople.
Your suggestion of a workaround via code is generally the way that I approach this. You need a report variable, something like "Commission_Grand_Total", and then you need a function in the report code that accepts 1 parameter, and in the function you'll add the parameter value to the variable. The easiest thing to do is to make the parameter the return value of the function.
Then, in the field where you currently have your commission formula (on the salesperson row), the expression in that field becomes =TheFunctionYouCreate((Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value))
By passing the formula to the function, you're achieving two things:
The function will take each salesperson's calculated commission and add it to your report variable
The function will output the parameter value that you passed in (since you want to display the calculated commission amount on each salesperson's row)
Lastly, to display the overall total, the expression for that field is just the report variable that holds the overall total (that has been cumulatively added to as SSRS wrote out each salesperson's record)
TIP: I sometimes do this same sort of thing, but if I don't want the row-by-row value to be shown (I just want the cumulative total to be calculated), just put the expression that calls the function in a hidden column. SSRS will still run the function as it renders each row, but obviously it's just not displaying the result of the function.
Some MS reference for report variables and code
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/built-in-collections-report-and-group-variables-references-report-builder?view=sql-server-ver15
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-code-to-a-report-ssrs?view=sql-server-ver15
This is untested unfortunately but...
assuming you have a rowgroup for employee called EmployeeGroup then the expression would look like this...
=SUM(
Sum(Fields!Total_Comission.Value, "EmployeeGroup")
* Parameters!Distribution_Factor.Value
* FIRST(Fields!Individual_Factor.Value, "EmployeeGroup")
)
The inner expression reads as
Sum of Total_Comission with current employee group
... multiplied by Distribution Factor
... multiplied by the first individual factor with the current employee group
The outer expression just sums all the individual employee level sums.

Google Sheets - COUNTIFS in ArrayFormula

Project Completion Target Date
Estimated Completion Date
12/31/2020
12/24/2020
12/31/2020
1/7/2021
1/19/2021
2/15/2021
I'm trying to create a CountIfs statement, or a CountIf inside an Array, which will evaluate one column in relation to another column, repeated for multiple rows. With multiple conditions: If B > A, and ignore the row is A is empty.
Formula So Far:
=COUNTIF({B2:B5}, ">"&{A2:A5})
Result is 3, but the desired result is 1. This formula is counting when B > null = True. But desired result is when A is empty/null, then B !> A.
Here's one option.
=COUNT(FILTER(A2:B5,NOT(ISBLANK(A2:A5)),B2:B5>A2:A5))/2
You can use FILTER() to filter your data with multiple conditions then count the filtered data (divide by 2 based on the number of columns in your data)
Your conditions:
A should not be empty
B should be greater than A
Example:
Filter the set of data based on the conditions required.
=FILTER(A2:B5,NOT(ISBLANK(A2:A5)),B2:B5>A2:A5)
Output:
It will return a filtered data like this.
Then you just need to use COUNT() to count the filtered data. You just need to divide the result of the count based on the number of columns in your data.
You can also use the following filter formula
=COUNTA(FILTER(B2:B7,A2:A7<>"",B2:B7>A2:A7))

Get column header of last non-empty cell in unknown row

I have a table in a sheet called "DATA" with the following headers:
Country, Code, Series, 2000, 2001, 2002, 2003, 2004, 2005, 2006.
In each row I have data for all columns always, except for years. Some rows have data for some years only, others all years.
In sheet "DATA AVAILABILITY" I want to build a formula which returns the most recent year for which there is available information in sheet "DATA", given a certain country and code. The relevant country and codes are in cells E2 and A3 of "DATA AVAILABILITY". Let's say, for argument's sake, that these are Country: Angola; Code: 3.
I have first built an array MATCH formula with two criteria:
={MATCH(1,('DATA AVAILABILITY'!E$2=Data!$B$1:$B$104701)*('DATA AVAILABILITY'!$A3=Data!$D$1:$D$104701),0)}
This has successfully given me the row in "DATA" in which there is information for Angola and code 3, which is row 1776.
Now I would like to get the header for the last non-empty cell of row 1776 in sheet "DATA". For this, I started by building a formula that would give me the column number of that cell:
=LOOKUP(2,1/(Data!1776:1776<>""),COLUMN(Data!1776:1776))
It successfully returned the number 53 which, after verifying on sheet "Data" is the correct number. I then added to the formula so that it would return the header, i.e., the year, instead of the column number:
=INDEX(Data!$A$1:$BE$104701,1,LOOKUP(2,1/(Data!1776:1776<>""),COLUMN(Data!1776:1776)))
Finally, I would like to combine both formulas (the MATCH and the INDEX formulas) so that the final result would be returned with one formula only. However, when I try to do it, something goes wrong and an error comes up - I am not even able to enter the formula. When I click ENTER, Excel returns an error that says there is a problem with the formula. what I have tried to do is to replace, in the LOOKUP within the INDEX, "Data!1776:1776" for the array MATCH formula that returns the row in which the information is - in my example, row 1776. The final formula which is not working is as follows:
=INDEX(Data!$A$1:$BE$104701,1,LOOKUP(2,1/(MATCH(1,('DATA AVAILABILITY'!E$2=Data!$B$1:$B$104701)*('DATA AVAILABILITY'!$A3=Data!$D$1:$D$104701)<>""),COLUMN(MATCH(1,('DATA AVAILABILITY'!E$2=Data!$B$1:$B$104701)*('DATA AVAILABILITY'!$A3=Data!$D$1:$D$104701))))
What may I be doing wrong?
Thank you
Hard to tell what is going on without at least some sample data (as a table or linked workbook -- NOT as a screenshot), and I would do it a bit differently.
You can simplify your formula to get the Header of the column that contains the last data in row 1776:
=LOOKUP(2,1/(Data!1776:1776<>""),Data!$1:$1)
To return the column number:
=LOOKUP(2,1/(Data!1776:1776<>""),COLUMN(Data!$1:$1))
To return the Appropriate Row Number (enter with CSE):
=MAX(($E$2=Data!$B$1:$B$104701)*(A3=Data!$D$1:$D$104701)*ROW($A$1:$A$104701))
To return the last filled in value, in the row that matches Country and Code, we make use of the fact that using 0 for the column number in the INDEX function returns all the columns in the designated row:
=LOOKUP(2,1/(INDEX(Data!$B$1:$BE$104701,MAX(($E$2=Data!$B$1:$B$104701)*(A3=Data!$D$1:$D$104701)*ROW($A$1:$A$104701)),0)<>""),INDEX(Data!$B$1:$BE$104701,MAX(($E$2=Data!$B$1:$BE$104701)*(A3=Data!$D$1:$D$104701)*ROW($A$1:$A$104701)),0))
entered with CSE.

Resources