I am trying to fill MDX query result to a datatable. Query is generating dynamically. When i fill datatable column header like [Dim Date].[Day].[Day]. I need it Log Date.
Is there any way to change column header ? I mean, in TSQL we using
select firstName [User] from users
Is there any way to achieve this ?
Thanks in advance
You can do this on the SQL side like this:
WITH mdx as (
<your MDX query>
)
SELECT [[Dim Date]].[Day]].[Day]]] as [Log Date]
...
FROM mdx
The escaping rules of square brackets make this a bit strange: You have to double all closing square brackets.
You can get this slightly more easy, avoiding the square bracket quoting in the rename action by using
WITH mdx([Log Date], ...) as (
<your MDX query>
)
SELECT [Log Date], ...
FROM mdx
enumerating the desired column names after the CTE name "mdx".
Related
Based on below formula, [Yesterday] variable is holding last date value but at run time it is not returning any result.
What should be the right syntax here?
=Sum([Total Amount]) Where ([Booking Date] = [Yesterday])
Having all the code would be helpful, but with the info we have I would recommend removing the brackets and leaving the select like this:
where "BookingDate" = Yesterday;
I am attempting to set a conditional format for one of the fields in my SSRS report. Basic formatting which would change font color. This is my original expression in report builder:
=IIf(Fields!delta.Value <
IIf("ex1"=Fields!ID_name.Value
,0.95
,IIf("ex2"=Fields!ID_name.Value
,0.988
,0
)
)
,"Red"
,"Black")
However, I have to do this for over a 100 different "ID_name" values which all share common "delta" values.
I was wondering if there is something similar to the IN clause in SQL that would allow me to paste all the "ID_name" values inside ('','','') format so it would be much easier? Something like this:
=IIf(Fields!delta.Value <
IIF(Fields!ID_name.Value IN ('ex1','ex2','ex3','...')
,0.95
,IIF(Fields!ID_name.Value IN ('ex4','ex5','ex6','...')
,0.988
,0
)
)
,"Red"
,"Black")
I tried the IIf(InStr() method but my "ID_name" share similar names with others that have different delta values so a contains clause would not work.
Is this possible? Appreciate any and all input! Thanks!!
You can do this but you'll need to wrap your text values in some kind of delimiter that won;t appear in your values to check like [ex1][ex2] etc..
You can use the contains method but it needs to be opposite way you would do a typical IN statement. Something like this..
IIF ("[ex1][ex2][ex3]".Contains("[" & Fields!ID_name.Value & "]"), 0.95, FalseBitHere)
Of course you can just use a comma or whatever you like as long as it wont; appear in your actual values to test.
Currently if I run MDX queries I get the formatted values like
123.456.789,01
What I want to achieve is that (period) is used as a decimal separator and (comma) as a thousands separator.
Is there any way to specify the separators/culture globally for all queries?
FORMAT_STRING is the standard way of altering formats: https://msdn.microsoft.com/en-us/library/ms146084.aspx
It can be implemeted within an mdx script like this:
WITH [Measures].[aMeasureFormat] AS
[Measures].[aMeasure]
, FORMAT_STRING = "#,##0.0"
SELECT
{} ON 0,
[Measures].[aMeasureFormat] ON 1
FROM [yourCube];
too late but it is probably:, LANGUAGE=1034, FORMAT_STRING="$#,##0.00"
will set apropriate code page.
I have a Pentaho CDE project in development and i wanted to display a chart wich depends on several parameters (like month, year, precise date, country, etc). But when i want to "add" another parameter to my query, it doesn't work anymore... So i'm sure i'm doing something wrong but what ? Please take a look for the parameter month for example :
Select_months_query : (this is for my checkbox)
SELECT
"All" AS MONTH(TransactionDate)
UNION
SELECT DISTINCT MONTH(TransactionDate) FROM order ORDER BY MONTH(TransactionDate);
Select_barchart_query : (this is for my chart, don't mind the other tables)
SELECT pginit.Family, SUM(order.AmountEUR) AS SALES
FROM pginit INNER JOIN statg ON pginit.PG = statg.PGInit INNER JOIN order ON statg.StatGroup = order.StatGroup
WHERE (MONTH(order.TransactionDate) IN (${month}) OR "All" IN (${month}) OR ${month} IS NULL) AND
/*/* Apply the same pattern for another parameter (like year for example) *\*\
GROUP BY pginit.Family
ORDER BY SALES;
(Here, ${month} is a parameter in CDE)
Any ideas on how to do it ?
I read something there that said to use CASE clauses... But how ?
http://forums.pentaho.com/showthread.php?136969-Parametrized-SQL-clause-in-CDE&highlight=dynamic
Thank you for your help !
Try simplifying that query until it runs and returns something and work from there.
Here are some things I would look into as possible causes:
I think you need single quotes around ${parameter} expressions if they're strings;
"All" should probably be 'All' (single quotes instead of double quotes);
Avoid multi-line comments. I don't think you can have multi-line comments in CDE SQL queries, although -- for single line comments usually works.
Be careful with multi-valued parameters; they are passed as arrays, which CDA will convert into comma separated lists. Try with a single valued parameter, using = instead of IN.
Heres the query which is giving the issue
select * from
(select user,logdate,[in time],[out time],[worked time] from tmp_phys_table) as sr1
PIVOT
(SUM([worked time]) FOR [LOGDATE] IN ([1])) AS TMPQ
I am unable to understand what the issue is. I was doing pivot as I wanted to make the rows into columns.
I want the output in the below format. The image is the one which I had created in excel for the visualization of data for my report purposes,the same I want in sql,but I am not getting the idea for how to go about the dates hence the query which I had written and which is giving the above error
No column was specified for column 1 of 'sr1' for pivot function
I think your issue is the use of a reserved word in you field name; User is a reserved word, you will need to alias it though I would highly recommend changing the field name.
SELECT *
from (SELECT user As Usr,logdate,[in time],[out time],[worked time]
from tmp_phys_table) as sr1
PIVOT (SUM([worked time]) FOR [LOGDATE] IN (1)) AS TMPQ
NOTE: I have not tested this, I am just going off what stands out as the issue
I would also strongly suggest changing some of your other columns so they do not have spaces in, as you have correctly typed they require square brackets, which will become frustrating over time.