Question regarding the string function in report builder - ssas

I have a expression /78_raho/dataschool and i want to extract the /78_raho/ from the expression without using query but by string function. How i can do so?

Related

Can you build an expression inside of a custom code function in Report Builder?

I need to provide my RDL files to teammates so that they can make minor customizations for each client. One of the ways I thought I might improve the efficiency is if I could build more complex expressions inside of custom code functions so that they can input some simple arguments and have the function handle the "heavy lifting" of adjusting the expression accordingly.
This is a very simple example, and not one I would take this step for, but I thought it the easiest place to start figuring out if I can make this work. For instance, in a tablix we want a count returned based on a value where the value is customized per client (and isn't a parameter).
=Count(iif(trim(Fields!Category.Value)="OPTIONA",1,nothing))
Is there a way I could build a function so that my teammates would just need to enter the following?
=Code.CustomFunction("OPTIONA")
My understanding is that the custom code in Report Builder can't query datasets, or at least not in the way that an expression within a tablix would be able to. I've built custom functions that work with the results of an expression added as the argument, but I can't seem to wrap my head around if there's a way to construct an expression within a custom function and pass it back to the expression.
For instance:
Public Function CustomFunction(field As String) As String
Dim customExpression As String = "Count(iif(trim(Fields!Category.Value)=" & field & ",1,nothing))"
Return customExpression
End Function
As expected, this just returns a string with the text of the expression, but not an executed expression. Is what I'm trying to achieve possible with Report Builder?
Or, as an alternative approach, can I somehow place variables at the beginning of an expression that are used later so that anyone else working on the expression just needs to worry about the beginning? Essentially create multiple custom functions and call them later on?
=Code.CustomFunction("OPTIONA",Count(iif(trim(Fields!Category.Value)=Code.CustFunc01(),1,nothing)))
Honestly not sure how I would go about building the functions themselves from here.
You can use a function instead of the related field. The function takes the field string as an argument and the filter string for which will increase the counter. Finally it returns the original field value
Private Dim Counter As Integer
Public Function SetCounter( Expr As String, Filter As String) As String
If Expr = Filter Then Counter = Counter + 1
Return Expr
End Function
Public Function GetCounter( ) As Integer
Return Counter
End Function
For the field value you can use the following expression (yellow color)
=Code.SetCounter( Fields!MyString.Value,"OPTION A")
To get the counter value you can either use the following expression calling a function (orange color)
= Code.GetCounter()
Or make the variable public and use Code.Counter as the expression

IntelliJ IDEA: inject language with String.format()

I have an SQL query which unfortunately cannot be written as a prepared statement because it has variable column names. Because of this, I have to build my SQL using String formatting.
The language (SQL dialect) I'm using is PostgreSQL, but because I have String.format() in my queries, IntelliJ complains about syntax errors in my code.
public class Example {
public String getUniqueFeatureCountSqlQuery(String feature, Long sourceUserId) {
//language=PostgreSQL
return String.format("SELECT COUNT(DISTINCT targetUserId), %s FROM userComments GROUP BY %s WHERE userId = %d",
feature, feature, sourceUserId);
}
}
How do I make IntelliJ recognize this string properly? It should know that it is PostgreSQL which is first formatted by String.format().
Thanks to #WillHumphreys I found a solution via youtrack.
You have to go the the User Parameters settings under Tools -> Database -> User Parameters, or use the find action command.
Then make these changes.
You may also have to use the argument index string format notation (String.format("SELECT %1s ...", ...)) for the parameters to be distinguishable when attempting to alt-enter run the query in the console.

String concatenation in stringtemplate

I'm trying to make a lookup to a hash table m.notes using concatenated value of position.qid and literal ".qid" like this:
$tag(name="itemId", content=m.notes.(position.qid".qid").itemId)$
I tried different options, but I get runtime error. Can someone correct my syntax?
Put the 2 items in an array. StringTemplate concatenates all items in an array (or as they call it, a multi-valued-attribute) when it executes a ToString() on it.
[position.qid, ".qid"]
So, if position.qid evaluates to "hello", this expression would become
hello.qid.
Not sure whether such concatenation is possible in string template. Why don't you use a different method that could do the concatenation and return the value.
e.g:
position.fullQid instead of position.qid
where,
public String getFullQid(){
return getQid() + ".qid";
}
in template group, I can do like this, first, define a concantenate template:
concantenate(substr)::=""
then use as following
(concantenate([position.qid,".qid"]))

Pass Java List to SQL query Grails

i have a populated list:
def someList=... (string values)
and I want to pass this into a SQL statement to restrict which columns the query selects.
db.rows("select ${someList} from arch_application")
However, I get this error when I try to do so:
There is a ? parameter in the select list. This is not allowed.
Anyone have an ideas? Thanks!
When you pass a GString to Sql.rows, it gets parsed differently than normal in groovy. In particular, it creates a PreparedStatement with replaceable parameters for ${} substitutions. In your case this is probably not what you want. Try forcing the GString to a Java string:
db.rows("select ${someList.join(',')} from arch_application" as String)

VB.NET logical expression evaluator

I need to test a logical expression held in a string to see if it evaluate to TRUE or FALSE.(the strig is built dynamically)
For example the resulting string may contain "'dog'<'cat' OR (1>4 AND 4<6)". There are no variables in the string, it will logically evaluate. It will only contain simple operators = > < >< >= <= and AND , OR and Open and Close Brackets, string constants and numbers. (converted to correct syntax && || etc.)
I currently acheive this by creating a jscipt function and compiling it into a .dll. I then reference the .dll in my VB.NET project.
class ExpressionEvaluator
{
function Evaluate(Expression : String)
{
return eval(Expression);
}
}
Is there a simpler method using built in .NET functions or Lamdba expressions.
I tried the demo out for this project and you might like it over you current method of evaluating. Note, it doesn't use lamdba expressions or any build it .NET methods.
http://web1.codeproject.com/KB/vb/expression_evaluator.aspx?msg=1151870
try out: http://www.codeproject.com/KB/cs/ExpressionEval.aspx
More guidance :http://www.thefreakparade.com/2008/07/evaluating-expressions-at-runtime-in-net-c/
Good one: http://flee.codeplex.com/
Boolean Example which you are looking for : http://flee.codeplex.com/wikipage?title=BooleanExpression&referringTitle=Examples (ignore the variable adding part as you are not looking for variable)