Data view with parameters in Datazen - ssas

I am designing a dashboard with Datazen. I need to define data view with parameters. Where statement of mdx query as follows
where (
STRTOMEMBER("[X].[X NAME].[" + {{ #XParam }} + "]"),
STRTOMEMBER("[Y].[Y NAME].[" + {{ #YParam}} + "]")
)
and I defined #XParam and #YParam. My query works when I go next step and get result as expected. But problem occurs when data view added from Datazen Designer to build charts. How can I solve this problem?
Exception: System.ArgumentException: Value does not fall within the expected range.
at Windows.UI.Xaml.Data.Binding.put_Path(PropertyPath value)
at ComponentArt.WinRT.DataVisualization.DataGrids.GridView.GenerateColumn(String name, String bindingPath, Type type)

Try this:
where (
STRTOMEMBER("[X].[X NAME].[" + '{{ #XParam }}' + "]"),
STRTOMEMBER("[Y].[Y NAME].[" + '{{ #YParam }}' + "]")
)
You missed single quotes and the last space in the second param.

Related

Laravel Migration: Combine multiple values in a new colum

i'm trying to make a migration using Laravel. The idea is to get the values of columns 'code' and 'id' in different tables, and merge them into a column 'name' with '-' separators.
So in part it is a SQL problem.
Currently i'm trying something like this.
First migration to create the new column 'name'
public function up()
{
Schema::table('work_order', function (Blueprint $table) {
$table->string('name')->nullable();
});
}
(works just fine)
And second migration to populate the new column with values
class AlterColumnNameWorkOrder extends Migration
{
public function up()
{
$company_code = DB::statement("SELECT code FROM company");
$campaign_code = DB::statement("SELECT code FROM campaign");
$work_order_number = DB::statement("SELECT id FROM work_order");
DB::statement("UPDATE work_order SET name = $company_code + '-' + $campaign_code + '-' + $work_order_number");
}
and i'm getting this error
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "-"
LINE 1: UPDATE work_order SET name = 1 + '-' + 1 + '-' + 1
I'm thinking that i'm not getting the values but the index instead.
UPDATE: I solved the problem by replacing + for ||. But now in column 'name' all my values are "1-1-1". The values are not being represented. What am i missing?
UPDATE2: I noticed that i was defining an unnecessary variable $work_order_number. As it belongs to the same table to be updated. So I removed it and put the field "id" directly in the statement.
DB::statement("UPDATE work_order SET name = $company_code || '-' || $campaign_code || '-' || id");
Now the third value is shown correctly. And this reduces my problem to getting values from another table into an column.
First of all, you shouldn't use migrations to populate the database. Read the documentation about seeds.
Also, i think your select query is wrong. Isn't you missing a where clause?
Run php artisan migrate to migrate your database, then create a new seed, and add this to the run method:
$company_code = DB::table('company')->select('code')->where('id', some_id)->first()->code;
$campaing_code = DB::table('campaing')->select('code')->where('id', some_id)->first()->code;
$work_order_number = DB::table('work_number')->select('id')->where('id', some_id)->first()->id;
$sql = "UPDATE work_order SET name = concat('{$company_code}', '-', '{$campaign_code}', '-', '{$work_order_number}');
DB::statement(DB::raw($sql));
Now, just run php artisan db:seed --class=YourSeedClassName and it should work.

GREL: qq about Templating Export and Nulls (Open Refine)

There is some expression more elegant than this to avoid printing NULLs and words "NULL"?
By reading the Open Refine's docs https://github.com/OpenRefine/OpenRefine/wiki/General-Refine-Expression-Language I have done this bellow, but feels odd and complex.
Cheers.
{
"rows" : [
{{ if(isNull(cells["supplierID"].value),
"",
" \"supplierID\" : " + jsonize(cells["supplierID"].value)
)}},
{{ if(or(isNull(cells["homePage"].value), cells["homePage"].value == "NULL"),
"",
" \"homePage\" : " + jsonize(cells["homePage"].value)
)}}
]
}
Usually I'd aim to make the column consistent (i.e. either contain a null value in all cases or the string "NULL" in all cases, but not a mix of these) before doing an export. So you could run a transform on the column first like:
if(value=="NULL",null, value)
If you were to do this first, then in the export template you can use:
forNonBlank(cells["homepage"].value,v," \"homePage\" : " + jsonize(v),"")
However, if you don't want to make this change in the data for some reason, you can achieve a slightly more elegant option than the one you have by using the 'coalesce' function (available from OpenRefine 3.0 onwards) which chooses the first non-null value from a list:
{{ if(coalesce(cells["homepage"].value,"NULL")=="NULL",""," \"homePage\" : " + jsonize(cells["homePage"].value)) }}
The coalesce will use the value of cells["homepage"].value if it is non-null, or fall back to using the string "NULL" if cells["homepage"].value is null. So this means that if you feed a cell with content string "NULL" or a cell that has null - the coalesce function outputs the string "NULL" in both cases - which means you then only have to check for the single condition.
coalesce is documented at https://github.com/OpenRefine/OpenRefine/wiki/GREL%20Other%20Functions

PUG / Express Js - Create Array Format in Pug

I am looking to make a array out of this pug template:
each test in profile
= '["' + test.profile_name + '"],'
This currently looks like this:
["Reach First"],
["Test Company"],
["Test Company"],
I want to omit that last comma and make it look like this:
["Reach First"],
["Test Company"],
["Test Company"]
Notice the comma missing at the very end. I am not sure hot to omit that last comma in a loop.
You can include the index in the iteration, and check for it not being the last one. That would probably look something like this:
each test, index in profile
= '["' + test.profile_name + '"]' + (index === profile.length - 1 ? '' : ',')

Can't get delphi SQL LIKE to work with %

I'm doing a school project and need to code a query to filter a dataset to certain variables. All my SQL works fine, except I can't get the LIKE statement to work with %-signs. I believe my syntax is wrong. Can anybody please tell me what I'm doing wrong. Thanks
The code:
qryMovie.SQL.Clear;
qryMovie.SQL.Add('SELECT * FROM Movies');
qryMovie.SQL.Add('WHERE Genre = ' + QuotedStr(genre));
qryMovie.SQL.Add('AND Price BETWEEN ' + minPrice + ' AND ' + maxPrice);
qryMovie.SQL.Add('AND Title LIKE %' + title + '%');
qryMovie.Open;
Error produced:
'Syntax error in query expression 'Genre = 'Action/Adventure'
AND Price BETWEEN 0 AND 200
AND Title LIKE %Star Wars%''
LIKE %Star Wars%
but you need
LIKE '%Star Wars%'
You need to quote % with ':
qryMovie.SQL.Add(' AND Title LIKE ''%' + title + '%''');
Anyway you should use binded parameters instead of concatenating SQL string. It is error-prone and could lead to SQL Injection attacks.

iif blank show zero

I have a visual studio report that I want to state that if a calculation box is blank due to there being no figures available on that particluar project then show zero.
My calculation is :- =((Sum(Fields!TotalCost.Value, "Accrued") + Sum(Fields!TotalCost.Value, "serv1")) /
(Sum(Fields!Quantity.Value, "serv1") + Sum(Fields!Quantity.Value, "Accrued"))
)
And I want to try and include an IIF statement in that to show zero if blank.
Any ideas on how to best achieve my aim?
so far I have got to
=iif((Sum(Fields!TotalCost.Value, "Accrued") + Sum(Fields!TotalCost.Value, "serv1")) /
(Sum(Fields!Quantity.Value, "serv1") + Sum(Fields!Quantity.Value, "Accrued"))
) = "" ,false,0 ) but I am getting a little confused.
Most likely value is not blank string but a Nothing. Try following construct:
=IIf(IsNothing(((Sum(Fields!TotalCost.Value, "Accrued") + Sum(Fields!TotalCost.Value, "serv1")) / (Sum(Fields!Quantity.Value, "serv1") + Sum(Fields!Quantity.Value, "Accrued"))), 0, ((Sum(Fields!TotalCost.Value, "Accrued") + Sum(Fields!TotalCost.Value, "serv1")) / (Sum(Fields!Quantity.Value, "serv1") + Sum(Fields!Quantity.Value, "Accrued")))
It's a bit awkward since you have to repeat the expression twice, to avoid it you may want to write a custom function.