I have two dimensions (Case Numbers, Test Code) and I want to count only the Case Numbers which have both test codes i.e. 4802 & 9050.
I created a data similar to yours
Create this calculated field
{FIXED [CaseNumber]: sum(
IF [TestCode] = '4802' OR [TestCode] = '9050' THEN 1 ELSE 0 END)} = 2
TRUE in above calculated field will return only desired CaseNumbers. Check
OR
OR
Related
I am attempting to create a parameter that allows me to custom filter for Sales, Units, Profit, Orders, Returns, and Return Units. I'm running into an issue when creating the calculated field that calculates return $ and return units. The result I am getting doesn't seem to be accurate.
I have created a Parameter with the above list called [Choose KPI].
I thought I would be able to create calculated fields for [Returned $] and [Returned Units]:
IF [Returned] = 'Yes' THEN [Sales] END
and
IF [Returned] = 'Yes' THEN [Quantity] END
Which would make my calculated field for [Choose KPI]:
CASE [Parameters].[Choose KPI]
WHEN "Sales" THEN SUM([Sales])
WHEN "Units" THEN SUM([Quantity])
WHEN "Profit" THEN SUM([Profit])
WHEN "Orders" THEN COUNT([Order ID])
WHEN "Returns" THEN SUM([Returns $])
WHEN "Return Units" THEN SUM([Returned Units])
END
Rather than returns being associated with product ID, they appear to be linked only with the order ID, which creates duplicate values when there were multiple items on an order (are we assuming all items in the order were returned when [Returned] = 'Yes'?), causing the sum of [Returns $] to be inflated.
How can I create a filter that uses the distinct Order ID to calculate total returns and returned units?
In Tableau, you can use the "Group" option in the "Analysis" menu to create a new field that groups your data by the "Order ID" field. Then, you can use the "COUNTD" function to count the number of unique "Order ID" values, which will give you the total number of returned orders.
To calculate the total returned units, you can create a calculated field that multiplies the quantity of each returned item by the number of unique items returned per order. You can use the COUNTD([Order ID]) and SUM(IF [Returned] = 'Yes' THEN [Quantity] END) in the calculation.
In the [Choose KPI] field, you can use the following calculation:
CASE [Parameters].[Choose KPI]
WHEN "Sales" THEN SUM([Sales])
WHEN "Units" THEN SUM([Quantity])
WHEN "Profit" THEN SUM([Profit])
WHEN "Orders" THEN COUNTD([Order ID])
WHEN "Returns" THEN SUM(IF [Returned] = 'Yes' THEN [Sales] END)
WHEN "Return Units" THEN SUM(IF [Returned] = 'Yes' THEN [Quantity] END) * COUNTD([Order ID])
END
This way, you will be able to filter your data based on the different KPIs you've defined, and the calculations for returned sales and units will be based on the distinct Order ID values.
(Answer by https://chat.openai.com/chat and formatted by me.)
I Need to get the Unique value of Max([Date]).
I have this calculation for max date:
{ FIXED [City] : Max([Date]) }
Count :
IF[Max Date (Last Street)]= [Date]
THEN [Count Record]
Else 0
END
For Example:
City Date Street I get (Count) I Want (Count)
Miami 01/01/2019 1st 0 0
Miami 01/02/2019 2nd 0 0
Miami 01/03/2019 3rd 1 0
Miami 01/03/2019 4th 1 1
This would be a good situation to mix LOD calculations and Table Calculations. Your initial LOD function looks good, as it will find the complete max date per each city. From there, you can apply the concept of the calculated field you already have started and add a Table Calculation (Last()):
IF ATTR([Max Date (Last Street)]) = ATTR([Date])
AND LAST() == 0
THEN [Count Record]
Else 0
END
Note that the other portions of the calculated field are wrapped in ATTR() to make them into aggregations.
Once you add additional cities back into the data, you'll have to edit the table calculation by Right clicking on table calculation on view > Edit Table Calculation...
Take note of the fact that Specific Dimensions is selected and Restarting Every is changed to "City"
Final product should look like this:
Alternative Method:
If you'd like to purely use LODs and your street names always contain unique ascending numbers:
If Date = {Fixed [City]: MAX(Date)}
AND REGEXP_EXTRACT([Street],'(\d+)') = {FIXED [City], [Date]:
MAX(REGEXP_EXTRACT([Street],'(\d+)'))}
Then 1
Else 0
END
The above will essentially extract the number from the street then add it as a condition in addition to the MAX(Date) which already exists. Then the you will only get a 1 when both conditions have been met.
The end result will be the same as above.
I am looking for difference of two columns in Tableau. I have the formula with me.
IF ATTR([Valuation Profile]) = "Base" THEN
LOOKUP(ZN(SUM([Value])), 1) > - ZN(LOOKUP(SUM([Value]),0)) END
But I get it as a separate column in the columns sections. How do I get that in the rows section? Basically how to get the difference as a dimension?
Please see attached images of what I want and what I have. Apparently, I cannot upload my excel sheet and tableau worksheet here. So I have upload just the screenshots.
What I have - vs - What I want
Tableau Workbook
First off, there is no way that you can generate additional rows for your data in Tableau!
In your case however you could use a workaround and do the following:
Create a calculated field for BASE and one for CSA. The formula should
be IF [Valuation Profile] = 'BASE' THEN [Value] END and IF
[Valuation Profile] = 'CSA' THEN [Value] END respectively
Afterwards you can drag Measure Names onto your rows shelf and
replace the SUM([Value]) with your two newly created calculated fields
that should give you all three measures in different rows in your table
Reference: https://community.tableau.com/message/627171#627171
Use LOD expression to calculate the individual values first.
Create calculated fields 'BASE', 'CSA' and 'CSA-BASE' as below.
BASE:
{FIXED [Book Name]: SUM( if [Valuation Profile] = 'BASE' then Value else 0 end ) }
CSA:
{FIXED [Book Name]: SUM( if [Valuation Profile] = 'CSA' then Value else 0 end ) }
CSA-BASE
[CSA]-[BASE]
Solution
My goal here is to count the # of True, False and NULL per day using my boolean calculation. Next step would be to calculate the percentage of each T, F, N with overall day.
Below is the visualization I would like to achieve but instead of blue dots, I would need the count of them in number.
Initially, I tried
IF [boolean] THEN 1 ELSE 0 END
But only changing from True to 1, False to 0 and missing the NULL - not counting:
I also tried different Calculated Fields to get the count of it but always getting the same error:
SUM(IF [Field]=TRUE then 1 else 0 end)
COUNT(IF [Field]=TRUE then [ID] end)
ERROR:
Could someone please assist me with a Calculate Field or any other solution where I could get a count of T, F, and NULL that would also assist me with the percentage?
Thank you
You're working too hard.
Just put SUM(Number of Records) on one shelf with DAY(Disconnected ...) on another, with the Boolean field that classifies data rows as > 0 or not on some other shelf, such as Color. No need for a table calc.
Here is an image of a solution posted at https://community.tableau.com/message/601862#601862
How to convert negative values to zero in a calculated column?
we have inner join of multiple tables where a column is a calculated column taken from tables,i need to convert negative values present in the column to zero, how can i do?
what was tried..
i tried with 'case' condition but its not working.
part of code where i intend to change is similar to like this
(isnull((select isnull(sum(AVAILPHYSICAL),0) from ax.inventsum
where ITEMID = ax.INVENTTABLE.ITEMID ))-
(select isnull(sum(QTY*-1),0) from ax.RETAILTRANSACTIONSALESTRANS RTST inner join ax.RETAILTRANSACTIONTABLE RTT
on RTT.TRANSACTIONID = RTST.TRANSACTIONID
where ITEMID=ax.INVENTTABLE.ITEMID and (RTT.ENTRYSTATUS = 0 OR RTT.ENTRYSTATUS = 2) and
(RTST.TRANSACTIONSTATUS = 0 or
RTST.TRANSACTIONSTATUS = 2 ) and
As Quantity,