Check the existence of association combinations from a table - tsql

Folks, I am looking for the best way to retrieve following information.
I got a table with products and options assigned to them. Then I got a list of option combinations and wanting to know the existence of products for my combinations.
product to option table
p1 - option1
p1 - option2
p1 - option3
p2 - option2
p2 - option3
p3 - option3
p3 - option4
My option combinations are [option1,option2], [option1,option4], [option2,option4] and [option3,option4]
My expected result is [option1,option2] and [option3,option4]
-The selection is based on, there should be at least one product associated with all the options in a combination. Here [option1, option2] is associated to p1 and [option3,option4] associated to p3. If the combination is distributed among multiple products then that combination will not be selected. Also there could be n number of options in a combination.
Thanks in advance!

Related

Count of group dimensions item in Tableau

I'm fairly new to tableau and I'm having the following issue. Below is a sample of the data I'm using.
Customer No | Item
___________________
1 A
1 B
2 A
3 A
4 A
4 B
5 B
6 A
I'm trying to get a count of how many customers bought Item A and B. So far I tried doing a separate group by combining A and B but I get the total result of 8. I also tried doing a calculation and I'm getting the same result of 8. Can someone please point me to the right direction on how to get this result. Thanks!
This is the result I'm trying to get:
Item| Count
A 5
B 3
A and B 2
I recreated your exact dataset and pasted it into Tableau so you could see a couple of examples.
Here's how you can see the number of customers who purchased an individual item, plus the number of customers who purchased both items.
Your calculation will be:
IF { FIXED [Customer No]: COUNTD([Item]) } = 1 THEN
[Item]
ELSE
'Both A and B'
END
And you'll need to set your view up to look like this:
Below are ways you can see when both items were purchased.
Boolean OR
The calculation you'll want to use is:
ATTR([ITEM]) = 'A' OR ATTR([ITEM]) = 'B'
And you'll want to set up your view to look like this:
A, B or Both
If you would like a bit more specificity in your result, you might try:
IF ATTR([Item]) = 'A' THEN
'A'
ELSEIF ATTR([Item]) = 'B' THEN
'B'
ELSE
'BOTH'
END
Replacing the previous calculation with the new looks like this:
More than 1 item
If the specific items purchased don't matter, you could use this logic.
COUNTD([Item]) > 1
Replacing the previous calculation with this one would look like:
More than 1 Item using a window function (probably overkill)
The calculation you'll need to use is:
WINDOW_COUNT(COUNTD([Item]))
Because this is a Window function, we'll need to specify how it's calculated across our dimensions. To do this click the down arrow on the right-hand side of the pill and select Edit Table Calculation...
You'll then need to set these settings:
I'll add the calculation we created in the first example ([A and B]) to the filter shelf and select True. That should give you something that looks like:
More than 1 item using a Level of Detail expression
The calculation for this example is:
{ EXCLUDE [Item]: COUNTD([Item]) }
You'll view should look like:
As you can see Tableau is quite flexible. Hope these examples were helpful!
You might want to use Tableau’s set feature to approach problems like this.
For example, right click on the field [Customer No] in the data pane (i.e. left sidebar) and choose the “Create Set” command. Click “Use All” at the top of the set panel and then click the Condition tab. Define the set using the condition MAX([Item] = “A”). Name the set “Customers who bought A”.
Similarly, create a set of customers who bought item B. You can then select both sets in the data pane, and create a combined set to be the intersection, that is, customers who bought both an item A and an item B.
You can think of a set as either a mathematical set of the members of a field that belong to the set (i.e. a set of customer ids) or as Boolean function defined for each data record in the data source indicating whether that data record is associated with the set (i.e. a Boolean function that operates on transactions to say whether the associated customer ID is in the set. A key to keep in mind for the condition formulas used here is that the condition is an aggregate formula, operating on a block of data records for a customer ID to determine whether the customer ID is in the set.
Once you have defined your sets of interest, you can use them in many ways - in calculated fields, as filters, as dimensions on shelves in a visualization, in set actions, to combine with other sets ...
To define a measure that counts the customers in a set, create a calculated field such as “[Num A Customers]” as COUNTD(if [Customers who bought A] then [Customer ID] end) Do the same for whatever other sets you are interested in. Then you can use those measures (probably with Measure Names and Measure Values) to make your viz.

Is it possible to create a calculation field between two datasets in Tableau

I have two datasets. One consists of shipments and the other for demands.
I would like to have the difference between the shipment quantity that is sent to particular countries and the demand for these particular counties. and then subtract the sum of the demands for particular countries.
The two datasets don't have a common key. So I am wondering if it is possible to do that via a calculation field.
Thank you
You said it yourself - if there is no common key, how would you tell it to join the tables together?
You could create a "key" by creating two tables and aggregate them to country-level and use the country as a key. An easy way to join the two datasets could be to:
1) Create a worksheet and aggregate 'Shipment quantity' to country level
2) Mark everything and copy paste (Ctrl + C, Ctrl + V)
3) Tableau will now insert the newly created dataset on a new worksheet.
4) Do step 1-3 again with 'Demand' instead
5) In Data-sources you can now link these two together with 'Country' as a key.

