Spotfire Custom Expression - spotfire

In spotfire need to extract employee name for a particular quarter, how many added and left.
like we have
Employee_nm Quarter
Mohan 1
Rohan 1
Sohan 1
Mohan 2
Rohan 2
Joseph 2
output:-
When we select Quarter 2 result should
Left Add
Sohan joseph

An IronPython script could do this with a property control setting the quarter of interest.
User selects number 1-4 from a drop down menu which is stored in the document property 'lstQuarter' and connected to the script that does the calculation.
Pseudocode for the calculation:
Access the table
Fill listA with all the names from lstQuarter - 1
Fill listB with all the names from lstQuarter
Iterate through the lists comparing each name. Those in listA but not listB have been removed, those in listB but not listA have been added.
Write this information into a string, out to excel, wherever you want it.
If you want to update a table in Spotfire with this information you'll need to write it to Excel first and then replace the data table with it but this can all be scripted.

There is a solution to this issue that requires only a property control and 2 calculated values set into a text area plus 2 calculated columns.
Firstly, I extended the dataset to show a full year:
Employee_nm Quarter
Mohan 1
Rohan 1
Sohan 1
Mohan 2
Rohan 2
Joseph 2
Mohan 3
Joseph 3
Katelyn 3
Katelyn 4
Joseph 4
Wesley 4
Next, the calculated columns:
Case First([Quarter]) OVER ([Employee_nm])
when 1 then "Q1"
when 2 then "Q2"
when 3 then "Q3"
when 4 then "Q4"
end as [added]
-and-
if(Last([Quarter]) OVER ([Employee_nm])!=Max([Quarter]),
Case Last([Quarter]) OVER ([Employee_nm])
when 1 then "Q2"
when 2 then "Q3"
when 3 then "Q4"
when 4 then "Q1 Following Year"
end,"") as [left]
NOTE: The above only accommodates the given dataset but can be easily be extended to accommodate multiple years.
The Property control should be set up like so:
Finally, the calculated values:
UniqueConcatenate(if([added]='${Quarter}',Concatenate([Employee_nm]," added ",[added]),""))
-and-
UniqueConcatenate(if([Left]='${Quarter}',Concatenate([Employee_nm]," left ",[Left]),""))
NOTE: The above values will exhibit a leading comma in many cases due to the 'UniqueConcatenate()' function. These can be dealt with using text functions within your calculated values and that logic has been left out of this answer in the interest of readability.
I hope this helps.

