Finding the total of an expression - SSRS - sql

I am trying to get a row with the totals for the following formula:
=iif(Fields!CreditRatingCode.Value>4,COUNT(CInt(Fields!CurrBalance.Value)),CInt(0))
I have tried adding a SUM, but is incorrect.
=SUM(iif(Fields!CreditRatingCode.Value>4,COUNT(CInt(Fields!CurrBalance.Value)),CInt(0)))

I figured it out.
For anyone who might be having a similar question, this is the expression that I came up with:
=SUM(iif(Fields!CreditRatingCode.Value>4,CInt(1),CInt(0)))

Related

Simple gSheet Query returns wrong values for Count function based on data in columns not evaluated in the query

The problem is that a count function evaluating only column A get different results depending on what's in other columns if those columns are included in the range even if not included in the select criteria.
This is a stripped down version of the problem. The additional columns are needed because of a where condition dependent on data in a different column. But the problem manifests even when the where condition is removed from the query.
A sample spreadsheet including a loom vid of the problem can be found here:
https://docs.google.com/spreadsheets/d/1BJ6qaTcEiXZlzD1opxMHNhFyIBM1CDJPCJ5gr9x_32k/edit?usp=sharing
Any insights or work-arounds will be appreciated.
There've been 18 views and no insights or work-arounds. Nor have I found a work-around so I'm assuming this is a gSheet bug. How does one go about submitting a bug to G?

SQL get values within quotes

im encountering the following issue i have a couple of strings in SQL and try to get just a little part off of it and i cant get it to work.
Examples of my strings:
{"#odata.type":"#make.this.short","Id":0,"Value":"Stackoverflow"}
[{"#odata.type":"#Mmake.this.short","Id":1,"Value":"Stackoverflow1"},{"#odata.type":"#make.this.short","Id":2,"Value":"Stackoverflow2"}]
{"#odata.type":"#make.this.short","Claims":"i:0#.f|membership|name#email.nl","DisplayName":"Lastname F. (Firstname)","Email":"Name#email.nl","Picture":"https://picture.com/","Department":null,"JobTitle":null}
Now im trying to write a stored procedure and get the following values back:
Stackoverflow
Stackoverflow1,Stackoverflow2
and name#email.nl
I tried working with SUBSTRING, LEN, RIGHT, CHARINDEX and REVERSE but i cant seem to get what i need. The value of Value: can ofcourse be of different lenghts for each record.
My idea was to count the total string (len string)
then get the first " on the right and subtract that from the total string.
then i would try and get the second " and subtract that from the first. whats left is the value inside and i could use a substring.
But that would only work for the first one, the others are quite different and somehow i cant even get the first to do what i like. (i cant seem to get the 2nd " on the right)
i hope this is enough info so you could point me in the right direction to fix this problem.
Thankyou
As you are on SQL Server 2017 you should be using the JSON functions for this
SELECT JSON_VALUE('{"#odata.type":"#make.this.short","Id":0,"Value":"Stackoverflow"}','$.Value')
SELECT JSON_VALUE('{"#odata.type":"#make.this.short","Claims":"i:0#.f|membership|name#email.nl","DisplayName":"Lastname F. (Firstname)","Email":"Name#email.nl","Picture":"https://picture.com/","Department":null,"JobTitle":null}','$.Email')
SELECT STRING_AGG(JSON_VALUE(value,'$.Value') ,',')
FROM OPENJSON('[{"#odata.type":"#Mmake.this.short","Id":1,"Value":"Stackoverflow1"},{"#odata.type":"#make.this.short","Id":2,"Value":"Stackoverflow2"}]','$')

Filtering a DISTINCTCOUNT in DAX

I have what I thought was a simple task: create a Measure that returns the distinct count of a field for all records that meet a specific filter condition, in this case a date filter. I came up with the following:
=CALCULATE(DISTINCTCOUNT(ExitFilter[Dim_Client_ID]),ExitFilter[ExitDate]<1/1/2014)
and the result was (blank) so I tried:
=CALCULATE(DISTINCTCOUNT(ExitFilter[Dim_Client_ID]),FILTER(ExitFilter,ExitFilter[ExitDate]<1/1/2014))
and the result was still (blank) so I tried:
=CALCULATE(COUNTROWS(DISTINCT(ExitFilter[Dim_Client_ID])),FILTER(ExitFilter,ExitFilter[ExitDate]<1/1/2014))
and the result was still (blank). What am I missing? And what does (blank) signify?
If it's not clear 'ExitFilter' is a table, [Dim_Client_Id] is a column, and [ExitDate] is a date column.
Tom, comparing dates is from my experience best done with simple Date function.
So if you update your formula to something like this:
=CALCULATE([Your Measure], Table[DateColumn]>DATE(2014,1,1))
You will get what you need with easy-to-read code. Also, for any advanced time-based calculations, the best way to go is creating dates table and using Time Intelligence module of PowerPivot.
Tom, think your second attempt is 'right' but you need to be careful about how you are expressing the date.
Later versions PowerPivot are a little bit funny about this and while "01/01/2014" should work I don't think it will.
Instead try replacing 01/01/2014 with 41640 - this is is the underlying date value, its hacky but then so is any kind of hard coded date :-)

Order not working correctly in MDX

I'm new to MDX and I cannot get the ordering correct. I looked at references online and I think i sorted the query correctly, but the result of the query doesn't agree with me. Can anyone shed some light into what I'm not doing.
I have included a hypothetical example that is close to my problem.
The result of the query comes out without being sorted.
Any help is deeply appreciated.
Thanks
The 2nd argument to the Order()-function on your Rows-axis, must be the value or string to sort by. If you want to sort by the names of the SalespersonID-members, do something like this:
Order([Sales].[SalespersonID], [Sales].CURRENTMEMBER.MEMBER_NAME) on Rows

Two aggregation in a single expression

How to resolve the below expression:
sum({<Category={'Internal Ops SLA'}>}(RangeSum(Above(sum(InternalOpsSLA),0,12))/TargetOpsSLA)*Weight)
It is giving the error in expression, because of the double sum.
The multiplier Weight value is selected as per the category in the set expression modifier. Is there any other way, apart from variable with ONLY as I need to sum the final results, for the above expression ?
I know this post is pretty old. Responding to it, thinking that it might help a few.
I faced a similar problem in qlikview, while trying to compute Sum of Averages. With an error message:
(Error in expression: Nest Aggregation not allowed)
I realized that one work around for this is to use, aggregate functions. Instead of grouping them like:
sum(avg(<Dimension_Name>condition))
I grouped them as:
Sum(Aggr(Avg(condition), Dimension_Name))
and this worked well for me.
So for your problem, I would try something like this:
sum(aggr(if(Category = {'Internal Ops SLA'},(RangeSum(Above(sum(InternalOpsSLA),0,12))/TargetOpsSLA)*Weight),'Dimension Name'))