I have data with sales, details including gender, location, date, etc. There's one row for each sale, so the total number of sales is a count of the rows.
customerid sale_date regionid studentid sex
18761372 01/09/2016 AFB07458 C2F815C6 1
18761372 01/09/2016 AFB07459 206AA234 0
07189635 01/09/2016 AFB07460 F218C8F1 1
07189635 01/09/2016 AFB07461 F021CD27 0
07189635 01/09/2016 AFB07462 E6145555 1
I'm trying to produce a line graph that shows number of sales by month, split by male and female. However male sales are ~5million for the year, and female are ~13 million. So it's hard to compare whether there's any difference in how the sales vary by month (i.e. whether males are proportionately more likely to buy in september).
I manage to get this to work by creating the following calculated field:
If [sex] = 0
THEN 1/5000000
ELSE 1/13000000
END
This does what I need, but it's not a great solution as it involves me manually checking what each total is and writing it down (admittedly not much of an issue with sex, but if I'm doing it on something with multiple fields then it would become very time consuming.
Is there a way of doing this more elegantly? I tried to use sums and case statements in there but I got "cannot mix aggregate and non-aggregate arguments".
I would approach this with a calculated field that shows a percent of total, by month.
Right click on your pill, select 'Quick Table Calculation' and choose 'Percent of Total'.
That way, instead of looking at a count of orders where one group always appears greater, you are looking at their share which will be more uniform.
Maybe I'm understanding this wrong but it seems fairly straight forward. Using the sample data provided I just:
Add the date field pill "sale date" to the column shelf(set it to pull back the month)
Drag the "number of records" to the rows shelf(automatically sum the results)
In the "Show Me" section in the top right select line chart.
Drag the sex pill onto the color card, this will break the line into to two, one for male the other for female(you may have to convert the sex pill to a dimension, to do this right click the pill and select "convert to dimension")
Let me know if this solves it for you?
Related
What I am trying to achieve is to get a count of people employed in a particular period.
I have 3 variables:
Employee ID (integer)
Hire date (date)
Termination date (date or null)
Example
the formula I am looking for is something like
if termination_date is null
then
count employee_ID in
dates between Hire_date and max of either hire_date or termination_date
else
count employee ID in
dates between hire_date and termination_date
This aims to show the dynamic of staff level over the time.
I am new to Tableau, not sure how to even start with it. Any suggestions welcome.
This problem will be simpler if you reshape your data to have the following three columns
Employee ID
Date
Action. (where action takes on the values of ‘Hire’ or ‘Terminate’).
Each data row represents one change in status for an employees. If an employee had a termination date, they will have two records in this new format, otherwise just one record showing the hiring date.
You can reshape your data by hand, or leave the original and use Tableau Prep or the Tableau data source page to reshape using a self Union and a few simple calculated fields.
Define a calculated field called Staffing_Change as
if Action=‘Hire’ then 1 else -1 end
Now you can plot the change in staff level over time by putting exact date on columns and sum(Staffing_Change) on Rows. You can use a quick Table calc, Running Sum, to see the net staffing level. For line mark types, I’d use a step style by pressing on the path button on the Marks card. Otherwise, the chart can give the impression of fractional number of employees.
I have date-wise data of a month in Tableau and I want to know total sales of the month. Can anyone show how to do it?
Here is the snapshot of the issue:
First of all, I would advise you to go to the "Data Source" Panel on the bottom left and change the data type of the dimension "Date" to date instead of string. If this is not possible, please speak with your datasource admin. It might be a problem, that the dates are in different formats (like "1.07.06" and "1.11.2016").
After that you can simply choose the discrete MONTH(Date) dimension by rightklicking (blue pills). If you display data ranging over different years it is advised to keep the "YEAR(Date)" blue pill.
In the sample data it looks like this:
Steps to get total sales month wise
Drag your date into column shelf and change by Right click on date and change into month.
Drag sales into row shelf and Right click on measure and go into sum.so you will get total sales per month.
I've got some data that I'd like to display both the averages and the count for.
For instance, there are 50 People taking a survey. Their names are saved in a Dimension "Raters". They are taste testing several products. These products are saved in a Dimension "Products"
They answer 4 questions. Taste, Texture, Appearance, Uniqueness, all saved in Dimension "Question"
The actual ratings are saved in "Ratings". This is a measure.
I can very easily make a table with Raters on the Rows, Question on the Columns, AVG(Ratings) in the text.
This shows me the average score for each question the rater answered.
It looks like this:
Rater-----Taste-----Texture-----Appearance-----Uniqueness
Joe---------2.2---------4.3--------------3.7-----------------2.4
Bob--------3.0----------1.2-------------3.4-----------------4.4
Sally-------4.5----------3.3-------------4.5-----------------3.2
Jessica---5.0----------3.0-------------2.0-----------------1.0
So far, so good.
Jessica's results look suspiciously integerish. When I look at the background data, I see that she only answered for 1 product.
I'd like to be able to add a column to the right of uniqueness which is the count of all product responses for that person.
I've played with this quite a bit, and I'm not sure that it is possible. Maybe with LOD?
I'd also like to filter the table, so that only "tough" raters are shown. Criteria for this is: Their average response for at least two criteria should be below 3.0. That would include Joe and Jessica.
When I try to do counts based on averages, I run into the "cannot aggregate an aggregate rule".
Is there a way around this? It would be trivial to do in excel with another column, a countif, and a filter.
Thanks,
Chris
Part 1:
You should be able to create a calculated field(Analysis->Calculated Field) and name it something like "Number of Records". In the query box just set it to 1 and select "Okay".
This new field will be selectable in the measures. Drag it into your table in the columns area and it should add a count next to your averages.
Part2:
In your measure values box you should be able to right click you measures. This will bring up a list of options including "Filter". Select this option.
On the SUM(Number of Records) set it to "At Least" = 2. Then right click on the AVG(Ratings) measure and set it to "At Most" = 3
Put Products on the Rows shelf.
Then right click on that Products field on the Rows shelf and change ITT from a dimension to a measure. Be sure to choose Count Distinct for the aggregation.
Finally, right click on the field again and change it from continuous to discrete.
This shows how many different products each person reviewed, no matter how many characteristics they rated. If you want the number of ratings, use count instead of count distinct. Or just Sum(number of records), again set to discrete
I'm working with a cube that needs a new calculated measure and I'm having a difficult time getting the MDX right.
The scenario that I'm looking to measure is a count of days where for a given Customer (by Customer Name) and Delivery Route (also on the Customer Dimension) the total sales amount is greater than 0.
The date hierarchy is fairly straightforward.
Date > Year > Month > Day
In the customer dimension, we are not going to be using a hierarchy.
customer name
delivery route
On the measures, we only really care about total sales
total sales
So, I've tried a little bit of everything, but I'm not sure I'm approaching the problem in the right way and that could be that I'm less familiar with MDX.
Here's a sample of data and what my end goal would be.
What I've tried to get there has been the following (however, nothing has provided what I need).
WITH MEMBER [Measures].[count deliveries]
AS
COUNT(FILTER(DESCENDANTS([Date].[Calendar].[Year].&[2013],2), [Measures].[total sales] > 0) )
SELECT NON EMPTY {[Measures].[total sales]
, [Measures].[count deliveries]} ON 0
, NON EMPTY ([Customer].[Customer Name]
, {DESCENDANTS([Date].[Calendar].&[2013],2)}) ON 1
FROM [Sales]
THE END GOAL
I would like to have this added as a calculated member to the cube and not just in query format. Any help would be appreciated!
I am a beginner in iReport and I cant program Java so I hope you can give me an idea.
I've already managed to make a chart that displays how often all customers have ordered in february, march,... etc.
Thats how I did it:
In category expression I have: $F{Month}
In value expression I have : $F{count(Orders)}
But I want to display how often only one customer (for example customer a) has ordered in february, march,... etc.
I have the following values which i can use:
Month, Orders and Customers(here are all customer names saved)
-------//-----------UPDATE--------------//-----------------------------------
I want to display a chart which represents the total orders per month of a customer. But iam trying to display my 3 customers (my database has only 3) in only one chart (stacked).
For example(see picture above): I want to display the total orders from Customer A (yellow) in february. And I want to display the total orders from Customer B (blue) in february and the same for customer C.
The customers should be displayed stacked (3 in every month) and every customer should have a different color plus the total orders from every customer should be displayed ...like in picture above for example:
customer A(yellow) made 3 total orders in february, Customer B(blue) made 2 total orders in february, customer C..etc.
it is very important that every month displays 3 customers...stacked.
How do I do this?
I appreciate every idea.
From what I have understood from your question, you want to show a chart which represents the total orders per month of a customer.
You need not use stacked bar graph for this purpose.
You may want to use bar graph which would serve your purpose.
If you want to see the chart per customer, create one parameter $P{customer} and pass it into your query.
Refer document iReport-Ultimate-Guide-3 on how to create parameters and to use it in queries.
e.g:
select customer,month,count(orders)
from <your table>
where customer=$P{customer}
group by month
The above approach would work if you want to see the details for only one customer.
**Here is my solution after your update.**
From your update, it seems like you want to represent the total orders per month for all the customers.And you want to use stacked chart for the same.
Then what you have done is correct but have missed to add a field to your 'Series Expression'
Add your field customer to your series expression and this will resolve your problem i.e,
Series Expression : $F{customer}
Category expression : $F{Month}
Value expression : $F{count(Orders)}
This will display the chart in the format you have specified.
Create a paramter that takes your customer name $P{customerName}
and another takes month $P{month}
pass these two paramters to your sql like that
SELECT customer_name, order_count FROM customers
bla.. bla..
WHERE customer_name=$P{customerName} and month=$P{month}
then create a chart with only one serie to show one customer as one color. Not like yours with 3 colors.
Fell free to ask for more specific detail.