Filemaker - Calculate remaining days of leave - filemaker

I would like to calculate the total number of leave days taken for a specific type of leave to find the balance for that type of leave. An example, I have made three entrees for annual leave on different dates and I would like to know the annual leave balance.
When creating a new entry and selecting Annual leave for the type of leave, I want a field to show the balance of that type of leave. Screenshot

Something like this should get you started. A calculation field or variable with this calculation will give you the balance for a record id from your person table within a period for a certain type. You need to populate the variables with your search criteria or use fields from your form as input.
ExecuteSQL (
"SELECT SUM("Leave Days")
FROM thetable
WHERE "record primary key field" = ? and "Start Date" >= ? and "End Date" < ? and "Leave Description" = ? "
; "" ; "";$recordid;$startdate;$enddate;$type )

I was able to solve the issue by adding a calc field on "Entitled Leave" table summing the used leave days from the "Used Leave" Table, then subtracting them which gave me the balance.
Thanks for the help everyone.

Related

PowerBI - calculation with 2 different dates

I have one data table from which I have to calculate 2 different KPIs, each KPI is tied to different date column.
"Creation Date" for KPI "Net Satisfaction Score" calculation and "Uni Date" for KPI "Response Rate" calculation.
"Date" from "Date table" used as field to filter time periods so I need to have a relation to that field.
table design
If I filter for results in September'22, I want to see "Net Satisfaction Score" calculated from all Ids with Creation date in SEP'22, and I want to see "Response Rate" calculated from all Ids with UniDate in SEP'22 (this means Ids 00004, 00007, 00009 and 00010 are not to be considered in Response Rate calculation).
What I have tried already:
Using more queries - one for Response Rate (with relation UniDate <-> Date) and second one for Net Satisfaction Score (with relation Creation Date <-> Date).
This worked, but if I want to go more into detail and see the results by country, the numbers don't show up correctly, as there is no relation on "Country" or whatever detail I want to split the result by.
Making relation based on IDs between the queries mentioned in "1)" - circular dependency error.
I am really out of ideas, but maybe some of you tried to solve this kind of issue already.
Sounds like you need to use USERELATIONSHIP within your measure.
You will need something like this
Net Satisfaction Score = CALCULATE(Sum('Net Satisfaction Table[Score]'),
USERELATIONSHIP('DateTable[Day]','Net Satisfaction Score Table[Created Date]))
You can obviously use sum, count, average...whatever you need to do with your score. You also need to make sure that both dates - Created Date and UniDate have an inactive relationship back to your Date Table.
Repeat the same measure example for your other measure. USERELATIONSHIP works perfectly on inactive relationships and only works within CALCULATE operation where you tell PowerBI which date to use in this calculation.

Tableau measure count items if between dates

What I am trying to achieve is to get a count of people employed in a particular period.
I have 3 variables:
Employee ID (integer)
Hire date (date)
Termination date (date or null)
Example
the formula I am looking for is something like
if termination_date is null
then
count employee_ID in
dates between Hire_date and max of either hire_date or termination_date
else
count employee ID in
dates between hire_date and termination_date
This aims to show the dynamic of staff level over the time.
I am new to Tableau, not sure how to even start with it. Any suggestions welcome.
This problem will be simpler if you reshape your data to have the following three columns
Employee ID
Date
Action. (where action takes on the values of ‘Hire’ or ‘Terminate’).
Each data row represents one change in status for an employees. If an employee had a termination date, they will have two records in this new format, otherwise just one record showing the hiring date.
You can reshape your data by hand, or leave the original and use Tableau Prep or the Tableau data source page to reshape using a self Union and a few simple calculated fields.
Define a calculated field called Staffing_Change as
if Action=‘Hire’ then 1 else -1 end
Now you can plot the change in staff level over time by putting exact date on columns and sum(Staffing_Change) on Rows. You can use a quick Table calc, Running Sum, to see the net staffing level. For line mark types, I’d use a step style by pressing on the path button on the Marks card. Otherwise, the chart can give the impression of fractional number of employees.

Count at the end of a month in Tableau

I want to find the number of customers per subscription plan at the end of the acquisition month.
As you can see in the workbook, customers can change their subscription plan on any date, but I only want to find the subscription plan at the end of the acquisition month.
I created a field, called EOM Acquisition, but need to find the desired output below for any given month of acquisition. (in sample dataset only October).
How can I do that? Thanks in advance!
Please proceed like this. Create a new calculated field say calculation1 as follows-
IF [Date] = [EOM Acquisition] then [Subscription Plan] END
drag this field instead of subs plan in view and filter out null values, you'll get what you want
Another way add a calc field as follows
IF [Date] = [EOM Acquisition] then 1 ELSE 0 END
And thereafter add sum on this field as measure alongwith EOM and subscription fields.

Count records as proportion of total in Tableau

I have data with sales, details including gender, location, date, etc. There's one row for each sale, so the total number of sales is a count of the rows.
customerid sale_date regionid studentid sex
18761372 01/09/2016 AFB07458 C2F815C6 1
18761372 01/09/2016 AFB07459 206AA234 0
07189635 01/09/2016 AFB07460 F218C8F1 1
07189635 01/09/2016 AFB07461 F021CD27 0
07189635 01/09/2016 AFB07462 E6145555 1
I'm trying to produce a line graph that shows number of sales by month, split by male and female. However male sales are ~5million for the year, and female are ~13 million. So it's hard to compare whether there's any difference in how the sales vary by month (i.e. whether males are proportionately more likely to buy in september).
I manage to get this to work by creating the following calculated field:
If [sex] = 0
THEN 1/5000000
ELSE 1/13000000
END
This does what I need, but it's not a great solution as it involves me manually checking what each total is and writing it down (admittedly not much of an issue with sex, but if I'm doing it on something with multiple fields then it would become very time consuming.
Is there a way of doing this more elegantly? I tried to use sums and case statements in there but I got "cannot mix aggregate and non-aggregate arguments".
I would approach this with a calculated field that shows a percent of total, by month.
Right click on your pill, select 'Quick Table Calculation' and choose 'Percent of Total'.
That way, instead of looking at a count of orders where one group always appears greater, you are looking at their share which will be more uniform.
Maybe I'm understanding this wrong but it seems fairly straight forward. Using the sample data provided I just:
Add the date field pill "sale date" to the column shelf(set it to pull back the month)
Drag the "number of records" to the rows shelf(automatically sum the results)
In the "Show Me" section in the top right select line chart.
Drag the sex pill onto the color card, this will break the line into to two, one for male the other for female(you may have to convert the sex pill to a dimension, to do this right click the pill and select "convert to dimension")
Let me know if this solves it for you?

How to display a full set of group headers in Crystal reports?

I have tricky question regarding Crystal reports. I have a data source that is basically like
DateGroupKey | Shop name | etc.
DateGroupKey =1 is this month, =2 is the previous month, =3 is the month before the previous. The trick is, every shop is only once in this list, in the most recent month, that had some activity. It is done with some sql magic, not the point of the question.
The report has two levels the top level looks like this:
This month (number of entries)
Previous month (number of entries)
Month before previous (number of entries)
No activity in the last 3 months (number of entries)
It has a #monthname variable that has a formula like:
IF ISNULL({GetOrders.DateGroupKey}) THEN "No activity in the last 3 months"
ELSE IF {GetOrders.DateGroupKey}=0 THEN "This month"
ELSE IF {GetOrders.DateGroupKey}=1 THEN "Previous month "
ELSE IF {GetOrders.DateGroupKey}=2 THEN "Month before previous "
The ground level looks like a list. If you double click on the 'This month' it will show only those records. This is well and good so far.
Now the question, if there are no entries for example with the DateGroupKey 1 there will be no group header 'Previous month'. I would like to have a group header displayed (even with 0 entries). How can I do that?
Thank you for your help!
Sziro
Edit: picture of the design:
This is a tricky one. If there is no data for a particular scenario, then CR doesn't know that there actually is a group. What you will have to do is create a dummy table that has one column that lists all your possible groups. You will have to add that to your report and then outer-join your real data table to the dummy table. That should give you all your data with a group for each one even if there is no data for a group.