How to calculate consecutive missed visit in Tableau? - tableau-api

I want to find consecutive missed visit by the site. First I created a flag if visit completion = missed then 1 else 0
Next, I created the following calculation to count the consecutive
Now my questions are following,
1) If I am counting consecutive missed visits, then shouldn’t I ignore the first index/occurrence? i.e., in this case, the count should show 8? How to do that?
2) How to aggregate it up to site level?
Looking forward to your help. Thank you in advance.

For part 1 of your question, to set the first occurence as 0, you can tweak your existing calculation: (picking up from the middle of your formula...)
...THEN IF FIRST()=0 THEN 0 ELSE PREVIOUS_VALUE(0)+1 END...
Part 2, to aggregate to site level, is more tricky. You'll need the VisitNo on Detail as it's needed for the calculation. You may need to wrap the entire calculation in:
IF LAST()=0 THEN [FormulaCalcField] END
Hence only keeping the final result of the calc. These things are complicated...

Related

Finding a max value restricted by Date

First of all thank you for the treasure of information! I have found many answers so far but I have run into an issue I cannot solve.
I run a database with vehicles involved and beginning mileage is something I would like to automate. I have tabs all keeping a tally of beginning and ending mileage based on a query of the main index of all trips. I have been using a vlookup function but I have found that it is quite fragile (amongst other calculations) and I have been converting them over to script in the hopes that it remains more robust (ie accidentally typing in a calculated field....which wipes thousands of trips in a single stroke. Since they are Vlookup currently I have to go back and systematically restore the correct calculation (takes a couple of hours to do).
My first attempt is here:
1: On the main page I would utilize vlookup which I restricted with a status:
=arrayformula(if(M2:M="Ready",vlookup(J2:J2287,'Vehicle Lifecycle'!$A$2:$L$30,7,false),O2:O2287))
2: On the Vehicle Lifecycle page I utilized a max formula which looks up the max mileage constantly for maintenance costs per mile:
=max('C-2'!$F$2:$F)
I would like to script a restriction with a date (meaning it doesn't look up a max after the date of the trip).
Or, if it might be more direct, find a way to lookup the last previous trip with the vehicle and pull the ending mileage.
Currently I have this as a script but I am just getting started with scripting so forgive my ignorance. I am a quick study however and so far I am doing well...ish
function myfunction()
{
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
ss.getRange("O2").setFormula("=iferror(max(indirect(\"'\"&J2&\"'!$F$2:$F\")),\"\")");
var filldownrange = ss.getRange(2,15, lr-1);
ss.getRange("O2").copyTo(filldownrange)
}
This is perfect for pulling the max value from the appropriate tab so I'm close. Can anyone help me get the cigar?
I got it!!! I started working with a formula and I bumped into a problem when I looked for just the date on vlookup. The solution was subtracting 1 from the date and looking for that.
function onVehicleSelection()
{
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
ss.getRange("O2").setFormula("=iferror(vlookup(to_date(minus(C2,1)),indirect(\"'\"&J2&\"'!$B$2:G\"),5,true),\"\")")
var filldownrange = ss.getRange(2,15, lr-1);
ss.getRange("O2").copyTo(filldownrange)
}
However if someone has a more elegant solution I would be interested to hear it. I could definitely use some pointers on triggers as I will be working on those after I figure out how to do about 8 more calculations in script. So far I have been lucky enough to have functions that translate nicely.

Reference numbers not in chronological order (wrong order in captions)?

I need to submit my thesis in word in a few days and heard that I could not submit it if my reference numbers were not in chronological order.
Word seems to number text references first and then start on captions in tables and figures. The result is that for example on the first page I have an alinea with reference number 1 at the end and below is figure 1 with reference number 59 in the caption instead of reference number 2.
Last year I used EndNote, this year Mendeley and had the same problem with both. If you need more information, please let me now. It's quite an emergency, need to solve this as quick as possible.

Getting a percentage in Tableau from a yes/no column

I have a spreadsheet of support case management data. I am working with this in Tableau. Each line in the spreadsheet is an individual case. Each case has, among much else, a support agent name and a Yes or No of whether the case work was started within 12 hours. I'd like to know, for each agent, what percentage of the time they started the case work within 12 hours. So, if Bob has 2 "No" and 8 "Yes", he should have 8 / (2 + 8) = 80%.
My attempt at this was to create 2 sets. One is the set of "Yes, started within 12 hours" (those that have "yes" in that field, and one that is the set of "No, not started within 12 hours", the complement to the other set. Silly me, I thought I could do something like COUNT(yeses) / COUNT(nos). Nope, big red failure. So what is the right way to do this?
It would help immensely to please respond as if this is the first thing I have ever done in Tableau. It is. I have learned a lot in this project, but only in comparison to the nothing I knew previously. Please also let me know if I've left out something necessary to answer this. I've tried to be complete but, well, am noob...
If it clarifies anything, here's a poor Excel mockup of data and the effect I'm looking for:
Yes, this is possible and easy in Tableau, but first a couple of points.
The reason your attempt to use COUNT() did not work is that COUNT() does not operate the way you, and that 99% of the people on the planet, expect. COUNT([some expression]) returns the number of records that have a non-null value, any value, for [some expression]. The name comes from SQL relational databases.
The calculations would be just a bit simpler if your third column took the boolean values True or False instead of the string values “Yes” or “No”. (In which case you could drop ‘= “Yes”’ from the formula below)
So two ways to do your calculation are:
Directly with an aggregate calculation which can get the right result, but is hard coded for this case, such as:
SUM(INT([Started within 24 hrs?] = “Yes”)) / SUM([Number of Records])
Using a table calc - which in this case is a bit easier and more flexible.
First, Build a table or viz in Tableau showing SUM([Number of Records]) with the dimensions you care about in play. Say with [Name] on Rows, [Started within 24 hrs?] on Columns and SUM([Number of Records] on Text. Second, Right click on your measure SUM([Number of Records]) and choose Percentage of Total from the Quick Table Calc menu. Finally, use that same menu to adjust Compute Using to specify how you want the percentages computed - in this case, using [Started within 24 hrs?]
If you only want to show some of the data, right click on the column header for the values you wish to hide and choose Hide.
The type conversion function INT() converts True to 1 and False to 0.
You could create another column that converts the Yes's into 1's, and the No's into 0's. Sum up all the 1's and divide it by the total and that's your percentage.
edit: the new column would look something like
=IF(C3="Yes",1,0)
in other words, if Cⁿ is "Yes", then 1, else 0

How to get the sum directly with one number?

I'm a beginner for tableau. I want to get the direct numbers for each row, but i get the number which are separate, how can i achieve this?
I've tried the sentence like:count("Implemented"), but I don't get the result I want.
For example, for the 1st row I want 3 10 10
not 111 10 112111111
Here is worksheet.
My code:
EDIT :
here is the photo for implementation opportunities
As you can see, the status is related to the date, I think maybe it causes the records which are counted 1by1.
Now the situation is that: i create the code which is related to the date, if i remove this from mark, it will cause the problem (the code is related to the date), but if i leave it, the system will always count it one by one. My code is not perfect but i can't find another one which can replace it.....
EDIT 2:
in short,what i want is the sum of the remaining opportunity:10
capture
Remove DAY from Mark shelf. That detail is producing those separations.
Attaching a workbook with numbers similar to (but not exact due to proprietary issues) is almost always advised. You will get the right answer a lot sooner than just screenshots.
In any case, it seems as if the measure portion of the visualization is properly being summed by the date. Try selecting the measure, and manually selecting "sum" from the menu drop down. Here is a link for more detail.
Secondly, you can play around with table calculations. Click this link and read up on option 3.

BIRT. Average function without value '0'

I am making reports with BIRT. I have table with "item planed quantity", "finished quantity", and percentage. Something like this Planed 50 , Finished 20, Percentage 40%... and etc.
and after this line i have sum of 'planed quantity', sum of 'Finished quantity'
and ave of percentage. the main problem is that this ave formula is taking percentage whic is equals to 0.
Anyone know how to set filter or expresion like "measure["percent"] != '0'" or something like this?
for the record, 192.168... is a purely internal IP. Unless someone is on your LAN, they won't have access to it. This means that nobody on the WAN can see the link you posted.
As to your issue - here are a few things to try:
1. Check your data type. I think integers round down so AVE( 12/13 ) will equal 0 instead of 0.923.
2. If your wanting to avoid zero values in your average, you'll need to gather counts of non-zeros which requires some scripting. You'll probably be best off creating a scripted data set for this.
See if you can take a screenshot and attach it to this issue if neither of these ideas work or if you need further assistance (particularly with the second option I suggested).
Thanks!