IReport puts ""+ in one of my fields - ireport

I'm having a problem with one of the fields in my IReport. The field expression is COALESCE(BusNo_FK,'No-Bus') as BusNo which replaces null with 'No-Bus' after left join. Now when I use it in my report, then dragged it into the detail section, the field expression becomes ""+$F{BusNo} instead of just $F{BusNo}. Then when I preview it the value that appears in the report is [78, 111, 32, 66, 117, 115]. And then when I edit its expression and removed the ""+ the value becomes [B#d89b35.
One thing I notice is that when I replace 'No-Bus' with just 0 (with out ' '), it works fine. Another thing I noticed is the field type of COALESCE(BusNo_FK,'No-Bus') as BusNo is of Object type, while others are String. Maybe it has something to do with that? Replies are GREATLY appreciated.

Related

How do I identify whether a column entry starts with a letter or a number using m code in power query?

I have a column that contains either letters or numbers. I want to add a column identifying whether each cell contains a letter or a number. The problem is that there are thousands of records in this particular database.
I tried the following syntax:
= Table.AddColumn(Source, "Column2", each if [Column1] is number then "Number" else "Letters")
My problem is that when I enter this, it returns everything as "Letter" because it looks at the column type instead of the actual value in the cell. This remains the case even when I change the column type from Text to General. Either way, it still produces "Letter" as it automatically assigns text as the data type since the column contains both text and numbers.
Use this expression:
= Table.AddColumn(Source, "Column2", each if List.Contains({"0".."9"}, Text.Start([Column1], 1)) then "Numbers" else "Letters")
Note: It would have been smart to add sample data to your question so I wouldn't have to guess what your data actually looks like!
Add column, custom column with
= try if Value.Is(Number.From([Column1]), type number) then "number" else "not" otherwise "not"
Peter's method works if the choice is AAA/111 but this one tests for A11 and 1BC as well

SSRS takes out leading zero if the Customer Ref contains leading zero

I have the following situation of running SSRS report with Report Builder 3.0 (SQL Server 2012).
The data field CustomerRef contains Customer Reference No which may have Cust1234 or 00001234. I want to retain the Cust1234 whereas to trim out the leading zero of 00001234 with below expression.
=IIF(Fields!CustomerRef.Value.Contains("Cust"), Fields!CustomerRef.Value, CStr(Cint(Fields!CustomerRef.Value)))
As a result, Customer Ref No with 00001234 can be changed to 1234. However, all other Custxxxx returns #Error. How do I solve this?
This is not tested but try this
=IIF(Fields!CustomerRef.Value.Contains("Cust")
, Fields!CustomerRef.Value
, CStr(Cint(
IIF(Fields!CustomerRef.Value.Contains("Cust")
,0
,Fields!CustomerRef.Value)
)
)
)
The idea here is that is the field does contain "Cust" then the CINT function sees 0 as the operand rather than the CUst1234 which will fail, even though that but of code will never get executed.
Another option (again untested) is the simpler
=IIF(Fields!CustomerRef.Value.Contains("Cust")
, Fields!CustomerRef.Value
, CStr(VAL(Fields!CustomerRef.Value))
)
As VAL() will try to turn a string into a value by extracting only the numeric parts of the string, it does not fail when presented with a string as an argument.

mutate() and str_replace() function

I'm trying to remove any strings that contains the word "Seattle" in the column named "County" in the table named Population
Population %>%
mutate( str_replace(County, "Seattle", ""))
It gives me an error message.
I suspect you are getting an error because in your mutate you aren't defining what column you're mutating...
Also, I think you will have better success with an if_else statement detecting the string pattern of Seattle using grepl and then replacing the contents. Below is the code I've used for something similar.
Population %>%
mutate(County = if_else(grepl("Seattle", County),"",County))
The grepl will detect the string pattern in the County field and provide a TRUE/FALSE return. From there, you just define what to do if it is found to be true, i.e. replace it with nothing (""), or keep the value as is (County).

