Calculated Fields and increments - filemaker

I am building a system using Starting Point and need help with calculated fields.
Basically when an estimate is created it takes the same ID as the project its linked to with a "-1" 1 being incremental value. So if the increment -1 exists the next estimate for that project would be -2 and so on.
So for example
Project Id: 120000
First Estimate: 120000-1
Second Estimate: 120000-2
I have found out how to add a hyphen and number after the project ID (the stored as estimate ID) like so id_project & "-" & 1 but I have no idea using filemaker how to use calculated fields to look and see if 120000-2 is a thing and if it is make it 120000-3
Any help greatly appreciated

I'm assuming you have at least a relationship between Projects and Estimates. Perhaps something like this (without the Estimates_self table occurrence, which I'll get to in a moment):
If you're in the Projects context (on a layout linked to the Projects table), you can get a count from there using something like Count ( Estimates::id ).
If you want to make this happen from the context of Estimates, create a self-join as shown above, using the project foreign key as the match field. Then you can use Count ( Estimates_self::id ).
Finally, an option without any relationship graph changes would be to use ExecuteSQL:
ExecuteSQL (
"SELECT COUNT(*) FROM Estimates WHERE project_id = ?" ;
"" ; "" ;
Estimates::project_id
)
All of these will give you the number of estimates that a given project has. Add one to that and you have your suffix number for the new estimate.

Count the related estimates based on a parent Project. This will give you the Estimate number after dash

Related

Tableau KPI prev value depending on variable

am trying to get Previous Sum(of someField) based on a variable value which is an Id.
This is not a table, Im doing a KPI
On Qlik you would do something like:
SUM({<Id={"$(=Max(vVariable),-1))"}>} someField)
But I can not achieve it on Tableau, off course is due to my lack of knowledge, unfortunatelly time is tinking at work and wanted to see if anyone has any input!
Thanks
Assuming you may use a sample input like the Superstore (using sales as metric), this could be what you're looking for:
In red you can see your "variable" which allows you to select a value and in blue you'll find the unique row for the previous value (Order ID sorted).
The first thing you need to to do is creating a parameter based on all the Order ID values:
Then things start to get a bit complicated if you're not familiar with LOD (Level of details) and the order of execution in Tableau, especially for filters.
Assuming that you can get some information on your own (otherwise, feel free to ask), the first thing you nee to to do is to "pre-calculate" the equivalent of a table having a rowe for each Order ID, in which you also have the previous Order ID value.
You can achive this combining Fixed (LOD) and Lookup function, creating this Calculated Field "Lookup Order ID":
LOOKUP( max({ FIXED [Order ID] : MAX([Order ID])}),1)
This is actually just a calculated field that you want to "fix" because you need the filter to act after you have made that previous calculus, and then you shift your data by 1 row backward.
Once you've done that, you just nee to create another calculated field in order to test your parametric value, and it could be something like this "check param":
[Lookup Order ID] = [Order ID param]
Moving this calculated field in the filter section and selecting just "true" values, you'll get that unique rows like in the initial image, showing the previous value (blue) related to the one you select in the parameter drop-down menu (red).

Calculate sum of unique tag values

sometimes it appears that one have to calculate SUM of unique TAG values in InfluxDB. How to do it?
For example I have multiple users who downloads software. Now I want to extract how many unique users downloaded it.
Following query was tested in Grafana to calculate unique users and also consider time filter applied to the database.
To do this we need to apply subquery first to calculate mean values, this basically will result a table with value 1 associated for each user:
SELECT mean("count") FROM "autogen"."downloads" WHERE $timeFilter GROUP BY "username"
Here count is an integer value that is equal to 1 for each time user downloads the software.
After we can calculate sum of these mean values, yes, this is not cheap if you have a huge database, but still is a working solution:
SELECT SUM(mean) FROM (
SELECT mean("count") FROM "autogen"."downloads" WHERE $timeFilter GROUP BY "username"
)
Please go ahead and propose best performing/more native solution, this will be nice to apply for larger DBs

To put two level of data in one tableau worksheet and aggregate them