Tableau - Filter has one value always selected

I need to create a dashboard in which there is one chart with bars for different Product Types. I am using this chart as a filter. I want one value of Product Type as always selected while I can select/deselect other product types.
For Example I have 4 product Types - A,B,C,D. I want A to be always selected while I can select one of B, C or D to filter other charts based on this selection.
I can have the product type A hidden from the chart too.
I hope if you follow the steps given in below answer then you should be able to solve your issue.
Hide value in filter - Tableau
The only change which you would require is in the definition of calculated field:
IF [parm_field] == 'All' THEN 'Y'
ELSE
IF (([parm_field]=[dim_field]) or ([dim_field]=='0')) THEN 'Y' //in your case just replace '0' by 'A'
ELSE 'N'
END
END
Kindly don't forget to let us know if it solves your problem :)

Tableau context parameter

I have 3 dimensions in the following hierarchy:
BigC
L SmallC
L Brand
(Having 200 combinations)
I am also creating a calculation using a parameter and multiple case statements.
For eg: CASE WHEN parameter=Brand1 THEN Brand1_field - Impact% END
Now I want my parameter to have only the relevant brand values populated for Big C and Small C rather than all the values. Is it possible?
If this is not possible then can I create a calculated field with a column selection?
If i have understood your question properly, I was able to achieve this using Context filter and Filter by Relevant Values.
Drop both Big Company and Small Company dimensions into Filter Card.
Apply Context Filter for Big Company and "Use only relevant values" for Small Company filter.
So as when you select values for Big Company only the related values of small company will be displayed and so the brands.
Find the workbook here : https://www.dropbox.com/s/txam3wfhz8qirqg/StackOverflowSolution.twbx?dl=0

ATG - Can an Order Level Discount be applied to Items?

Consider I have two items in my cart 50 USD each , I also have a coupon '20 USD off 100'. when I apply this my cart will look like below (for simplicity and focus I am eliminating tax and shipping)
Item 1 50 X1 = 50
Item 2 50 X1 = 50
subtotal =100
discount (-)20
**Total 80
now I have multiple cases where I have to split this 20 USD to items so that returns at third party are easy , also in situations where the two items will be fulfilled by two independent vendors.
I understand that ATG's ReturnManager class provide wealth of methods to calculate returns and does consider all item shipping order discounts and taxes.
but is there a way I can split the order discount to items Out of the Box based on weighted average algorithm.
Thanks
The simplest way to do this would be, to do the splitting algorithm in a Order Pipeline Processor (custom processor) store the split Item Level Discount Shares in a ApportionmentInfo repository item. Whenever, a return occurs you need to access this repository item through the order and display it to the user.
Regards,
Gaurav E
You Can't
Basically OrderPricingEngine will set adjusment against OrderPriceInfo. you cant do apportionment that to item level because the trigger is on order.
Best practice is expose a reprice Order as service to thirdparty. Re run the calculation
and identify the return value. If you customize per promotion level it will open up pandora box of reprice order issue.