Create calculated column in one table using data from another table in Spotfire? - spotfire

Apologies for asking this, I see a few similar questions but unfortunately I don't really understand the answers given. I am fairly new to Spotfire.
I am trying to create a calculated column in one table based off of data from another table. The first table (which I am trying to add the new column to) is a monthly data census of all contracts the company has. Each contract has one row. Call it "monthly table". The second table is a complete transaction history for all contracts, so each contract can have hundreds of rows. Call it "total table".
I am not sure if I can link the data tables. I read in a few similar questions to insert columns from the table with data into the table where the new column will go, or to merge them beforehand, but the monthly table has about 13,000 rows compared to the total table's 550,000, so I am not sure how this would work.
I am trying to create a column to sum all the transaction amounts for each contract if the transaction type (also in the total table) is equal to a certain string. Like a "net transactions to date" column. I successfully created this column in the total table, but then each cell for a contract that meets the conditions had the transaction sum. I want it in the monthly table, where each contract just has one row, and it only displays the sum once. This is the code I have:
IF(
Concatenate([Contract_Number],"(transaction type string)",[Month],Year([Date]))
=[Type],
Sum([Amount]),
NULL)
It is currently in the total table. If possible I would like it in the monthly table, and for the [Number] and [Date] columns to refer to the monthly table, and [Type] and [Amount] to the total table.
Sorry if this is too much information or confusing! Also I know there is a problem with my summation (it is summing all transactions and only displaying in the correct rows, but it needs to only sum correct rows), but I think I can figure that one out, I just need help getting it in the right table.
I am currently working on transitioning a process/workbook from Excel to Spotfire.
If it would help I can provide the current formula used for this process in Excel.

After a few more hours of tinkering, I figured it out! I thought I would explain what I did here in case anyone else encounters a similar conundrum.
TLDR; Made the desired column in the total table, and added the new column to the monthly table with a left single join on the contract number.
My month and date are tied to a document property which is a drop-down of unique date values in my monthly table. Within the total table, I used a similar code to what I've typed above, but instead of referencing the Date column directly, I referenced the document property, so it was pulling the date from the monthly table into the total table. I also switched from the form IF(condition, SUM()) to SUM(IF()) OVER (). This ultimately summed the correct values. For example, there might be five different types of transactions for each contract, but I only wanted the sum of two types. This resulted in the correct sum being displayed. The sum was displayed in every single cell corresponding to the correct contract number in the new column, so (in the same example) in all 5 contract #1 rows, the sum of the two correct types was displayed.
Then, I went to the data canvas for my monthly table, and added the new column. I chose a left single join, as each contract had only one row in the new table, so that the correct sum would only be displayed once.
End result code:
SUM(IF(Concatenate([Contract_Number],"type-string",[Month_ValDt],[Year_ValDt]) =
[Type], [Amount],0)) OVER ([Contract_Number])
Where [Month_ValDt] and [Year_ValDt] are new columns I made in the total table that display the month and ye
ar from the document property that is tied to the date in the monthly table.
Reasoning for the property is that we have a few years of data but I was told to make it dynamic so only one month of data is visible at a time, hence the drop-down.

Related

Function to filter excel table data in to a new dataset based on value defined in another table