You can insert a calculated column to identify the employees added/removed per Quarter:
Concatenate(If(Find([Employee_nm],Concatenate([Employee_nm]) OVER
(Previous([Quarter])))=0,"Added in this Quarter"),If(Find([Employee_nm],
Concatenate([Employee_nm]) OVER (Next([Quarter])))=0,"Removed from Next
Quarter"))
You can see result per Quarter by filtering on Quarter column.

Related

EXCEL formula to sum demand per date when multiple entries of dates exist

How do I sum the amount of demand I have for each date, when there are multiple entries for each date., e.g.
Sheet 1:
A B
Date Demand
13/7/21 5
13/7/21 4
13/7/21 2
15/7/21 6
15/7/21 3
16/7/21 2
16/7/21 4
So I'm trying to get a summary as follows:
Sheet 2:
A B
13/7/21 11
14/7/21 0
15/7/21 9
16/7/21 6
17/7/21 0
I've tried =SUMPRODUCT(--('Sheet 1'!$A$2:$A$240='Sheet 2'!A2),'Sheet 1'!$B$1:$B$240)
I'm not wanting to do a pivot table, as the pivot table does not give me the zero values for dates where there is no data (unless there is a way to show this in a pivot)
You can use SUMIFS() like
=SUMIFS(Sheet1!B:B,Sheet1!A:A,A1)
You can also use SUMPRODUCT() in this way.
=SUMPRODUCT((Sheet1!$B$2:$B$8)*(Sheet1!$A$2:$A$8=A1))
Put together quickly to start you off:
Edit to give text version of the solution to the OP's problem:
=SUMIFS(B6:B12,A6:A12,"="&G12)
Then you can do between by setting lower and upper criteria in the sumifs().

Rank, group and set a label in Spotfire table

I have two column [Clients] and [Sales], I'd like to create a new column containing a scoring (from 1 to 5) for each "Client" in terms of Sales.
I want to make a ranking of [Sales] and split it, uniformly in 5 groups, then set a label 1 for the highest [Sales], 2 for the second group, etc...
Does someone have an idea of an expression to use ?
You can use the percentile function in conjunction with a case statement. In the screenshot below, I created 5 calculations to find the 20th, 40th, 60th, and 80th percentiles and then created a case statement to rank based on those values.
Percentile calculation:
Percentile([Sales],20)
Case statement:
case
when [Sales]<[20th Percentile] then 1
when ([Sales]>=[20th Percentile]) and ([Sales]<[40th Percentile]) then 2
when ([Sales]>=[40th Percentile]) and ([Sales]<[60th Percentile]) then 3
when ([Sales]>=[60th Percentile]) and ([Sales]<[80th Percentile]) then 4
when [Sales]>=[80th Percentile] then 5
else NULL
end
See attached screenshot
Data sample and calcs

Excel with rows of details related to other row

There is a way to have a group of rows related to other one, in the same sheet, like a more detailed information? Obviously must keep them always next to the main row if you filter or sort.
Desired example based on vehicles and travels:
A B C D
1 [ID] [VEHICLE TYPE] [BRAND] [COLOUR]
+ 2 A-171 PICKUP HONDA BLACK
- 3 [TRAVEL] [KM] [STATION]
- 4 12/08/2016 13.000 BARCELONA
- 5 13/08/2016 13.750 DONOSTI
+ 6 B-501 VAN RENAULT WHITE
- 7 [TRAVEL] [KM] [STATION]
- 8 12/08/2016 117.800 PARIS
- 9 13/08/2016 120.000 AMSTERDAM
- 10 14/08/2016 124.320 MUNICH
So when you sort the spreadsheet, should keep always the travel rows next to the vehicle row.
It is that possible? If not, what can I do to get this or similar? (I don't mind to use other sheet tab, but it wasn't the ideal)
You can use the Group function (Alt-A-G-G), and they won't be sorted as usual if you use sort on the whole column

Count in Excel over a range using 2 columns of data

Tried looking for an answer first...
I want to count the number of items that were open between 1-7 days, 8-14 days, etc etc (open and closed on same day = open for 1 day)
Is there a way I can count this directly using the 2 columns holding the data without creating a 3rd column for Date Closed - Date Opened +1??
So in this example, what can I use to calculate that the number of 1-7 days items is 2? (Items 1 and 3)
Item # Open Closed
1 01/06/2014 01/06/2014
2 05/05/2014 20/06/2014
3 10/06/2014 16/06/2014
4 08/06/2014 15/06/2014
5 02/06/2014 19/06/2014
Many thanks :o)
One way would be to use the versatile SUMPRODUCT:
=SUMPRODUCT(1*(C2:C6-B2:B6+1>7))
assuming your start date column is B and end date column is C. The second part of the formula will determine all date spans which are larger than 7, and the 1* will convert the TRUE values to 1 in order to sum them up.

Count names one time (per year) regardless of how many there are by year

The problem is:
There is a table that gets data added to it each month. I use this data for many different pivot tables and reports, so I am not able to modify it. The user has requested that if its possible (and I assured him that it was) he would like to see two (2) single values of This Year and Last Year Doctors on the list.
The data looks something like this:
Doctor, In/Out, Date, Number
John Deaux Out 10/1/11 8
John Deaux Out 11/1/11 3
John Deaux Out 01/1/12 5
John Deaux Out 05/1/12 3
John Deaux Out 09/1/12 1
Billy White In 02/1/12 2
Mike Adams Out 06/1/11 6
Mike Adams Out 10/1/11 9
Mike Adams Out 01/1/12 1
Mike Adams Out 04/1/12 6
I would have 1 John Deaux for 2011, and 1 for 2012. The same for Mike Adams.
TY 2
LY 2
Now I only have to count the "Out"(s), so I have to be careful of that. Also, there is the chance that I would have to build this for the previous 12 months as well making it that much harder.
1 for John Deaux for the previous 12 months.
TY 2
LY 1
*TY: This Year - LY: Last Year
To do this manually:
Since you can't make any edits to the existing table, copy everything to a new table.
In the new table, add a column called Year. Use the Year() function to get the year out of the date cell.
Make another column called Count. Use If(A2="Out",1,0) where A2 is the cell in the In/Out column.
Copy the Doctor, Year, and Count columns to a new table.
Excel 2007 and above has a convenient tool called Remove Duplicates in the Data ribbon. Use that to remove the duplicates. This will keep you from counting a single doctor twice in the same year.
Create a pivot table, using Doctor as the row, Year as the column, and sum(count) for the value.
Check this, this will check the B column for the year 2012/2013 and count the distinct unique values in column A.
=SUM(IF(FREQUENCY(IF(YEAR(B1:B11)=2013;A1:A11);A1:A11)>0;1)) + CONTROL + SHIFT + ENTER
=SUM(IF(FREQUENCY(IF(YEAR(B1:B11)=2012;A1:A11);A1:A11)>0;1)) + CONTROL + SHIFT + ENTER

Resources