I'm having trouble creating a Tableau calculation. For this calculation, I would like to create a new column called "New Sales", where the sales of "Company B" equals the sales of "Company A" (see screenshots below, Initial vs. Target dataset). The sales numbers change over time, so I cannot simply set the value of Company A to "200".
I've tried creating a combination of IF, IIF, and CASE statements, but the values are not matching correctly.
Could anyone please help me with this?
Thank you!
Initial Dataset
Target Dataset (added "New Sales")
Related
I'm trying to subtract a value in one field from a value in another table, depending on ID number using Filemaker Pro 19.x. I thought I'd done this before without any problems but now it isn't working and I don't know why.
First, I want to do this in a calculation field, not in a script. I don't understand scripting at all and use it only when there is no alternative. In this case, I think a calculation field should work.
I have 2 tables, I'll call them "Data" and "Categories"
Both tables have the field "CID" "Category ID".
The CID fields in both tables are linked in the Relationship Editor
The Data table has a field "Product ID"
The Categories table has several fields related to products. Two of those are "MIN PID" and "MAX PID". These are the minimum and maximum product ID numbers.
Product IDs are assigned in ranges. If it is within a certain range, it has to belong to a certain category. These categories have CID numbers.
To assign the CID number to the products listed on the Data table, I did run a script that essentially recreated all the data within the Categories table. It was inefficient (in my eyes) because the data was sitting right there in the table. I couldn't figure out how to reference it, so I gave up and ran the script instead. The other problem is that if the CID ever changes for a product, I have to rerun the script (or someone else, who might not know about the script)
That said, I now have the correct CID assigned for all 62 product categories. What I want to do now is to use the CID MIN and CID MAX values (among others) in calculation fields in the Data table.
For instance, if the product ID is "45,001", it belongs to the Category "16", which has a MIN value of "30,000" and a MAX value of "50,000". I want to subtract the "30,000" from the "45,001", (PID - CID MIN) to return the result "15,001". This allows me to locate a product within the category. Instead of being "Product 45,001", it will be "Product 16.15001".
The calculation I tried is:
If (CID = CID::CID ; PID - CID::CID MIN)
The result is a huge group of records where this field is empty.
I also tried:
PID - CID::CID MIN
Again, no results.
Both tables have the field "CID"
The two CID fields are linked in the relationship editor.
I have tried this with a test file and it works perfectly. It does not work in the database I am working within.
What am I doing wrong?
I have a table that shows the recurrence of purchasing a product, with the columns: product_id, report_date, quantity.
I need to list in a table the products that are more than 50 days unsold. The opposite I managed to do (list those that were sold in the last 50 days) but the opposite logic has not yet been able to implement.
Does anyone have any tips?
An example of the table:
product_id,date,report_date,quantity
329,2019-01-02 08:19:17,2019-01-02 14:34:12,6
243,2019-01-03 09:19:17,2019-01-03 15:34:12,6
238,2019-02-02 08:19:17,2019-03-02 14:34:12,84
170,2019-04-02 08:19:17,2019-04-02 14:34:12,84
238,2019-04-02 08:19:17,2019-04-02 14:34:12,8
238,2019-04-02 08:19:17,2019-04-02 14:34:12,100
238,2019-08-02 08:19:17,2019-08-02 14:34:12,100
238,2019-10-02 08:19:17,2019-10-02 14:34:12,100
170,2020-01-02 08:19:17,2020-01-02 14:34:12,84
170,2020-01-02 08:19:17,2020-01-02 14:34:12,84
There are many steps to do this task. I assume the date column is the one to work with. Your example from table includes duplicated entries. Is it right that at the same time the order is there twice?
So here are the steps:
At first add an calculated field date_past to your dataset:
DATE_DIFF(CURRENT_DATE(),date)
To the dataset add a filter SO_demo with:
include date_past<30
Then blend the data with it self. Use product_id as Join key. Only the 2nd dataset has the SO_demo filter. Add to the dimension of this dataset the calculated field sold_last_30_days with the formula "yes".
In the table/chart to display add a filter on the field include sold_last_30_days is Null.
I am trying to create a simple table in Google Data Studio, which fetches data from MySql table. For example,
"Peter
John
Mike
Peter
George
Peter"
The above are the set of values in a field,
Here I have to count the number of "Peter" in the field and display the count.
Is it possible to display the count of particular values from a single field? If so, what function should I apply to get the required output?
I would suggest using a REGEXP_MATCH function to create a new field. Try this:
Create new field called Peter Count and use this formula:
CASE
WHEN REGEXP_MATCH(FIELD_NAME, "Peter") THEN 1
ELSE 0
END
Make sure the new field has a field type of Number and aggregation of SUM
Create a scorecard in your report and select your new field as the metric.
That should add up the occurrences of Peter and ignore other names.
I'm editing a database template so I can track differences in patient tests across age for the same person.
I retro-fit the "Student Database" template to utilize the forms and macros already created.
I have a patient table that stores all data collected at initial intake : name, date of birth (DOB), etc. and a second table that would track test scores across visits that includes : name, date of visit (DOV) and score information. These are paired so I can pull up information from one patient and see their scores across visits.
What I need to do now is create a query where I can calculate their age when they took the tests.
To do so, I have used expression builder and entered Calculated:([Visit Date]-[DOB])/365
This works for calculating age only if I re-enter the DOB in a new column on the patient visit table
I've tried using DateDiff and using [Patient]![DOB] to recall the data from the other table but I get the same error.
(Calculated age: ([Patient Visit]![Visit Date]-[Patients]![DOB])/365)
Calculated age: (DateDiff("yyyy",[Patients]![DOB],[Patient Visit]![Visit Date]))
Both spit out the error : Enter Parameter Value 'Patients!DOB'
If I enter a date, all data points and patients calculated to have the same DOB that I entered.
How do I let Access know I need it to calculate the date at visit for the DOB of the same patient?
?: Do I need to create a lookup table for the patient ID to match with the DOB and then use that field for calculation?
If there is something wrong with the expression I can fix, that would be ideal. If not, what is the best way to calculate age at visit without having to manually enter in the patient DOB more than once (once in initial uptake and again at each visit).
Thank you in advance.
I found a solution!
I was using 'query' wrong. instead of trying to force it to recognize another table, I needed to add the table to the query upon query creation.
i.e.:
1_ selected 'Query Design'
2_ selected the tables with the required information (entered through forms)
3_ Used `
Patient Name: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name]))
`
for the first field and
Patient Visit.*
for the second field. By adding "Patient Visit.*" the query will add all fields from the table into the query.
The third field I selected DOB from the Patients table (it was available for selection because I had the two tables selected in the layout initially).
I am now able to use the original
Calculated:([Visit Date]-[DOB])/365
for age calculation w/o any error. I finalized formatting under properties > format > fixed.
Wooo!
I'm working on a SSAS cube to allow user to analyze some sales.
So, I created a fact table to record all sales and few dimensions to browse inside data (category / location & store, etc...).
This is a example of the fact table output (from SQL Server Management Studio) :
When I browse my cube, I can review all sales including date, quantity, etc.
However, when I add some fields like the "unit price" or the "unit cost", it returns me a strange result probably due to an aggregate behavior.
It seems it return the sum of all matching rows (aggregateFunction property).
How to simply display the unit price of a sale without apply any calculation to the unit price column. The None value for the AttributeFunction display BLANK/NULL.
If your unitCost and unitPrice are the same for each product (I mean unitCost can be only 77.6 for product_id = 2), you can just use average (or even emulate average by SUM/COUNT) - but only for product dimension on axis!
Another dimensions will show real average values.
Maybe it's better to use this 'static' fields like attribute properties in 'Product' dimension? But you still need to add some logic to choose one value for several (or all) product members selected.