Aggregate on day, month and week level - tableau-api

I am making a dashboard with clicks on a daily level and a month level on a certain campaign.
If I have say 1 customer clicking on 2 days then at a daily level that customer is counted twice. However, when I look at the aggregate monthly level this person will be counted once.
My SQL code that I am pulling into tableau is at a daily level. How do I get a monthly level view in the dashboard? When I am creating a parameter with month and day..on selecting month it is just adding the day level numbers to give me the month.
Any advice?

Sounds like a count distinct thing. To get around this the COUNTD would need to happen in Tableau. That would mean you need the Contact ID (or whatever it is you want to count) within the data source. Obviously that would mean your data source is much bigger but is the only way to get an accurate unique count over a custom time period.
Another alternative is to restrict the available time periods for the user and pre-aggregate for those time periods.

Related

Tableau dashboard filter action excluding date but including clients represented in date clicked

I have a bar chart below that shows the sum of clients by month. I want to be able to click on a month and use a dashboard action to navigate to all data for each of the clients represented in the month that was clicked. Basically, I want to exclude the date portion of the filtering.
I currently do this by navigating to a sheet that includes client_id and filters for the single month and then I select all client_ids and action to another sheet that filters by the selected client_ids and not date. I want to remove the middle step.
If the above selected month is April 2020 and represented 64 clients, my current action takes me to a sheet that has each client on a row and shows me their sum of invoices for April 2020. I want to see those same 64 clients for all months they have transactions in.
This one may be tough to accomplish, but I definitely see what you're setting out to do. If you're using a date dimension on your action it will use that data to filter.
However, there may be some other options depending on what you're needing. If don't need to see the invoice ids and only want to see the sum of invoices for all months you could use a LOD (Level of Detail) calculated field.
You would create a calculated field like:
{ FIXED [client_id] : SUM([your invoice amount measure])}
Use this as a new column to get the sum of all invoices in your data set for each client.

Calculate a running total that works with relative date filters

I have a Union table of my various bank accounts to create a personal finance analysis dashboard.
I am trying to make a Running Total to show my total capital available at any given date. Using a Running Total table calculation works, just as much as using a RUNNING_SUM() calculated field. They both work up until I filter the dates. So I am trying to find a way to make the running calculation work without being thrown off by Date Filters (I would like to implement relative dates for visualisation in the dashboard).
My union table has the following relevant data columns:
Order ID: Descending number from 1 for each entry per account.
Date: Date of entry.
Item: Entry name.
Account: Name of bank account.
Amount: +ive for credit or -ive for debit.
Balance: balance after entry value for each given account.
So the table can look like this:
So on 07/05/2019 the Running total should be 229.64.
The running sum formula mentioned above is currently RUNNING_SUM(SUM([Amount])), so if any dates are excluded via filter the running total doesn't add up to the right amount.
A way I can see around the problem could be to get the sum over all accounts of the last balance reading at a given date. The balance is a running total but only if the final entry per time period for all accounts are summed would it work. Would it be possible to make a calculated field that gets the last balance reading for each account at any given date and then sums them?
Or is there a simpler smarter way I am not aware of?
This comes down to an Order of Operations problem. Once you filter the dates the viz doesn't have access to the data anymore.
Your best approach would be to add the running sum to the data source before you bring it into Tableau. Then the running sum isn't a calculated field dependent on the data in the Viz.

Segregate Products based on shipping <SQL>

I have 10 different products (A,B,C),..,J)have multiple purchase dates (by various customers) and delivery dates. I want to see which products have the date difference of less than 5 days. If the date difference is less than 5 days, which products have customer rating less more than 3.If the above criteria is satisfied I want to fetch those products that has the minimum date difference from the queue along with the "Important_date".If there are same minimum date difference for a particular product then I would like to select the top one among the same product in recent times and mark the purchase date as the "Important_date".
The columns in the table are: Product,Purchasedate,deliverydate,date_difference,customer_rating.
I am trying to use case statements to solve the problem in PostgreSQL.
I am looking for an output which will give me all the columns of the table along with "Important_date."

Tableau Aggregation of Groups over Fixed Level of Detail

