Tableau report that aggregates the same row into multiple groups - tableau-api

A vendor has many products in various product categories. A new customer might buy items from one or multiple categories. The data rows represent one order/item combination, such that if three items are bought in an order, there will be three rows in the data set. When trying to answer the question of the average sales total by order category, I want to include each order total in every applicable category. For example, if this is what happened:
Customer #1: Bought $20 in category A and $40 in category B.
Customer #2: Bought $40 in category B.
Customer #3: Bought $40 in category A and $30 in category C.
The data will show:
Row 1: Customer #1 bought $20 in category A.
Row 2: Customer #1 bought $40 in category B.
Row 3: Customer #2 bought $40 in category B.
Row 4: Customer #3 bought $40 in category A.
Row 5: Customer #3 bought $30 in category C.
My report should show:
Category A: Two customers, $130 total (**Not $60**). Average sale per order = $65.
Category B: Two customers, $100 total. Average sale per order = $50.
Category C: One customer, $70 total. Average sale per order = $70.
Each order should get counted in its entirety in every applicable category. This means that a given row of data will get aggregated into multiple category groups. How can I do this in Tableau?

Sounds like a case for a Level of Detail calc! Fix to the Category...
{FIXED [Category] : SUM([Sales])/COUNT([Orders]) }
Be sure to check for division by zero.
UPDATE
In light of the new detail specifying that the data set is item level, not order level, you can count the distinct order numbers instead of counting the number of records.
{FIXED [Category] : SUM([Sales])/COUNTD([Order Number]) }

Related

Is there a better way to design an E-commerce products database when the products can have multiple price lines?

I'm trying to develop a new products database for a client and I am having a hard time finding a solution to handle the many different prices a product can have.
Variables that can affect the price of a product:
region (where the customer lives).
customer type (whether they're a new customer or a registered customer).
order type (whether you want to purchase the item once or subscribe monthly).
store type (there were many store types, but now they're transitioning to one, but I don't know if they will add more in the future again so I want this to be flexible
Product Table
id
product_name
sku
description
1
Vanilla Protein Powder
1111
This is a description...
Attributes Table
id
associate_type
region
store
currency_code
order_type
1
2
1
11
usd
1
2
2
1
11
usd
2
Product Attributes Table
id
price
product_id
attribute_id
1
49.95
1
1
2
29.95
1
2
I was initially thinking this would be a good route to go, but the issue that arises is on the product page I want to display the price of the product if you want to purchase it once and the price if you wanted to subscribe. The same issue would happen if I also wanted to show a list of product cards on a product category page displaying both prices.
The issue I run into
When I write a query to get the correct products with the correct price lines, I would filter all the products by the variables mentioned above, but I will always want the subscription price and the one-time price, so in the query, I would have to include WHERE order_type = 1 AND order_type = 2 but doing this would return duplicate records of the product/ products because of the different prices for a one-time purchase and a subscription purchase.
Is there a better way to set up the tables I have so that the query would not return duplicate records of the product/ products? Or is there a way to write the query to handle this for me? Or do I even need to switch up my database design altogether?

Data studio calculated fields

I have the following dataset:
Week #
Company Name
Product
# of transactions
Week1
Company A
Product 1
100
Week1
Company B
Product 1
30
Week1
Company A
Product 2
100
Week2
Company B
Product 2
50
My goal is:
for each COMPANY (there could be multiple rows per company) calculate Usage score with the following formula total # of transactions per company/100. For example, from the table above Company A has 200 transactions and Usage score=2 - I've done it successfully
categorize each company per the following formula: when usage score>1 then "promoter" else "critic" - I've done it successfully
Count promoters and critics - that's where I fail. Data studio in this case calculates Usage score and NPS per row, not per company. Therefore, I have promoters per product, not per company.
please help, I'd appreciate
You can solve this by Re-aggregating the Datasource with itself where the Second Join is the Datasource itself with the Key Company Name and the Metric Usage score make sure to set its Aggregation to Average.
Now you have a new Datasource with each Company and Row having its Usage Score in one column.
Unfortunately I don't understand the NPM part.
Hope this help though

How to Display the Sales and Other Department Sales Seperatly on Tally

hope you all are good .I new to tally and I have a new situation ,I have provided the details below
1.we Own a supermarket and which contains some other departments as well
2.only one counter is available for this supermarket section
3.so the sales of other departments also get mixed with the total sale
Task :- when I enter this data into tally I have to show the other departments sales seperatly on balance sheet, how to achieve this
The Profit & Loss statement in Tally shows you the sales data of every Sales ledger separately. So, to have data on separate sales for separate departments, you will have to make different sales ledgers for different departments and make the entries accordingly.
If you are using combined single ledger for all sales, then you should make three ledgers now for sales of each of the three departments. If you are using sales ledger item wise or tax slab wise, then you need to create similar ledgers for every department and take care of choosing the right ledger when creating the voucher.

How To EXPRESSION with WHERE " count Orders WHERE customer = Mr. Smith "?

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.

In an SSRS report, dividing the sum of one child group by the sum of another child group in a different parent group

I have a financial statement. It has detail lines divided into the groups for Sales, Cost of Goods sold, Operating Expenses, and Other Expenses.
Sales and Cost Of Goods Sold are in the parent Group "IF"
Operating Expenses are in the parent group "E".
I want to divide the total of Operating Expenses by the total of Sales. Is that possible?
I've been struggling with this for a couple weeks. I was able to get the gross profit as a % of sales with this formula:
= iif(Fields!SectionName.Value = "IF" and
Fields!Account_Type.Value = "I",
(ReportItems!txtGP12.Value/Fields!Month12_Net.Value),"0").
You can use in-built aggregate functions and declare a scope for which the aggregate should be performed. In your case you wish to SUM() sales, and SUM() operating expenses, in the scope of the parent groups you have.
Example
For this example we will assume sales is in a field called Sales in the data set.
Operating expenses is in a field called Expenses in the data set.
Assume the same parent group names as you have described: IF and E
The formula would be:
Sum(Fields!ExampleField.Value, "E") / Sum(Fields!ExampleField.Value, "IF")