Tabular Model: DISTINCTCOUNT on field with blanks in DAX - ssas-tabular

I understanding that DISTINCTCOUNT function in DAX is supposed to ignore blanks. From this I'd expect that if you had 2 unique values and a blank in a column the DISTINCTCOUNT on that column would return 2.
I am find this continues to return 3 i.e. the BLANK is treated as a value. How can I change this?
I cannot find anywhere in the tabular model where I can change the equivalent of NullProcessing. I have tried creating a column with just BLANK() and this returns a count of 1 too where I'd expect 0.
All help appreciated.

I got the answer. To do this using the following DAX for numeric fields
CALCULATE(DISTINCTCOUNT('Sales'[SomeID]), 'Sales'[SomeID] <> 0)
OR
CALCULATE(DISTINCTCOUNT('Sales'[SomeID]), 'Sales'[SomeID] <> "")
for character fields.

CALCULATE(DISTINCTCOUNT('Sales'[SomeID]), 'Sales'[SomeID] <> BLANK())

Related

SSR Sorting Expression using Report!Items

I have a report using Matrix table group by Business with Sub-total and grand total. I have a calculated field called "% of Received" column that uses Report!Items in the detail row, and I want to sort it from highest to lowest value =ReportItems!MTDPACount.Value/ReportItems!MTDLOBTotal.Value, but it is giving me an error that Report Items cannot be used in expression. Please advise.
Thanks
Have you checked whether some of the ReportItems!MTDLOBTotal.Value are NULL or 0? If so, treat ReportItems!MTDLOBTotal.Value first, add ISNULL and WHERE column != 0 to your query or Stored Procedure to filter out those invalid denominator. Or you could directly add condition in the expression to treat 0 or NULL for your ReportItems!MTDLOBTotal.Value

Using LIKE in Multi-Value Parameter in Crystal Reports 2011

I am developing a report in Crystal Reports 2011 that has 3 sub-reports pulling data from 3 different databases. I have a Multi-Value Parameter (String) in the main report that passes the input values to the 3 sub-reports which have the same Multi-Value String Parameter.
Sample Input Values are:
P000000030,
P000000930,
P000001730
The user does not want to input the leading alpha character and preceeding zeroes. They want to input the following:
30,
930,
1730
The sub-report pulls all of the records successfully if the user puts the entire string value in with the following Record Selection Criteria, but it does not work with the partial strings input:
{Command.Puchase Order} in {?Pm-?Reference}
Can anyone advise the syntax needed to pull the data in the subreport with the substrings as inputs?
Thanks in advance!
Thank you for your input guys!! I took a bit from everyone and came up with the following solution:
Create a column in the datasource that trimmed out the desired value --> ltrim(regexp_replace(a."po_num",'P',''),'0') as "Puchase Order2"
Modified my Record Selection Criteria to select for either column --> {Command.Puchase Order} in {?Pm-?Reference} or {Command.Puchase Order2} in {?Pm-?Reference}
I really appreciate your input! I am able to deliver the desired solution with your aid.
go ahead and create a formula that calculate the length of your parameter(len({?Pm-?Reference})) and place it suppressed on your report header. Then put below in your record selection formula
right({Command.Puchase Order},{your length formula}) in [{?Pm-?Reference}]
You could add the "number only" version of [Puchase Order] to your datasource...
cast(cast(right([Puchase Order], len([Puchase Order]) - 1) as int) as varchar(9))
as [Puchase Order Number]
...then use that in the select expert. I'm getting the number without the leading P, casting to int to remove the leading zeros, and then back to a varchar for the string comparison in Crystal.
You could do the same with a formula in Crystal reports. Then reference that formula in the select expert. Downside is having to repeat that in all 3 sub reports.

Parameter to find all records or exclude NULL