For some reason when I try to group a field created by a fixed level of detail groups containing more then one item disappear from the view.
The basic set up is that there are 'unique event IDs' which are RCIPID which have one or two dates associated with them (some events have two separate dates that are non-linear). There is a 'follow up' date which is tied only to the event location and not the RCIPID, but each RCIPID has only one location.
I've joined the 'follow up' data to the main file based on the location. The below computations [NTC Submission Date] is the date of the event. [Live Date] is the date of the followup. The computations correctly give the number of days after the event that the follow up happened.
However when I try to do a unique count of NTC Date (Or RCIPID) and then group the computations any group with more then one day disappears.
FP - Straight Diff
DATEDIFF('day', [NTC Submission Date], [Livedate])
FP - Remove Negatives
IF [FP - Straight Diff]<0
Then DateDiff('day',[NTC Submission Date],TODAY())
ELSE
[FP - Straight Diff]
END
FP - Days after NTC
{FIXED [Rcip Id], [NTC Submission Date]: MIN([FP - Remove Negatives])}
It works when it is not grouped together
But as soon as I group it all of the groups with more then one day disappear.
Any and all help is greatly appreciated. I think it has /something/ to do with being a dimension, but I honestly don't know what.
The goal is a bar chart similar to the second one, but with the groups "4-5 Days", "6-10 Days", "11-20 Days", and "Over 20 Days" visible. Those values do exist in the data and if I change the view to show the day instead of a count it shows the proper calculations:
EDIT: Using a calculated field instead of groups did not work. Trying a concatenated RCIPID and NTC Submission Date also did not have an effect.
I'm not a huge fan of the group by feature in Tableau as it has give me some unexpected behavior in the past.
There are a few approaches I would recommend trying. One is spelled out well here by using the bin functionality built into tableau. https://community.tableau.com/thread/188952
It sounds like you have some irregular bin sizes you're looking for, in which case you could create a separate calculated field with a series if else statements based on the range of [FP - Days after NTC] and assign a string to each 'grouping'
Lastly, I've not done an LOD of this style with two dimensions "FP - Days after NTC". You only appear to have COUNTD(submission days) on the view shelf. I would verify that you are getting the results you are expecting. And if not, you could create a separate calculated field that is a concatenation of [Rcip Id] and [NTC Submission Date] on which to based your LOD calculation, and then you can use COUNTD on that new field.
EDIT: It was suggested to try using a computed field instead of a group and/or concatenate RCIPID and NTC Date. I tried both and neither affected the result.

MS Access 03 Query Criteras

If I have a report that tracks data for several accounts for each month with rows labeled:
UNITS,
REVENUE,
AVG REV/UNIT
How would I create a query that will filter the report to just show accounts where the UNITS row has increase/decreased 25% and the AVG REV/UNIT has increased/decreased 10%, from the previous month to the current month.
An example would be for the month of June I have the numbers....
JUN
UNITS 3,271
Revenue $3,598.10
Avg R/U $1.08
So when I run the report at the end of July I only want accounts that have a 25% difference in UNITS and/or a 10% difference in AVG REV/UNIT to show on a report.
qryPharmacy
SELECT PHAR_REPORT.*, (IIf(u1 Is Null,0,u1)+IIf(u2 Is Null,0,u2)+IIf(u3 Is Null,0,u3)+IIf(u4 Is Null,0,u4)+IIf(u5 Is Null,0,u5)+IIf(u6 Is Null,0,u6)+IIf(u7 Is Null,0,u7)+IIf(u8 Is Null,0,u8)+IIf(u9 Is Null,0,u9)+IIf(u10 Is Null,0,u10)+IIf(u11 Is Null,0,u11)+IIf(u12 Is Null,0,u12)) AS USUM, (IIf(r1 Is Null,0,r1)+IIf(r2 Is Null,0,r2)+IIf(r3 Is Null,0,r3)+IIf(r4 Is Null,0,r4)+IIf(r5 Is Null,0,r5)+IIf(r6 Is Null,0,r6)+IIf(r7 Is Null,0,r7)+IIf(r8 Is Null,0,r8)+IIf(r9 Is Null,0,r9)+IIf(r10 Is Null,0,r10)+IIf(r11 Is Null,0,r11)+IIf(r12 Is Null,0,r12)) AS RSUM, RMonth.*, PG2.*, PG.pGroup
FROM PHAR_REPORT, RMonth, PG2, PG
WHERE (((PHAR_REPORT.PR) Like ([PCODE] & '*')) And ((PG.pID)=PG2.PID))
ORDER BY PG2.pID, PHAR_REPORT.PR;
You should do it with more than one query. In the first query, select the data for the first month. On a second, to the desired month to compare. Create a third query that links the two first (be care about the correct relationship). Do the grouping/calculations in these queries.
In the 3rd query, create two fields that calculates increasing/decreasing for units and rev/unit. Now, you can add a criterium on each parameter field in the query columns.
The chalenge here is to be sure about hou would you work with the primary keys on months. Eg: if a A row in the first query isn't in the second (for not having an event on second month, for example), it will not be showed. In this case, the solution would be to create the queryes linking a table or query wich has the entyre set of registers, forcing it to show all the desired records despite they have or not occurrences.