carriage returns or new Line with linq

so i have a problem with carriage return I have web page that have a text area and for a report I need to count how many people wrote in this text area that are save in a sql table call sell and column note
so with linq I do
var count_notes = Vmsb.Sell.Where(v => !(v.Note == null || v.Note.Trim() == string.Empty)).Count();
Vmsb is my dbcontext
the problem is when my note just have carriage returns or "\r\n", it count it and that is not what I want
the sql that generate is something like this
SELECT count(note) FROM [dbo].sell AS v WHERE (( NOT (v.[nota] IS NULL OR N'' = (LTRIM(RTRIM(v.[nota])))))
so how can i do to not take in count the "\r\n"
I never was aware of the fact that L/RTRIM in SQL does not remove newline characters. The only way I can think of is
v.Note.Trim().Replace("\r", "").Replace("\n", "")
(sorry Brice, did not see your comment when wrote this)
Of course it is much easier to prevent input like these "empty" strings to enter the database. I would consider a clean up action and adding a gatekeeper to the application.

How to filter datas in OpenERP using domain list

I want to filter recods in OPenERP using domain filter expression
In the recored I have a field of list of users, so i want get the record where the user logged in the list
[(user.id , 'in' , 'user_ids')]
This doesn't work
it return this error :
File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 2356, in search
return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4846, in _search
self._apply_ir_rules(cr, user, query, 'read', context=context)
File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4728, in _apply_ir_rules
rule_where_clause, rule_where_clause_params, rule_tables = rule_obj.domain_get(cr, uid, self._name, mode, context=context)
File "/usr/lib/pymodules/python2.7/openerp/addons/base/ir/ir_rule.py", line 156, in domain_get
query = self.pool.get(model_name)._where_calc(cr, SUPERUSER_ID, dom, active_test=False)
File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4676, in _where_calc
e = expression.expression(cr, user, domain, self, context)
File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 632, in __init__
self.parse(cr, uid, context=context)
File "/usr/lib/pymodules/python2.7/openerp/osv/expression.py", line 759, in parse
field_path = left.split('.', 1)
AttributeError: 'int' object has no attribute 'split'
Please help me.
Your domain syntax is wrong.
It should be [('user_ids', '=' , user.id)]
Each tuple in the search domain needs to have 3 elements, in the form: ('field_name', 'operator', value), where:
field_name must be a valid name of field of the object model, possibly following many-to-one relationships using dot-notation, e.g 'street' or 'partner_id.country' are valid values.
operator must be a string with a valid comparison operator from this list:
=, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right
The semantics of most of these operators are obvious.
The child_of operator will look for records who are children or grand-children of a given record,
according to the semantics of this model (i.e following the relationship field named by
self._parent_name, by default parent_id.
value must be a valid value to compare with the values of field_name, depending on its type.
Domain criteria can be combined using 3 logical operators than can be added between tuples: '&' (logical AND, default), '|' (logical OR), '!' (logical NOT).
These are prefix operators and the arity of the '&' and '|' operator is 2, while the arity of the '!' is just 1. Be very careful about this when you combine them the first time.
Here is an example of searching for Partners named ABC from Belgium and Germany whose language is not english ::
[('name','=','ABC'),'!',('language.code','=','en_US'),'|',('country_id.code','=','be'),('country_id.code','=','de')]
The '&' is omitted as it is the default, and of course we could have used '!=' for the language, but what this domain really represents is::
(name is 'ABC' AND (language is NOT english) AND (country is Belgium OR Germany))
In a simple case this is right, BUT if you want to filter current object by its functional field, you'll be very surprised that code in function of this field will not execute; instead fnct_search part of this field will be executed, that will allow you to do various things.
Left part of filter expression is evaluated in context of current object, and right part — in context of inner context (read current user).
Left part is evaluated after right, so you can add a functional field to a user model, make some calculations there, and then receive those calculations on the object's side and take them into account.
See this answer for details: https://stackoverflow.com/a/21336100/674557

Resources