I'm building up a supervisor scorecard on Tableau. Basically, there're two parts impacted on supervisor's score. One is supervisor's own performance, eg. there own's lateness. And the other part was their reporting employees' performance, eg. their employees' absenteesim.
My expectation is aggregating all the criteria in dashbaord, and filter supervisor's ID get his scorecard data. Here is a sample of the raw data:
So from the data we can know that for each CSR, they all have their supervisor, and for a supervisor, their reporting supervisor(which should be a manager) is blank.
So I created 3 calculation filed. One is called SUP_ID, and here's the code:
IF ISNULL([SupervisorID]) THEN [EmployeeID]
ELSE [SupervisorID]
END
Another calculation filed is called SUP_Flag, the code is :
[EmployeeID]=[SupervisorID____OLD]
The last one called SupervisorID___OLD], the code is:
IF [ROLE] = 'Supervisor' THEN [EmployeeID]
ELSE NULL
END
With these three calculation field, i'm able to use SUP_ID to filter all the information I want in each worksheet. When I want each supervisor's belonging employee's performance, I'll just use SUP_ID as filter. If I want each supervisor's own performance, I use SUP_ID as well as SUP_Flag to give me the information, and it works very well.
Everything above was done by separate worksheet.
Now my problem is:
There's a field that i need to put is called supervisor's final score, and it combines with both employee's performance score and supervisor's own performance score together in one filed. These two score are both in previous seperate worksheet. I'm thinking to use LOD to aggregate them, but it doesn't work as my expectation.
Here's what i wrote:
Final_Score_Part1(Sup's performance)
{FIXED [SUP_ID],[Supe Flag]: ([EVALUATION SC]*1* 0.2)}
Final_Socre_Part2(Employee's performance)
{FIXED [SUP_ID],[Supe Flag]: ((([LOST TIME %] * 0.6) + ([ATTENDENCE_SC]*0.2) + ([PUNCTUALITY_SC]*0.2)) * 0.5 )}
Final_Score:
Final_Score_Part1 + Final_Socre_Part2
Here's the screenshot that Tableau gave me.
(I've crossed out Supervisor's name)
So you can see that the part1 score was based on Sup_Flag = True, and part2 socre is based on SUp_Flag = Null, so when i aggregate them, it still won't give me the correct score.
Can somebody help me with this? I'll be so apprecaited for your help.
Thanks
Hi #Phani,
As i couldn't upload an image in comment, i've posted the new image here
enter image description here
For Final_Score_Part1(Sup's performance): include the condition
IF [ROLE] = 'Supervisor' THEN calculate the score[]
ELSE NULL
END
The same condition need to be used in Final_Socre_Part2(Employee's performance).

SSRS Grouping Summary - with Max not working

This is the data that comes back from the database
Data Sample for one season (the report returns values for two):
What you can see is groupings, by Season, Theater then Performance number and lastly we have the revenue and ticket columns.
The SSRS Report Has three levels of groupings. Pkg (another ID that groups the below), venue -- the venue column and perf_desc -- the description column linked tot he perf_no.
Looks like this --
What I need to do is take the revenue column (a unique value) for each Performance and return it in a separate column -- so i use this formula.
sum(Max(Fields!perf_tix.Value, "perf_desc"))
This works great, gives me the total unique value for each performance -- and sums them up by the pkg level.
The catch is when i need to pull the data out by season.
I created a separate column looks like this
it's yellow because it's invisible and is referenced elsewhere. But the expression is if the Season value = to the Parameter (passed season value) -- then basically pull the sum of each of the tix values and sum them up. This also works great on the lower line - the line where the grouping exists for pkg -- light blue in my case.
=iif(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
However, the line above -- the parent/header line its giving me the sum of the two seasons values. Basically adding it all up. This is not what I want and also why is it doing this. The season value is not equal to the passed parameter for the second season value so why is it adding it to the grouped value.
How do I fix this??
Since your aggregate function is inside your IIF function, only the first record in your dataset is being evaluated. If the first one matches the parameter, all records would be included.
This might work:
=IIF(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
It might be better if your report was also grouping on the Venue, otherwise you count may include all values.

Tableau Mixed Data

I've been tasked to set up a Tableau worksheet of counts of data (ultimately to create percentages) where the contrived incoming data looks like the following.
id fruit
1 apple
1 orange
1 lemon
2 apple
2 orange
3 apple
3 orange
4 lemon
4 orange
The worksheet needs to look something like the following:
Count of ids
2 Lemons
2 No lemons
I've only been using Tableau for about 4 hours, so is this doable? Can anyone point me in the right direction?
The data is coming in from a SQL Server database in a format that I can control if that helps contribute towards a solution.
Alex's solution based on sets are very good for this scenario, but I would like to show that LODs can be more flexible if you need to extend your solution to include more categories.
for the current scenario, create a calculation with below formula and create text table using COUNTD(Id)
{FIXED [Id]:IF MAX([Fruit]='lemon') THEN 'Lemon' ELSE 'No Lemon' END}
Now for the extension part, you are considering below list where you want to count IDs with Lemon, Apple and others. Since no double counting of Ids are allowed, categorization will follow the order. (This kind of precedence will be a headache without LODs)
Now you can change your calculation as below:
{FIXED [Id]:IF MAX([Fruit]='lemon') THEN 'Lemon'
ELSEIF MAX([Fruit]='apple') THEN 'Apple'
ELSE 'No Lemon or Apple' END}
Now your visualization automatically changes to include the new category. This can be extended for any number of fruits.
This is a good use for a set.
In the data pane on the left sidebar, right click on the Id field and create a set named "Ids that contain at least one lemon" (or use a shorter less precise name)
In the set definition dialog panel, define the set by choosing "Use all" from the General tab, and then on the Condition tab, define the condition by the formula max([Fruit]="lemon")
There are many ways to think of a set, but the most abstract is just as a mathematical set of Ids that satisfy the condition. Remember each Id has many data rows, so the condition is a function of many data rows and uses the aggregation function MAX(). For booleans, True is treated as greater than False, so MAX() will return True if at least one of the data rows satifies the condition. By contrast, MIN() is True only if ALL (non-null) data rows satisfy the condition.
Once you have a set that separates your ids into Lemon scented Ids and others, then you can use that set in many ways - in calculated fields, in filters, in combination with other sets to make new sets, and of course on shelves to make visualizations.
To get a result like your question seeks, you could put your new set on the Row shelf, and put CNTD(ID) on the text shelf or columns shelf. Make sure you understand why you need count distinct (CNTD) instead of SUM([Number of Records]) here.
BTW, the LOD calculation { fixed [Id] : max([Fruit]="lemon") } is effectively the same solution.