I'm looking to create a variable to remove unnecessary null values from my query results. I will also need that variable to create a crosstab to count the acuity levels by day. Some of the query results return a line with a numeric result and line with a null result. Others will just return one or the other. The caveat is that I need to keep the null results if they are the only result for that patient. Please see sample data below and a sample cross tab. The cross tab is using the current acuity dimension which includes the additional null values I don't want. The other fields on the cross tab are Tracking Date and # of Patients (see below).
=FormatDate([Start Tracking Date & Time];"MM/dd/yyyy")
=Count([Financial Number])
Related
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:
I am trying to find a way to use the Group By functionality to create a table where the numerator of a fraction is grouped both by column and row, and the denominator is grouped only by column.
Here's my existing expression:
=Round(Sum(Fields!Days_In_Step.Value)/CountDistinct(Fields!ID.Value),1, MidpointRounding.AwayFromZero)
When grouped by rows (groupName) and columns (month/year) the numerator (Sum(Fields!Days_In_Step.Value)) gives me good data, but the denominator (CountDistinct(Fields!ID.Value)) is also grouped by row (groupName) and I don't want that.
I have a SQL solution but am trying to do this entire within SSRS expressions, if possible.
edit
Sample Data:
It would look like this. The background is that these groupings are counts of days and the "all" are counts of tickets, so we are trying to see who is sitting on their tickets longer.
Here is a mock-up including a sample data set using a pivot table:
Edit 2
Here is a full sample data set:
https://docs.google.com/spreadsheets/d/1rYPMcrLNB-FZN64Fn2-y3FtnM2iQo2VMH7YTdfiVnKM/edit?usp=sharing
I need to group on month as well as year, and I do not want to see "Exclude" in the group rows, however they cannot be filtered out of the tablix without being removed from the overall population, which is required for the denominator.
Your problem is caused by the scoping of aggregate functions. When you use aggregate function they run under the scope where it is placed in the tablix by default. In your case Sum() and CountDistinct() functions are running in both row groups (Owner Group) and column group (Month Group).
Fortunately, you can specify the scope that you want your aggregate function computes the aggregation, simply add the group name in the function:
CountDistinct(Fields!ID.Value,"MonthGroup")
The whole expression is like this:
=Round(Sum(Fields!Days_In_Step.Value)/
CountDistinct(Fields!ID.Value, "MonthGroup"),1, MidpointRounding.AwayFromZero)
Replace "MonthGroup" by the actual name of your group in columns
group.
This is result using the sample data you provided:
I've used this expression to show you how it is produced:
=Sum(Fields!Days.Value) & "/"
& CountDistinct(Fields!Ticket.Value,"MonthGroup") & "=" &
Sum(Fields!Days.Value)/CountDistinct(Fields!Ticket.Value,"MonthGroup")
Note my column group is named MonthGroup.
UPDATE: Scoping multiple groups in CountDistinct function.
Firstly I am not filtering the dataset, I prefer hide the Exclude rows using the below expression in the Hidden property of the Row Visibility window:
=IIF(Fields!Group.Value="Exclude" OR Fields!Group.Value="-1",true,false)
To count distinct id grouping by Month and Year but not by Group you can create a child group below Month group as you can see below:
My group is called Group2 and I used this expression in the Group on textbox.
=Fields!End_Month.Value & "-" & Fields!End_Year.Value
It will create a group per every Month-Year combination. When you create the group it will be added as a column group so you will have to delete the row so you will be prompted if you want to delete the group and row or delete the row only. Delete only the row leaving the group.
Now the expression you have to use is
=Round(Sum(Fields!Days.Value)/CountDistinct(Fields!ID.Value, "Group2"),1,MidpointRounding.AwayFromZero)
Replace Group2 by the name of the created group in your case.
This is the whole recreation of your scenario:
Let me know if this helps.
Hoping I’ve not over simplified things,
I have 2 tables: tblTestA and tblTestB
Both tables are linked through their common ID fields.
I’m looking to select all records from tblTestA that have a date greater than #2013/01/01# its Date field.
Then, from this record set, further filter by keeping only those records who have at least 1 non-Null value in Field1 or Field2 from tblTest2 (i.e. remove double Nulls)
Is there a way to modify the following unworkable/pseudo code so that the above is achieved?
SELECT tblTestA.ID, tblTestB.Field1, tblTestB.Field2
FROM tblTestA
WHERE tblTestA.Date > #2013/01/01#
Inner Join tblTestB
On tblTestA.ID= tblTestB.ID
Where (Not IsNull(tblTestB.Field1)) Or (Not IsNull(tblTestB.Field2));
In the real scenario (due to the way the tables are structured, their size, and additional factors) querying only on the non-Null requirement takes very long. Querying only on the date greater than #2013/01/01# requirement takes very little time. So I’m thinking that if we can return the smaller date requirement result set and then use the common ID field to do the second filter on the non-Null check, then, the whole query might complete faster.
Edit:
Modifying the above to...
SELECT tblTestA.ID, tblTestB.Field1, tblTestB.Field2
FROM tblTestA
Inner Join tblTestB
On tblTestA.ID= tblTestB.ID
WHERE tblTestA.Date > #2013/01/01#
AND
(Not tblTestB.Field1 Is Not Null) Or (tblTestB.Field2 Is Not Null);
...returns records that are within the required date range but seems to also link the non-Null filter to that same date range. Entries for Field1 and Field2 may have been entered before the date range requirement filter. I've probably over simplified things from the real scenario, but I'm looking to do 2 things: 1. return records within a date range, and 2. from this result set, filter out any records that do not have at least one non-Null value in Field1 or Field2 from any date range.
I have SSRS report where in I am using table with 7 columns (Date, Job ID, Job Name, Status, Output Count, Expected Count, Flag). Out of 7 columns , 4 are directly coming from dataset. Rest three (Job Name, Expected Count, Flag) are calculated columns. I am getting their values from either SSRS custom code or expression. I want to count those rows where Output Count and Expected Count are not matching. Also I have Flag column where I am using Background Color property to check if values are matching or not. So even if I can get count of rows having Red background at Flag column will also server my purpose. Please help me in achieving the same.
You can create some new fields for your dataset to handle calculated values. Then, in your report, you can add some groups and add count or sum values on the table.
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.