I have found several articles on how to accomplish the reverse of what I want to do with several methods (IS NULL, CASE, COALESCE), but I think at this point I am more confused than ever after reading all this and probably making solution harder than it needs to be. I am new to T-SQL and I am currently using VS 2005 to build a basic medical report.
I have the Date Range parameter working properly by using a convert command to ignore time stamp giving me all records for the day or date range. I am now wanting to filter SSRS reprot by perliminary report date to find records with preliminary report, or, all records in table.
The database has NULL if no preliminary report was created
The database has time stamp if preliminary report was created. (showing date and time it was created)
I need to find all records not NULL, or all records. (using a parameter)
I have a parameter "Display Prelim Reports only?" #PrelimOnly with a YES or NO answer.
If I use the following it will show all records correctly (all records not NULL showing only records with Prelim report/time stamp present)
LIS_Results.Prelim_Report_Date <> '#PrelimOnly' ----User selects YES it passes NULL
however, if user selects NO, how would I get it to display all records including NULL?
Thank you for any help
Thank you both for your help, it was ultimately a combination of both that got it going. Syntax is as follows.
WHERE (#PrelimOnly = 'NO') AND (CONVERT(VARCHAR(10), LIS_Results.Final_Report_Date, 101) BETWEEN #ReportStartDate AND #ReportEndDate) OR (LIS_Results.Prelim_Report_Date IS NOT NULL) AND (CONVERT(VARCHAR(10), LIS_Results.Final_Report_Date, 101) BETWEEN #ReportStartDate AND #ReportEndDate)
Use an if statement in tsql to say if parameter is yes select records from table where conditions are true.
If no select records from table where conditions are true and date field is not null.
Since #PrelimOnly can only be YES or NO, use:
SELECT
...
FROM
...
WHERE #PrelimOnly = 'NO' or LIS_Results.Prelim_Report_Date is not null
...
If the parameter is NO, the left hand condition of the OR is satisfied and all rows are returned, otherwise only those non-null rows will be returned, as required.
here exist small trick:
((LIS_Results.Prelim_Report_Date <> '#PrelimOnly') OR (1=#AllowNull))
if user selected NO - set AllowNull argument to 1, other way set it to 0
NOTE: AllowNull - it is custom additional argument, you should add the same way as #PrelimOnly
another possible approach:
((LIS_Results.Prelim_Report_Date <> '#PrelimOnly') OR ('NO'='#PrelimOnly'))
for you full query you should do like this:
WHERE
(CONVERT(VARCHAR(10), LIS_Results.Final_Report_Date, 101) BETWEEN ReportStartDate AND ReportEndDate) AND
(
LIS_Results.Prelim_Report_Date is not null
or
('#PrelimOnly' = 'NO') // if instead of NO VS sends empty string replace it here
)
It was a combination of Iiya and Ian that got me the solution however the syntax was not complete and is as follows.
WHERE (#PrelimOnly = 'NO') AND (CONVERT(VARCHAR(10), LIS_Results.Final_Report_Date, 101)
BETWEEN #ReportStartDate AND #ReportEndDate) OR (LIS_Results.Prelim_Report_Date IS NOT NULL)
AND (CONVERT(VARCHAR(10), LIS_Results.Final_Report_Date, 101) BETWEEN #ReportStartDate AND
#ReportEndDate)
It requeired the Date and Time paramater to be repeated so that both paramters would still work, and the #PrelimOnly = 'NO' had to be first.

Crystal Reports and Adding values

I am using Crystal Reports XI and I'm trying to add a particular column if one column or another column is set to one.
Here is the current preview:
Username (GROUP 1)
MONTH (GROUP 2)
DATE SUBJECT TOTAL_TIME
End of group 2
End of group 1
Now I want to add the values in total_time if one of the two hidden fields contain 1 (true).
I tried using sum() function but it didn't work as it added all the times together.
I'm still new to Crystal Reports and I tried searching on google but nothing came up similar to what I need.
Any help would be greatly appreciated.
One alternative that I can suggest, You can use Parameter fields on your report.
Do the calculation on Code behind and set the calculated sum to parameter field on Page_Load event of Crystal Report page.
This parameter field will be used to display the sum on report page.
Please check this link to see
-How to create Parameter Fields:
http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/en/CrystalReports_dotNET_SDK/crsdk_net_doc/doc/crsdk_net_doc/html/crtsktutorialscrvparametersdiscretecreatingreport.htm
-How to set values in Parameter Fields:
http://msdn.microsoft.com/en-us/library/aa289936(v=vs.71).aspx
Your best option will be use "Running totals" by this way you can control the flow by keeping a condition to sum when the required column is 1.
Did you think about small trick? You wrote: I want to add the values in totaltime if one of the two hidden fields contain 1 (true).
Under these circumstances you can calculate helper field Total_Time_Conditional using formula:
Total_Time_Conditional = IIf(HiddenField1 = 1 or HiddenField2 = 1, 1, 0) * Total_Time.
This will multiply Total_Time
by 1, if any of hidden fields is 1
by 0, if both hidden fields are 0
Calculating Sum(Total_Time_Conditional) will give you expected result.

Formula field displays blanks instead of desired result

I'm stuck on a problem with a formula field in Crystal Reports and I keep going around in circles. I'll try my best to explain it.
The report I'm creating will be exported as a data file. It uses 3 tables, with work_table as the main table. work_table is joined to a view called order_item_with_aux using two fields, orderhdr_id and order_item_seq; it's an inner join. I don't think this has much bearing on my problem but, work_table is also joined to the customer_address table on customer_id and customer_address_seq.
In my output, I've included several fields from all three tables. Where I'm stuck is creating a formula field to populate a #Split field. Here's what I'm writing in my formula:
if {order_item_with_aux.zzaux_no_renewal_notices} = "Y" then "B"
else {work_table.split_value}
This results in the #Split field being populated with "B" for records on the work_table whose corresponding record on the order_item_with_aux view has zzaux_no_renewal_notices equal to "Y". The value of #Split for all other records displayed is blank. I've tried several variations of the above formula all to no avail. I've also tried setting a variable and handling it that way, but again, no go.
Anyone have any ideas? Please let me know if there's more info I can provide.
You need to test for null values first:
if isnull({order_item_with_aux.zzaux_no_renewal_notices}) then
"missing value"
else if {order_item_with_aux.zzaux_no_renewal_notices} = "Y" then
"B"
else
{work_table.split_value}