Top N by Count of Dimension Tableau - bar-chart

I am a bit new to Tableau.
I have two columns: DATE and Car Model
I want to create bar graphs for the Top 5 (Count of Car Model) each individual year on the same sheet.
When I select the Top N filter, it selects the overall top 5 models and displays counts for each such model.
However, each year has a different Top 5. I want to be able to get the top for that particular year only.
Can anyone help me with it?

This you can do through function INDEX. Do these steps (I am replicating your problem on sample superstore as you haven't given any data)
I built a view/viz with order date & customer name rows shelf and sum(sales) on columns shelf.
create a calculated field named say INDEX with formula INDEX()
drag this INDEx field to DETAILS on Marks card
right click, edit table calculation and set the following options
-- specific dimensions (check both fields drag to adjust date field prior to second nested field)
-- At the level (select second field name - customer name in my case)
-- restarting at every (select first date field , order date in my case)
-- sort order - CUSTOM - select Sales(Measure) with descending and aggregation as your measure (sum in my case). A screenshot is attached for reference
ctrl + drag INDEX field to Filter and select 1 to 5.
Your desired view is ready

Related

Waterfall - Custom Sorting in PowerBI?

I'm aware of the sorting function in waterfall, but that seems to sort the items by category and y-axis column.
What I'm hoping to do is sort non- category or y-axis column.
Needs to be organize by the following order:
FY 17 YTD, Revenue , Transport , Services and Delivery, HQ, Dispatch, Duties , GL Admin
Thank you.
Add a column to your source data and populate it with values for the preferred sort order.
Then select the column you want to custom sort and click Modeling > Sort by Column. Select the new column as the SortBy column for the existing column. The SortCategory column is used as the sort order for the Category column.

Alteryx to select top N records where N=a value on that group

I'm in a fix with Alteryx. I'm trying to select the top N rows where N=a cell value for that partition. The business question is:
"We need to know, out of our orders (TicketIDs), those that have
least 1 combination of Type of discount item AND drink AND side."
The SQL query would join this table onto itself and partition to get the TopNtoIncludeInItems for that row, however, I just can't seem to find a way to do this in Alteryx. I've tried the community, but the question has gone ananswered.
In other words, select thusly:
<pseudocode>
for each (TicketID)
for each(Type)
select top(TopNtoIncludeInItems for this.TicketID)
next
next
</pseudocode>
or indeed select just the green records
Here's my solution:
MultiRow Formula: create new field ComboCount (or whatever) as Int32, 0 or empty for rows that don't exists, Group By TicketID and Type, with the Expression [Row-1:ComboCount]+1 ... this counts up each group; we'll want the first topN of each group, ensuring the group actuall has that many, and not going beyond TopN.
Filter on [ComboCount] <= [TopN] ... which excludes unnecessary rows beyond TopN
Summarize: group by TicketID and Type, doing Max(ComboCount) ... if this value is less than TopN for any group, the group should be excluded:
Join the summary back to the earlier pre-summary data on TicketID and Type
Filter on [Max_ComboCount] = [TopN] ... this excludes the groups where any ItemType falls short of TopN
And that's it. Pictorally, this is what my workflow looks like, along with data results based on data similar to that in your screenshot:

Report Builder - Total Expressions

I have a report that displays the following data:
Quantity
Line Item Total/Extended Price (this is based off of a formula of rate * quantity)
Product Type (i.e. Type A, B, C, D, & Other)
At the bottom of the report, I would like to add a small three column table that takes the total quantity and price by the product type.
The table will only ever have 5 rows - row 1 = Type A, etc. Columns will be "Qty" and "Total" which should represent the sum of each based on the type.
I am struggling getting a RunningValue formula to work with a IIF statement that would filter based on type.
Here is what I have tried in cell A1 of the table (to display qty total for type a only):
=IIf(Fields!type.Value="A",RunningValue(Fields!quantity.Value, Sum, Nothing)
To achieve this it would be best to use a Matrix, as follows
Create a matrix and set the row grouping to be your Type Field.
Right click the column header and select Insert Column – Inside Group Left to give you two columns to display the Quantity and Total values.
In the header you can right click the area and selected Insert -> Rectangle, then added two text boxes to give the column headings (in blue)
In the left Dataset set the expression to be
=sum(CInt(Fields!Qty.Value))
To sum all the values for this Type together (Note this assumes the are integers, you can use CDbl for doubles for example)
Do the same for the Totals text box as well (note I have set the expression to return a currency as well – Right Cick -> Palaceholder Properties -> Number -> Currency)
This matrix looks as follows in design mode
And like this when rendered (note the source data I am using to generate this is also shown)
Is this the sort of output you required? Let me know if I can help further.

SSRS Group per N distinct

I'm trying to solve a problem.
As an example, let’s say I have a table containing 3 columns (Name, Timestamp, Value) with 30 unique or distinct Names and over + 1,000 rows
I have created a line chart which plots Value(Y) vs. Time(X) for each Name (series group), therefore there are 30 lines in this chart.
However, having 30 series in a chart is too cluttered and illegible for the most part. So I have placed the chart in a table (although a "List" would probably be more appropriate). I then grouped the table by "Name" which gives me one Name (series) per chart, which is great but still not ideal as this generates lots of charts and takes up many pages.
I would now like to keep the name grouping but have 5 Names (series) per chart.
I believe this is something simple but I’ve battled with this by searching and trying numerous grouping expressions for several days without any success.
Also , the order or ranking is not important.
Here is a grouping example that comes close to what I need but is not suitable as it groups per 5 lines rather than 5 per distinct name.
This expression groups per 5 lines… =Cieling(RowNumber(Nothing)/5)
Thanks
John.
The easiest way to solve your problem is to add that information on your query. If you're using SQL Server you can add to your query:
SELECT Name, Timestamp, Value,
ROW_NUMBER() OVER(PARTITION BY Name) as rownum
....
And then your grouping expression on the table can be =Fields!rownum.Value Mod 5

Difficult MS Access Query - how to combine them?

I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.