I have two tables as below. For formulas, assume "ID1" is on cell A1 and one blank row between tables so "ID" is on cell A4.
ID1 ID2 ID3 ID4 ID_OF_MAXDATE
a b d #N/A formula_here
ID DATE
a 1/1/2015
b 1/2/2015
e 1/3/2015
d 1/4/2015
g 1/5/2015
In the formula, I want the id of the max date if id's in that row. So in this case, out of a,b,d - the max date is d with 1/4/2015. So the I want the formula to output d.
I have the below so far but the #N/A throws it off. Without the N/A value, the below outputs the max date. However, I want the ID of the max date. And it should ignore N/A's in the range. Note, all ID's in table 1 will appear in table 2. But some id columns in table 1 may be N/A.
=MAX(IF(A2:D2=A7:A11,B7:B11))
A much bigger and complex formula than expected, but it will take into account that a date can appear more than once in the data set. Be sure and enter with CTRL + SHIFT + ENTER.
=IF(SUM(IFERROR(MATCH(A2:D2,$A$6:$A$10,0),""))>0,LOOKUP(REPT("Z",255),IF(MAX(IF(FREQUENCY(IFERROR(MATCH(TRANSPOSE(A2:D2),$A$6:$A$10,0),""),ROW($B$6:$B$10)-ROW($B$6)+1),$B$6:$B$10))=IF(FREQUENCY(IFERROR(MATCH(TRANSPOSE(A2:D2),$A$6:$A$10,0),0),ROW($B$6:$B$10)-ROW($B$6)+1),$B$6:$B$10),$A$6:$A$10)),"No Match Found")
I also put in some additional error handling. The formula will return "No Match Found" if it is unable to find a match.
Insert an "iferror". In the example above, change the formula to:
=MAX(IF(IFERROR(A2:D2,"")=A7:A11,B7:B11))
Related
I have 4 sheets named: STATS, SHEET01, SHEET02 and SHEET03.
SHEET01, SHEET02 and SHEET03 look exactly the same like the picture below but with different dates and percentages.
In cell A1 of the STATS sheet I have the following formula:
=IFERROR(ArrayFormula(AVERAGEIFS(SHEET01!B2:B,month(SHEET01!A2:A),2,year(SHEET01!A2:A),2020)))
This formula returns the average percentage of February 2020.
This formula clearly only works with SHEET01 and I can't figure out how to make it also take the averages of SHEET02 and SHEET03.
I have tried:
=IFERROR(ArrayFormula(AVERAGEIFS(SHEET01!B2:B,SHEET02!B2:B,SHEET03!B2:B,month(SHEET01!A2:A,SHEET02!A2:A,SHEET03!A2:A),2,year(SHEET01!A2:A,SHEET02!A2:A,SHEET03!A2:A),2020)))
UPDATE
Now using the following query:
=query({'SHEET01'!A:B;'SHEET02'!A:B;'SHEET03'!A:B},"select avg(B) Where A is not null and A>=date'2020-01-01' and A<=date'2020-01-31'")
This outputs the following error:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: B
try in B2 of stats sheet if A2:A contains dates:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A,
QUERY({SHEET01!A2:B; SHEET02!A2:B; SHEET03!A2:B},
"select Col1,avg(Col2)
where Col1 is not null
group by Col1
label avg(Col2)''"), 2, 0)))
or use only this to get the full summary:
=QUERY({SHEET01!A2:B; SHEET02!A2:B; SHEET03!A2:B},
"select Col1,avg(Col2)
where Col1 is not null
group by Col1
label avg(Col2)''")
note that you might need to format dates via 123... button if your dates will outputted as 4000+ numbers
I have a table which I would like to return in its entirety but filtered by column H with the maximum date as rows have duplicate account numbers with different dates.
https://docs.google.com/spreadsheets/d/1x3hYy1igiL3_lqhFE3IwrQNFbOjdpXRtHLAbOXB2BE4/edit?usp=sharing
I'm using this query right now, but clearly I'm overlooking something, can anyone help, please?
=QUERY(B3:I12, "Select *, Max(H) WHERE B is not null Group by C")
correct syntax would be:
=QUERY(B3:I12,
"select B,C,D,E,F,G,H,I,max(H)
where B is not null
group by B,C,D,E,F,G,H,I")
but you probably need this:
={B3:I3; SORTN(SORT(B4:I, 7, 0), 99^99, 2, 2, 1)}
The final formula was ={DataTable;SORTN(SORT(Data,17,0),99^99,2,2,1)}
DataTable is the headings and Data is the dataset. Out of 14,000 lines this filtered down to around 7,000 lines of unique rows with the highest (Maximum) date.
I have a Matrix created using Matrix Wizard in Report Builder 3.0(2014), having 2 row groups ,1 column groups and 2 values. After I create the matrix (included total and subtotal), I have a matrix that look just nice. But now I want to add one more cell for each columns groups (one row), to store the below value.
Value = Total of 1st row group + Total of 2nd row group - Total of 3rd row group ...
The matrix built just show me the subtotal of each row group which I don't need.
I want to ask how do I retrieve the result of total calculated by matrix itself and how do I identify them based on their row group value using expression? And also, how do I do this for every column groups which have different data?
I tried to look at the expression in design view of the matrix, it just shows [SUM(MyField)] for every cell in the Matrix (total & subtotal).
Or should I do it at another dataset using another query? If so, what query should I use and how do I put two dataset into one matrix?
My Matrix looks something like this :
Column Group
ROW GROUP 1 | ROW GROUP 2 | VALUE 1 | VALUE 2
Row Group 1 | Row Group 2 | [Sum(MyField)] | [Sum(MyField)]
| TOTAL OF ROW GROUP 1 | [Value] | [Value]
| ROW PLAN TO ADD | [Value(0)+Value | [Value(0)+Value
| (1)-Value(2)] | (1)-Value(2)]
CAPITALS : Column name, constant
[sqrbrkted] : Calculated Value
Normal : data inside table
I am new to Report Builder, sorry if I made any mistake. In case I didn't make myself clear, please do comment and let me know. Thank you in advance.
EDIT: I have figured out an approach to achieve my purpose at the answer section below. If anyone have other solution, please feel free to answer it. Thanks.
I solved this problem by changing my SQL query to make another dummy column which shows negative result if its respective row group is meant to deduct the subtotal (Value(2)), and place it inside the matrix. And inside the expression, I have another IIF statement to convert it back to positive for display purpose.
SQL:
SELECT *, (CASE WHEN COL_B = 'VAL_2' THEN -COL_A ELSE COL_A END)AS DMY_COL_A FROM TABLE
Expression:
=IIF(Sum(Fields!DMY_COL_A.Value)<0,-Sum(Fields!DMY_COL_A.Value),Sum(Fields!DMY_COL_A.Value))
I have data in the format below with unique ID's in Column A, but these ID's could appear on multiple rows representing repeat transactions against that individual. In col B i have the datetime stamp of that transaction, and in Col C, the name of the transaction;
Col A Col B Col C
ABC1 15/02/2018 16:26 Apple
ABC1 14/02/2018 11:26 Pear
ABC1 13/02/2018 09:11 Pear
ABC2 15/02/2018 16:26 Orange
ABC2 14/02/2018 11:26 Pear
ABC2 13/02/2018 09:11 Apple
ABC3 15/02/2018 16:26 Grape
ABC3 14/02/2018 11:26 Orange
ABC3 13/02/2018 09:11 Apple
I'm trying to pivot this data with MIN and MAX criteria on the datestamp to get the count of how many records had which transaction in Col C as their first transaction, how many had X transaction in Col C as their latest transaction etc, the aim to finalise the data in something like this;
MIN (first) transactions:
Distinct Count Col A Col C
1 Pear
2 Apple
MAX (last) Transactions:
Distinct Count Col A Col C
1 Grape
1 Orange
1 Apple
Is there a way to do this with Pivot tables I'm missing? I'm working with several million rows of data here so manipulating via a pivot is easier for me to do (data loaded via power query) than using a formula or something. I can concatenate columns during the load process if needed.
Thanks in advance for your help.
Use helper columns as this will allow you to use page filters for max and min rather than relying on ordering each column in question.
Set your data up as a table. Then add a max column and a min column.
Max column formula:
=IF([#[Col B]]=MAX([Col B]),1,0)
Min column formula:
=IF([#[Col B]]=MIN([Col B]),1,0)
Create 2 pivots. 1 for max and 1 for min and put the max or min in the page field and filter on 1 (i.e. date is max or min of source values)
Order the Column C by count of Column of Column C (the fruit name column), in which ever way you see fit. Ascending for the min if you are interested in the fruit with the smallest count for the min date.
Final outcome:
You can always remove unwanted fields e.g. Column B to get the exact same look:
Edit:
If you want to show the count of each fruit, by ID, for the minimum date for that ID you can use lookup table pivot(s)
An example lookup table pivot for minimum values for each ID
You then reference this table in your source table, in a helper column, using index match to retrieve the minimum date and compare against the date in your data table for the same ID:
Formula in helper column (MinMatch):
=IF(INDEX(LookupMin!B:B,MATCH(A2,LookupMin!A:A,0))=[#Date],1,0)
Note: This would be a lot easier if you created a unique key of ID & Fruit and lookup against that.
The helper column formula is:
=IFERROR(IF([#[Col B]]=INDEX(LookupMin!$A:$E,MATCH([#[Col A]],LookupMin!$A:$A,0),MATCH([#[Col C]],LookupMin!$4:$4)),1,0),"")
LookupMin! is the sheet with the minimum pivot in.
Note that I have used a pivot on the data table to see count of each fruit, on the minimum date for each ID.
You could have used a formula instead, but then you would have repeating sums i.e see Column F
Formula in E (then dragged down):
=SUMIFS([MinMatch],[Fruit],C2,[ID],A2)
Finally, if you then decided you wanted earliest date for ID and fruit you could change the lookup as follows:
I have the following Matrix in SSRS 2008 R2:
What I would like to do is only show columns where the "FTE" row has a value. (Marked with red circles). I've tried the filter and show/hide options based on expressions in the Column Properties, but I can't figure out how to only reference the rows when "category"="FTE". My data looks like this:
tblPhysicians
employee_id last_name ...
102341145 Smith
123252252 Jones
tblPhysiciansMetrics
id fy period division_name category_name employee_id
123 2014 1 Allergy Overhead 123456
124 2014 1 Allergy Salary 125223
125 2014 1 Allergy FTE 1.0
query
SELECT * FROM
tblPhysicians
INNER JOIN tblPhysicianMetrics
ON tblPhysicians.employee_id = tblPhysicianMetrics.employee_id
WHERE
tblPhysicianMetrics.division_name = #division_name
AND tblPhysicianMetrics.fy = #fy
AND tblPhysicianMetrics.period = #period
Notice that the rows in my Matrix is just the category_name, so I can't just hide when category_name = "FTE", that's not really what I want. What I really need is some way of saying, "For rows where category_name = "FTE", if the value is not set, don't show that column". Is this possible?
An alternative would be to not even get those in the query, but as with the filtering of the matrix, if I simply add "AND tblPhysiciansMetrix.category_name = 'FTE'" to the WHERE clause, my entire data set is reduced to only those records where category_name is FTE.
Any help is much appreciated!
Update: added definition of Matrix to help:
You need to set the column visibility with an expression that checks all underlying data in the column for the FTE category.
I have a simple dataset:
And a simple matrix based on this:
Which looks exactly as you expect:
So in the above example, we want the Brown column to be hidden. To do this, use an expression like this for the Column Visibility:
=IIf(Sum(IIf(Fields!category_name.Value = "FTE", 1, 0), "last_name") > 0
, False
, True)
This is effectively counting all the fields in the column (determined by the last_name scope parameter in the Sum expression) - if this is > 0 show the column. Works as required:
CAVEAT I'm not 100% sure how you are grouping this data in the matrix. It isn't 100% clear from your description. Let me know why this doesn't work (if it doesn't and I'll update my answer accordingly.
I've replaced the column employee_id with the name value for my answer, to keep my explanation simple.
Add this nested IIF() to the visibility property of your Matrix's column.
=IIF(Fields!category_Name.Value="FTE" ,IIF( Fields!value.Value >= 0, True,False),false)
It will check both the value of the the category and the 'FTE' in that row's cell.