Filter an in-tooltip visual using a Lookup type filter - tooltip

Sample Tableau Workbook with Superstore data: https://filebin.net/jkph5ccuzmzr3y21
I have a chart that shows both a weekly view, and a cumulative view, and a parameter swaps between the two.
In the attached example, we have a parameter that has two possible values, "Weekly" and "Cumulative".
[Sales (Weekly/Cumulative)] looks like this:
IF [Weekly/Cumulative] = "Weekly" THEN
SUM([Sales])
ELSEIF [Weekly/Cumulative] = "Cumulative" THEN
RUNNING_SUM(SUM(Sales))
END
I've added a text table to show the Week detail as a Viz in the tooltip, and this works great when we select "Weekly". But for "Cumulative" the tooltip still shows a total for a single week, rather than the running total number. This is because when we switch to the Cumulative view, we're using a Table Calculation, and Table Calculations only calculate based on what's in the view. When you filter by Week = 38 (for example), the detail table only shows week 38, and so there's no running total.
In a normal viz, you would overcome this by using a filter like LOOKUP(MIN([Week]), 0) to filter without messing up the table calculation. Is there a way to do that for the "in tooltip" visual?

Related

how to get index of word from column containing array in all its cells

This is fake data for question purpose
sorry for using images rather than markdown table but it would have been very hard to explain if i used markdown table
This is my DATA named Work Sheet where Y and Z is always going to be array and both have corresponding value. EX: for row2:
WBC = 33
this is my stats Sheet where i need to get value of Parameter[x] based on Day & Disease
This is where i took B$151 to B166 and now need value of it from DATA!Z2:Z (Lab values) based on name of parameter,Disease , Day .
where selected cell (B169) has formula:
B166 = RBC
A169 = DAY 1
B1 = Gastroenteritis
=MODE(INDEX(SPLIT(query(DATA!$E$2:$Z, "Select Z where Y contains '"&B$166&"' and E contains '"&$A169&"' and X contains '"&B$1&"' limit 10"),",",1),0,B$167))
Now problem is in DATA sheet user can input item at any index. right now i am using fixed index B$167, but it will break entirely and give wrong results if user changes index of that term. is there any way where i can replace B$167 with dynamic like searching that parameter name in that E,X (Day, Disease). and get index of it and change B$167 with it
i have tried using match search index and pretty everything in my knowledge but problem was Match function only takes single cell and column, so i can't give entire DATA!Y2:Y and split them and then get index. but did not work.
this was the limit of solution i was able to reach.
where A5 = WBC or any in regards
given Y2 becuase was getting error on Y2:Y
=MODE(INDEX(SPLIT(FLATTEN(FILTER(DATA!Z2:Z,DATA!X2:X=B4, DATA!E2:E=C4)),","),0,MATCH(A5,SPLIT(FLATTEN(DATA!Y2),","),)))
but using this will only give index if it is in y2 and also there is no garranty
that parameter is going to be in same index in all cells all the time
i have tried to add 4th condition to Filter on above formula such as search, regexmatch and all but i was not able to solve.
CURRENT SOLUTION: EDIT2
[NEW SHEET][1]
[1]: https://i.stack.imgur.com/rNDh8.png
right now i have did kind of like this and it will be ok if i can combine those 2 (Disease, value) into single cell like this.
RBC: 11
WBC: 33
so i don't need to manually add disease name and Value column each time. i googled but found that i can't skip columns in formula output
so i moved to this.
EDIT2:
i solved this way, now everything is automatic.
where 1 = n
=INDEX(UNIQUE({A2:A}),1)

Tableau calculating variances (division) of two calculated (countif fields)

