I'm new to tableau.
I have a data like this.
[department]
[employee]
And I want to get employee count under 30 age per department. like this..
[my goal]
I want to show all departments (if there is no employee)
To get result, I do these steps,
make relationship of dept - emp (one datasource)
make datasource filter (emp.age < 30)
make sheet and set row as dept_no, countd(emp_no)
But I could only get like this.
[my result]
How can I get my goal..!!??
Help me!!
It is simple hereafter. Use join (instead of relationship) on the side of dept table and Take dept_no column from dept_table instead of emp_table. To do this follow these steps
double click on first added table (say emp). A join window will open (thgis differs from relationship)
add dept table and use right join
right click age convert to dimension
right click again age and convert to continuous
create filter at most 29 on age and don't forget to check include null values in the table
If you want to add all values in view. create a calc field with calculation as
INT([Age] <30)
add sum of this field to view
edit the calculation to show all nulls as 0
ZN(INT([Age] <30))
Related
So, simple question, I have combo box in my database and I want items that I have selected most frequently to appear first the next time that I add a record.
I would suggest adding a Long Integer field to the table consituting the row source for your combobox, and incrementing the value held by such field either on the AfterUpdate event of the combobox, or following the main operation being performed by your form.
Then, sort the items in the combobox by this new field in descending order.
I assume that your combo box selects a lookup value in for a property (PropertyID) that is saved in a table (MainTable).
You can get the number of times this property has been selected with
SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID
Now get the sorted lookup table by using this query as sub-query:
SELECT L.PropertyID, L.Name
FROM
LookupTable L
( SELECT PropertyID, COUNT(*) AS SelectedTimes
FROM MainTable
GROUP BY PropertyID) X
ON L.PropertyID = X.PropertyID
ORDER BY X.SelectedTimes DESC, L.Name
I'm also sorting by name in case two entries have the same count.
As usage may change over time, you should record the time when an item was selected. Then you can weight the usage, so recent usage of an item have higher weight than those items used, say, a year ago.
Then you can run a query to list the usage having the most recently used items at top:
Select Item, Sum(1 / DateDiff("h", [SelectedTime], Now())) As Usage
From ItemUsage
Group By Item
Order By Sum(1 / DateDiff("h", [SelectedTime], Now())) Desc
Of course, this linear weighting may be too simple. You can apply any math to the usage like square or log.
I have a table that displays 8 columns. Due to the way the data source is structured (I cannot change this) it sometimes means one or more of the columns will be the same across two rows.
I need to filter to show only one row of data. This is based on "email', so if an email has more than 1 row, I want one of the rows. If the other columns are the same or not doesn't matter.
I don't need to combine anything, and I don't care which row is displayed, I just need to remove one of the duplicated rows.
Replace this:
Place orderid email item name date
a 1 a#a.com b c 1/1/11
a 1 a#a.com d c 1/1/11
With this:
Place orderid email item name date
a 1 a#a.com b c 1/1/11
Or this:
Place orderid email item name date
a 1 a#a.com d c 1/1/11
Any help would be much appreciated! I had a go with LOD calculations and I couldn't make that do what I wanted (that may well be me not understanding how to use them properly, though).
Given your example, it appears the difference is within the [item] field. You can create an index calculation on it and filter for value of 1.
index()
Set the index to discrete and compute using the [item] and filter for only 1. You can hide the field if you don't want it to appear by deselecting Show Header.
If you want to show the first row per email, regardless of what's in the other fields, try the following:
Create an [Index] calc field using INDEX().
Add [Index] to rows shelf and change to discrete.
Edit the table calc for [Index], select 'Specific Dimensions' and restarting every email (dropdown menu). All of the checkboxes should be ticked by default.
Notice how the index is not restarting for each email as expected. To correct this, drag email checkbox to the top position.
From here, filter [Index] = 1 and hide index column from view.
I want sum of only unique values in SSRS report.Is there any logic to achieve this.
this is what something like this sum(distinct value)
Thanks
Supposed you have a column named value in your query, you could do the following:
Add an additional column to the query of the dataset:
ROW_NUMBER() OVER (PARTITION BY [value] ORDER BY [value]) AS valueNr
Then, if you already have created a Sum field in the table, change the expression of the textbox to
=Sum(Iif(Fields!valueNr.Value=1, Fields!value.Value, 0))
Repeat this for every "distinct sum" calculation.
Yes. You use groups. At the top click the insert menu, then table, then Table Wizard. Pick your dataset and hit next. Now drag the column for the different types of items you want a distinct sum of into the Row Groups section. Drag your count column into the Values section. This should automatically turn it into Sum(ColumnName). You can click the down arrow to change the aggregate type (if desired). Press next and next and finish. Viola. You have a distinct sum for each specified field.
I have below data
Name Product
XYZ A
XYZ B
XYZ A
MAP Z
MAP Z
I want only those customers that have more than 2 distinct products. So in the above example, we get only XYZ, so the count is 1.
Not sure how to do it.
Thanks,
Hema
If you only want to see the customers without information on the different products, you can drag the Name pill to rows, create a calculated field distinct_products as
COUNTD([Product])
and drag it to filter. Select 'at least' and enter '2'.
If you still want to see the product information you can solve this using Level of Detail expressions in Tableau together with a filter.
Create a new calculated field distinct_products as follows:
{exclude [Product]: COUNTD([Product])}
Drag this to filters and choose attribute. Then select 'At Least' and enter '2' as value. Now the filter is in place. What you then need is to drag the 'Name' pill to rows.
If you want the products to be shown in a single row: drag the Product pill to 'Text'. If you want the products to appear in multiple rows, drag it to rows.
I have a really basic question that I can't figure out. I need to create a table that has multiple calculated fields, but I need only one of the calculated fields to be filtered for a specific dimension value. For example, I have the following data set (dummy data) and I want to create a table that will include total clicks for both companies, but [cost per click] from one company only, company B.
DATA SET
Company| Clicks| $ Cost
------------------------
Comp A | 100 | $20
Comp B | 200 | $40
WHAT I'M LOOKING FOR
CLICKS | COST/CLICK
TOTAL 300 | $0.13
$0.13 comes from 40/300; $40 from company B and 300 clicks from both company A and B.
How do you create a table that has multiple calculations but with one of those calculations filtered on one dimension value only?
One simple calculated field:
sum(if [Company] = 'B' then [Cost] end )/sum([Click])
This should get you in the right direction.
Based on your question and your comment, you want to divide the cost by the TOTAL number of clicks in your dataset.
Create a calculated field called "TotalClicks" and enter this formula
window_sum(sum([Clicks])) // This formula will sum the clicks field for all rows
Create a calculated field called Cost / Clicks and enter this formula
sum([Cost]) / [TotalClicks]
Add the Cost / Clicks field to the sheet and it should look like this
NOTE: If you need to partition / group your report, you may have to play around with this some. I don't use window functions within tableau very often since I usually handle the aggregation at the datasource level instead.
NOTE: Since you mentioned filtering, I will add this statement -- If you filter out any of your data, that data will not (cannot) be included in any calculated fields (To the best of my knowledge and experience, anyway). If you need to include that data (total clicks), I think the only option is to add that aggregated total to your dataset - otherwise, tableau can't calculate it if you are filtering it out.
Edit2: If you cannot change the underlying dataset, you could accomplish this by creating another datasource and joining it to your inital data source --
Data > Add Datasource, add the datasource again and change the name so you can identify it
Click Data > Edit Relationships. Click Custom and REMOVE any linked fields -- this will essentially produce a Cartesian join (every record in your first DataSource will have every reocrd from your second Datasource)
Select the second datasource and create a calculated field (ClicksTotal_DS2) using the same window_sum function
Select the first datasource and create a calculated field (named Cost / Clicks_DS2) using this formula
sum([Cost])/ [Sheet1 (test) (2)].[ClicksTotal_DS2]
Now you can apply a filter to your first data source, and your second data source will still calculate the total.