Preserve the records without value for measure in report - ssas-tabular

Aim: User wants to see all Auto's irrespective of Premium.
I created a tabular model for Auto Policies. Where an DimAuto is associated with FactPremium. However, there are cases in which an AutoItem Doesn't have a premium associated with it(the key for such AutoItems in FactPremium is 0 so that it can join to dimAuto). When browsing on excel I am not able to see the AutoItems that doesnt have premium associated with it in the Pivot Table.
I would like to know if there is any way to display every auto Items ?

In Excel, you can set this property in the PivotTable settings (Rows > Field Settings):
In PowerBI, this option is also available:
As alternative, you can adjust the measure, by adding 0 (zero)...
Sales plus 0 = SUM(Sales[Sales]) + 0
...or correct for blank values:
Sales if blank =
VAR Amount = SUM(Sales[Sales])
RETURN
IF (ISBLANK(Amount);0;Amount)

Related

Tableau Calculated Field to Display Specific Rows

I'm trying to find a way to display only certain rows of my data based off a very specific criteria. I will try to explain it the best way I can. Let's start with a screenshot here:
Picture of part of the Tableau sheet as-is
What I'm trying to do is create a way to display only the values of "Order: Sales Order #" that have a value filled in for "Item: Connected Product Category". As you see on the screenshot, order number 15589543 has one Connected Product Category that displays "Connectable".
Since this order number does not only have null field for the Connect Product Category, I would like ALL of the rows (even the blank ones) be displayed for order # 15589543. If an order # has NO rows that have "connectable" displayed in them (orders 10305573, 15573299, 15699578, etc.) I would like these orders to be filtered out.
This is a screenshot of just a small part of the data. Basically, if an order has a "connectable" field in it, I need all of the rows for that order # to be displayed.
I tried to do logic such as IF [Item: Connected Product Category] = "Connectable" THEN [Order: Sales Order #] ELSE NULL END but this only displays the rows that literally contain "connectable" in them, not all of the rows for that order number.
Any assistance would be greatly appreciated. After extensive research I'm not sure if this is even possible. Thanks
It is simple. Create a calculated field desired filter as
{FIXED [Order: Sales Order #] : SUM(
IF [Item: Connected Product Category] = 'Connectable' THEN 1 ELSE 0 END
)} > 0
This calculated field will evalaute as TRUE/FALSE and setting filter on this field for TRUE will filter records as desired.
Try this. Good luck

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.

Top 10 and items upon user's demand

fellow Tableau Developer,
Take the super store database for example, it is easy to draw a histogram displaying the sales amount of each customer and to only display the Top 10 customers.
It is also easy to build a multiple dropdown filter to let the user to specify some customers at the user's will.
But, is it possible to combine the two of them, namely, to display Top 10 customers and in the same graph display a few other customers (possibly not in the Top 10) on the user's demand?
Here is a straight forward solution that works with Tableau Desktop, but not as useful currently on Tableau Server. The viz still works on Server, but you can can't alter the list of specific users on Server.
Here's the approach.
Create a set to represent your Top 10 customers -- a computed set. (right click on the [Customer Name] field, and Create Set)
Create a second set to represent your specific list of customers of interest -- a static set (select [Customer Name] and Create Set)
Create a combined set to be the union of both sets and place it on the filter shelf. (select both sets, right click and create a combined set)
Use your combined set on the filter shelf, row shelf, in calculations, as desired.
A desktop user can edit the Interesting Customers set. Sure wish there was a control similar to "show filter" for editing set members.
If you'd like this feature more flexible in Desktop, and even available on Tableau Server, upvote the following idea
https://community.tableau.com/ideas/5193

Show calculated measure in row?

I'm using Tableau Desktop 9.0 on OSX. I have data (loaded from a local CSV file) that looks like this:
code,org,items
0212000AA,142,10
0212000AA,143,15
0313000AA,142,90
0314000AA,143,85
I want a chart that shows the number of items beginning with 0212 as a percentage of all items, for each organisation. (I mean as a percentage of the organisation's items - for example, in the above, I would like to show 0.1 (10/(10+90)) for organisation 142.)
I have been able to get part way there, by adding org to Columns, and SUM(items) to Rows. Then by adding a Wildcard filter on code, for starts with 0212.
This shows me the number of items starting with 0212, by organisation.
But what I don't know how to do is show this divided by the value of all items for the organisation.
Is this possible in Tableau, or do I need to pre-calculate it before loading my data source?
One way is to define a calculated field called matches_code_prefix as:
left(code, 4) = "0212"
You can also define a parameter called, say, code_prefix to avoid hard coding the prefix string:
left(code, 4) = code_prefix
And then show the parameter control for code_prefix to allow the user to interact with it.
If you use this new field as a dimension to separate SUM(items) according to those that match the prefix and those that don't, you can then use a quick table calculation to get the percent of total.
For example, you can place org on the Rows shelf and matches_code_prefix on the Columns shelf, and SUM(items) on the Text shelf to make a table. Then under the analysis menu, turn on grand totals for both rows and columns to see the behavior. Next, right click on SUM(items) and choose Quick Table Calc->Percent of Total. Tableau will display the percents of total in the table.
If you want the percent of total defined differently than the default, then right click on the measure again and set Compute Using to a different value such as matches_code_prefix in your case. It's usually better to set compute using to a specific field.
If you only want to display the value for the matching case, select the column header you don't want to see and choose hide. You can also turn off the grand totals from the analysis menu when you are done.
When you are confident in the values in your table, you can turn it into a bar chart for example by moving matches_code_prefix to the detail shelf and the measure to the Columns shelf.
--
The above is the drag and drop approach. If you prefer to hard code everything in a single calculated field that is calculated on the database side, you could instead define a calculation such as:
zn(sum(if matches_code_prefix then items end)) / sum(items)
Then set the default number format for that field to display as a percentage

Microsoft Access - I want my mainform to create X records in subform base on fields automatically

I been putting a lot of thought into the logic behind this, and I can't seem to figure out the best way to handle this problem.
1 - Afterinsert
2 - unbound fields + button to insert X times
3 - I am open for suggestions
The form
The relationship
I was debating on using AfterInsert to handle everything. Since NoOfBoxes will decide the amount of records and I would only need to duplicate the value of MergeNo and isCommission to the subform. But the problem is, I need to also auto fill the item, which made me think of solutions number 2.
The reasoning behind going with number 2 is; my receive report header doesn't contains the item information and since a subform can only have 1 type of item but multiple of them. I was hitting toward number 2.
Solution number 2 would be multiple unbound fields which pulled the information into a combo box, or enter the information needed and hit a button which will then transfer all that data to the subform and create the correct amount of records.
unbound fields = itemcode, mergeNo, isCommission, and NoOfBoxes.
I think you need a Numbers table with integers from 1 or 0 to an appropriate number, you can then say something like:
INSERT INTO ATable ( MergeNo, IsCommission )
SELECT [Forms]![aForm]![MergeNo] AS MergeNo,
[Forms]![aForm]![IsCommission ] AS IsCommission
FROM Numbers
WHERE Numbers.Number<=[Forms]![aForm]![NoOfBoxes]
Do not forget that if the numbers table starts from 0, it is less than, not less than or equal to.