I have two tables of data, the first is EmployeeSalaryTbl which holds the salaries for employees over time:
and the second StaffDetailsTbl which has details on the employee discipline etc.
I use various columns from the tables in a function to calculate total employee salaries per month and I'd like to re-purpose the function to only calculate the salaries dependent on a specified discipline in a given cell, for example Progamming.
To do this, I was thinking, is it possible to filter the results of EmployeeSalaryTbl[Employee], EmployeeSalaryTbl[Salary Start Date], EmployeeSalaryTbl[Salary End Date] etc to only contain the rows where the employee has the Programming discipline through a lookup in to the StaffDetailsTbl?
If it doesnt need to be pretty and you just want to sum the totals
You could put this in the column next to your table, starting at the first row you want to check from. then at the bottom sum up the values. You can change where it says programming to make it a cell reference if you want to check for various disciplines
=IF(INDEX(StaffDetailsTbl[Discipline],MATCH(EmployeeSalaryTbl[[#This Row],[Employee]],StaffDetailsTbl[Employee],0))="programming",EmployeeSalaryTbl[[#This Row],[Salary]],"")

Assistance needed pivot table, Countif, Averages, and tons of data

I have a pivot table with employees names, their grand totals of cases worked for the month, the days they worked during the month, and the case counts for each day.
I have them all stacked on top of each other on a sheet for fast viewing.
I created a column to countif Column (A) has a partial text value that matches the month.
In that column (AR) it returns 1 for true and 0 for not true.
I'm trying to create a formula where it sums up the 1s between the 0s.
The picture is horrible due to the size limits.
Basically, I need to count the days the employee worked and find the average case count for the month for each employee.
I can't use the average function in the pivot table because the count is based on IDs.
I tried If statements, and SumIfs.
ATTACHED IS A SAMPLE OF THE FILE I'M WORKING WITH
Picture of the Spreadsheet as requested
Sorry, i'm working on Excel in french. But I hope my answer with the file modified will help u understand what I'm talking about.
Here is your Excel sample with my modifications : Your Excel file that I modified
You can create another pivot table, that uses your previous pivot table as new datasource. But before doing that, make sure the elements of your first column "Claimed by" is repeated, by checking the column option "repeat element labels" like this :
In this new crosstab, you add as columns : the sum of "Case Count" ; and the count of "Days".
After that, you can filter the column "Claimed by" by selecting only elements without the word "total".
Then your average will be obtained simply by dividing the two columns.

Replace value in the same column based on ID number EXCEL

Does anyone have an idea how to solve this problem using Excel? I have this table. As you can see there is false information in the data, as the "Customer_since" column has different values for the same customer (column "cust_id"). "Customer since" column defines the year of the customer's first purchase. Here is the table:
In fact, the year of the first purchase must be the same in all rows for the same client. In my solution, I would like to keep the earliest year (of the first purchase) for all clients. As you can see one client can appear in many rows, for example, client 275250 had 8 purchases (means 8 rows in a data set) and client 275246 had only 4 purchases. I cannot change it manually as the data set contains over 7000 rows. The desired solution would be to get the same year of their first purchase for the same customer in all rows (for example, correct data is for 275252 and 275233 customers).
MINIFS will get you there. https://support.microsoft.com/en-us/office/minifs-function-6ca1ddaa-079b-4e74-80cc-72eef32e6599
Below, I'm using formula =MINIFS(C:C,B:B,B2) where C:C would be the range of your transaction dates, B:B is the range of customer IDs, and B2 is the current customer ID.
I would do the following:
Create a new table with unique cust_id and the corresponding min(Customer_since). A PivotTable would do it easily.
Change the column Customer_since to use XLOOKUP() to find the correct value on the new table.
If needed, you can do it on another worksheet and Paste Values back into this.

Calculate average of values in a column based on matches of two variables in two other columns

I'm having an issue with some data that I'm working on that has had me stuck for a while.
I'm working on some patient data for a clinical practice that has each patient encounter logged on a separate line with an account ID, date of service, the height and weight measurements for that date, and other variables.
Aside from VLOOKUP and the usual formulae/functions I've got a pretty rudimentary understanding of Excel but I can pick up on things fairly quickly.
In the data I've got each line tied to a patient account ID as well as what quarter the DOS was in. For patients with multiple visits, they will be identifiable by repetitions of the account ID number on other lines.
For some patients, there will also be repetitions in the quarter if the same patient was seen twice in the same quarter. This is where I need help.
I'd simply like to average the value of a variable for each patient in each quarter. I'm not sure if AVERAGEIFS is the right function to use but I need an operation that checks for matches in a line of both account ID and quarter (Q1, Q2, Q3, or Q4) with the other lines in the sheet and comes up with a quarterly average for the variables in question.
What I have
What I need
If I'm understanding your question, you could use AVERAGEIFS to accomplish what you are asking. With excel, a lot of how successful an approach will be is determined by how your data is structured, and if/how often you are planning on updating your work.
It would be easier to give a concrete answer with an example of the data you are looking at.
If your source data is in columns A:D something like:
and you are looking to summarize the weight data in I by account ID and Quarter:
you could use AVERAGEIFS(C:C,A:A,G2,B:B,H2) this would find the cells in column A that match the value in G2, find the cells in column B that match the value in H2, and report the mean value in column C of the matching rows.
An alternative is to use a pivot table, which automates a lot of what you are trying to do. For that approach you would select your data block, and click on Insert>>Insert Pivot Table (at least in my version). That should bring up a wizard. Accepting the defaults will create a new sheet. Then look on the right side of your window, and you should see a list of your column names near the top, and four boxes called Filters, Columns, Rows, and Values. You should be able to drag and drop your columns into these boxes to get summaries of your data. If you add your Account ID and Quarter tabs as columns, and your height and weight as Values, then right click on each of the value columns and select "Value Field Settings" and select Average from the menu that pops up. That should give you something that looks like:
At that point, you can change the formatting to make if fit your needs, or copy data somewhere else.
The AVERAGEIFS approach will automatically update if you add more data, but will only summarize things that match the values you list. If there is an account ID/Quarter pair that isn't in the summary column you won't have any idea it's there. If you are summarizing an ID/Quarter pair that isn't in your data you'll end up with a division by Zero error like in the example.
The Pivot Table option only updates when you manually click refresh (right click and choose refresh pivot table from the menu), but will summarize all the data based on the columns you've selected. It's also a little more robust as you avoid having to type out the formulas and make sure you are pointing to the right column. This option also by default provides nested summaries; you can turn the subtotals and grand totals off if you want.
I used the function:
=SUMPRODUCT(($B$2:$B$13="Customer 1")*($C$2:$C$13="Q1"))
Where Customer 1 could be a user id and Q1 you can change to which quarter you want.
Excel screenshot

Column Name in Pivot table is a day Need to group by month

Good Morning,
New user here; need assistance please. My data is structured with days across a spreadsheet. t1 = 9/30/2016, u1 = 10/1/2016, v1 = 10/2/2016 etc...
The right side of the sheet s1:s711 has structured data which are the specific employee numbers i.e. 5672291. These are unique identifiers and do not repeat.
The data contained between t2:bsa711 represents the amount of sales on a given day for the employee.
I have tried several sumifs and sumproduct functions to capture the amount of sales for each employee by month. This did not work due to the multiple criteria (employees name and <= EOMONTH => EOMONTH criteria to sum the sales within the month)
My last attempt has been to pivot the data and group by month, but I am unable to produce the desired result because I can only get column names (the days) in the pivot list (1000+ due to the T-BSA range of columns/days).
My overall goal is to know the total per month I am not averse to using pivot or some type of array sumifs. Sorry that I do not have much to add to show research. I have been looking.
Thank you in advance.
Make sure the dates are formatted as dates.
Click on analyze -> insert timeline-> select column for dates.
You might want to experience with slicer and pick the days you want which is even more specific.

Resources