Tableau is giving me a hard time, trying to compare two items by percentages. I need to display the percentage different between the number (couintif) of string items based on condition.
Basically, I wrote two calculated fields like:
Calc field #1
IF [Outcome] = "Complete" Then 1 Else 0
Calc field #2
IF [Outcome] = "Pending" Then 1 Else 0
and a third field to get the percentage of pending sales to completed sales
Calc percentage
SUM(Calc field #1 / Calc field #2)
But it's not working. The first two fields work fine, validated them with dataset, but the third calculation doesn't work and always outputs 0
The formula for Calc percentage should be
SUM(Calc field #1) / SUM(Calc field #2)
As both the calculated fields are computed row-wise, it is important to aggregate while using it in a formula.

Ignore cells from count in google sheets

I'm running a sheet to manage stock levels. When stock comes in, it is entered as a (positive) number, when stock goes out, it is recorded as a - (negative) number. I would like to ignore some numbers in a column when I sum the total if the row contains "Stock Take Level" in the description cell.
I need this so I can see what stock levels we had on whatever day I do a stock take.
It currently works like:
I would like it work like:
to ignore within sumif:
=SUMIF(A2:A8; "<>Stock Take Level"; B2:B8)
or:
=ARRAYFORMULA(SUM(IF(A2:A8<>"Stock Take Level"; B2:B8; )))

Reference Specific Row in Named Range within another Named Range

I'm writing a spreadsheet to keep track of a small business' financials. They operate a few Rooms for rent, and the structure of the document is made so that each sheet holds a year's worth of booking for all the rooms.
Essentially, each row is defines a specific date, while each rooms spans a few columns (reason is that they don't just want to track whether or not a room is booked, but also record names of clients & other remarks), among which the daily calculated income (some factors alter the daily rate each room will generate).
So this is all fine and dandy, and I've created named ranges for each month of the year, and for each room.
For example, rows 6:36 will represent the month of January, while columns C:I will represent Room 1. Room 2 will span J:P and so forth.
Now, in another sheet, I wanted to make a dashboard which lists the earning for each room, per month. It's a very simple table with 12 rows (one for each month) and 10 columns (1 for each room) where I planned to sum up all the earnings.
So my issue is that I can't find a way to retrieve a specific column of a named range for a room ('vertical named range'), which is also limited in a named range for a month ('horizontal named range'). I had read about using ARRAYFORMULA(INDEX(named_range, ,wished_column)) but that only works for a single named range. My knowledge of these two functions being non-existent, I didn't manage to extend it to a 2-named-range version...
(I mean I did try something along the lines of ARRAYFORMULA(INDEX(January, , INDEX(Room1, , 3))) but that didn't work)
So because there isn't a one-to-one relation from the Dashboard cells to the Rooms cells, my current only solution is to manually reference everything, which you'll understand is inefficient and time-consuming...
My question, in fine, is: How can I retrieve a range that results of the intersection of 2 (or more) named ranges ? Once I have that resulting range, I know it will be very easy to use INDEX().
Define a named range Base as
A:Z
Define a range named Horizontal as
6:36
Define a range named Vertical as
C:I
Then the intersection of the vertical and horizontal ranges is given by:
index(Base,row(Horizontal),COLUMN(Vertical)):index(Base,row(Horizontal)+rows(Horizontal)-1,COLUMN(Vertical)+columns(Vertical)-1)
This can be verified by using it in a function e.g.
=countblank(index(Base,row(Horizontal),COLUMN(Vertical)):index(Base,row(Horizontal)+rows(Horizontal)-1,COLUMN(Vertical)+columns(Vertical)-1))
gives the result 7 * 31 = 217 in my sheet because I haven't filled in any of the cells.
The Offset version of this would be:
=countblank(offset(A1,row(Horizontal)-1,COLUMN(Vertical)-1):offset(A1,row(Horizontal)+rows(Horizontal)-2,COLUMN(Vertical)+columns(Vertical)-2))
or more simply:
=countblank(offset(A1,row(Horizontal)-1,COLUMN(Vertical)-1,rows(Horizontal),COLUMNS(Vertical)))
So this works well in OP's case where you have two fully overlapping ranges like this:
Partial Overlap
Suppose you have two partially overlapping ranges like this:
You can use a variation on the standard overlap formula (This is one of the early references to it as used with a date range)
max(start1,start2) to min(end1,end2)
So the previous formula becomes
=countblank(index(Base,max(row(index(Partial1,1,1)),row(index(Partial2,1,1))),max(COLUMN(index(Partial1,1,1)),column(index(Partial2,1,1)))):
index(Base,min(row(index(Partial1,1,1))+rows(Partial1)-1,row(index(Partial2,1,1))+rows(Partial2)-1),min(COLUMN(index(Partial1,1,1))+columns(Partial1)-1,column(index(Partial2,1,1))+columns(Partial2)-1)))
and the offset version is
=countblank(offset(A1,max(row(offset(Partial1,0,0)),row(offset(Partial2,0,0)))-1,max(COLUMN(offset(Partial1,0,0)),column(offset(Partial2,0,0)))-1):
offset(A1,min(row(offset(Partial1,0,0))+rows(Partial1)-2,row(offset(Partial2,0,0))+rows(Partial2)-2),min(COLUMN(offset(Partial1,0,0))+columns(Partial1)-2,column(offset(Partial2,0,0))+columns(Partial2)-2)))
I have tested this on ranges C2:F10 and D3:G11 which gives the result 24 as expected.
However, if there is no overlap, this can still give a non-zero result, so a suitable test needs adding to the formula:
=if(and(max(row(index(Partial1,1,1)),row(index(Partial2,1,1)))<=min(row(index(Partial1,1,1))+rows(Partial1)-1,row(index(Partial2,1,1))+rows(Partial2)-1),
max(column(index(Partial1,1,1)),column(index(Partial2,1,1)))<=min(column(index(Partial1,1,1))+columns(Partial1)-1,column(index(Partial2,1,1))+columns(Partial2)-1)),"Overlap","No overlap")
Perhaps the best approach in Google Sheets is to go back to the full version of the Offset call OFFSET(cell_reference, offset_rows, offset_columns, [height], [width]) . Although this is rather long, it will return a #Value! error if there is no overlap:
=Countblank(offset(A1,
max(row(offset(Partial1,0,0)),row(offset(Partial2,0,0)))-1,
max(COLUMN(offset(Partial1,0,0)),column(offset(Partial2,0,0)))-1,
min(row(offset(Partial1,0,0))+rows(Partial1),row(offset(Partial2,0,0))+rows(Partial2))-max(row(offset(Partial1,0,0)),row(offset(Partial2,0,0))),
min(COLUMN(offset(Partial1,0,0))+columns(Partial1),column(offset(Partial2,0,0))+columns(Partial2))-max(COLUMN(offset(Partial1,0,0)),column(offset(Partial2,0,0)))
))
Notes
Why did I have to introduce some more indexes (indices?) in the second formula to make it work? Because if you use the row function with a range in an array context, you get an array of row numbers which isn't what I want. As it happens, in the first formula you are not using it in an array context, so you just get the first row and column of the given range which is fine. In the second formula, Max and Min try to evaluate all the rows in the array, which gives the wrong answer, so I have used Index(range,1,1) to force it to look only at the top left hand corner of each range. The other thing is that both index and offset return a reference, so it is valid to use the construct Index(...):Index(...) or Offset(...):Offset(...) to define a new range.
I have also tested the above in Excel (where as mentioned the Index version would be preferable). In this case Base would be set to $1:$1048576.
Although in Excel you have the Intersect Operator (single space) so it's not necessary to use an Index or Offset formula at all e.g. the first example above would simply be:
=COUNTBLANK(Vertical Horizontal)
and if there is no overlap the formula returns a #NULL! error.
"I've created named ranges for each month of the year, and for each
room. For example, rows 6:36 will represent the month of January,
while columns C:I will represent Room 1. Room 2 will span J:P and so
forth."
What I suggest is that if "January" is defined for columns C to whatever (the last column of the last room), then that's all you need.
You haven't shown us the layout of the dashboard. But let's assume that at the very least you're interested in the income generated by each room.
=query({January},"select sum(Col3) label sum(Col3)'' ")
In this image, the range called "January" is highlighted. Note that it does NOT include the header. Note also that it can be many columns wide; in this example, I've just made up a few columns, but your range should cover all the columns for rooms 1 to n.
Syntax: QUERY(data, query, [headers])
Data: This formula queries the range called "January". That range can be on the same sheet, on on another sheet (such as your Dashboard). Reminder: in this screenshot, "my version of "January" is highlighted.
Query to count Number of People: "select sum(Col3) label sum(Col3)'' "
Query to sum the income earned: "select count(Col2) label count(Col2)'' "
Col2 & Col4 = Number of People for Room#1 and Room#2 respectively.
Col3 & Col5 = Income for Room#1 and Room#2 respectively.
[headers]: You can ignore them.
This formula delivers just the value of the query; even though it includes a "label", the label will not print.
Modify and adapt these formulae to create the other information required for your Dashboard.

How to use an IF to allow me to select between the views?

I am currently creating a dashboard in Google Sheets.
In cell A2, one can select from two views (let's say "test" and "test2").
In A5 they can pick a starting date and in A8 one can fill in the end day.
In cells A10:C17 I have some mock-up data (see below).
Now what I want is to display the data between two dates and based on the views (in the table called selector. Users can select test and test2). I am able to use Filter() to filter the dates, however, I am unable to select a view. Thus I can only use it for the dates, not for the views.
This is the formula that allows me to filter the dates:
=arrayformula(ifs($A$2="test";1)*FILTER(A11:C17;A11:A17>=A5;A11:A17<=A8))
Anyone any idea on how to use an IF (or any other function that might work) to allow me to select between the views?
Mock-up data:
Selector
Test
Start date
01-01-2018
End date
03-01-2018
Date Users Pageviews
04-01-2018 350 400
03-01-2018 300 350
02-01-2018 250 300
01-01-2018 200 250
31-12-2017 150 200
30-12-2017 100 150
29-12-2017 50 100
If you want you can view the spreadsheet here: https://docs.google.com/spreadsheets/d/e/2PACX-1vRjwsm49p48sP2dZXWjdMacw9vLe0GoADLKc_J4E2Sggo5hDpp2a_2zpCsZM4jlW21CfLrG_TSthhV7/pubhtml
In A10:C17 you can see the data I want to show for test and in A20:A27 you can see the data I want to show for test2.
Sample File
=if(
A2="test",
formula_1,
if (A2="test2", formula_2, "Other")
)
In the formula above, if a user selects:
"test", then the result is formula_1,
"test2", then the result is formula_2,
else the word "Other" will appear
Replace:
formula_1 with FILTER(A11:C17;A11:A17>=A5;A11:A17<=A8)
formula_2 with a formula for the second view.
This works for a combined "view" drop down. If you want to separate the view options to get a side-by-side comparison, that should be no problem.
Filter
=IF(A2="test",FILTER(A11:C,A11:A>=A5,A11:A<=A8),IF(A2="test2",FILTER(A11:C,A11:A>=B5,A11:A<=B8),"Sorry. No matches found"))
Selected dates minus 1 year
=DATE(YEAR(A5)-1,MONTH(A5),DAY(A5))
See this Google Sheet
The dates ranges in the drop downs are just data validation based on the spreadsheet data.

Resources