MDX query date range - mdx

I am working pentaho dashboard trying to generate report to get transaction count per day between two date. i am beginner to mdx query below query shows only two date transaction count what i want is range between. i know it how to do it on simple query
SQL Working Query
SELECT
DATE(modified) AS trndate,
COUNT(id)
FROM
log.transaction
WHERE DATE(modified) BETWEEN DATE(${from_date}) AND DATE(${to_date})
GROUP BY
trndate
MDX Query which shows only two date transaction instead i want range between two date
WITH
SET [~ROWS] AS
{[created].[2014-10-01 12:01:53.507787], [created].[2014-10-01 20:34:14.410064]}
SELECT
NON EMPTY {[Measures].[id]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [transaction]

Usually you can use a colon to specify a range
WITH
SET [~ROWS] AS
{[created].[2014-10-01 12:01:53.507787]:[created].[2014-10-01 20:34:14.410064]}
SELECT
NON EMPTY {[Measures].[id]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [transaction]

Related

How to add one more measure in MDX where clause?

Below query is perfectly working and bringing rolling 12 months data for selected measure. Now how do I add one more measure to same MDX query so that query fetch rolling 12 months for 2 measures?
Thanks in advance for your help.
Working query with single measure
select
non empty({lastperiods(12,[Time].[By Fiscal Year].[Period].&[Jul-21])}) on columns,
[Customer].[CustomerName].[CustomerName].MEMBERS on rows
from(
select
([CustomerNamedSet]) on columns
from [CSIS]
where ({[Time].[By Fiscal Year].[Period].&[Jul-21]},
{[Measures].[measure1]})
)
enter image description here
Modified MDX query by adding one more measure in where clause (Not working)
select
non empty({lastperiods(12,[Time].[By Fiscal Year].[Period].&[Jul-21])}) on columns,
[Customer].[CustomerName].[CustomerName].MEMBERS on rows
from(
select
([customerNamedSet]) on columns
from [CSIS]
where ({[Time].[By Fiscal Year].[Period].&[Jul-21]},
{[Measures].[measure1],[Measures].[measure2]})
)
Expected results::
enter image description here

MDX Hierarchy query

I work with Pentaho BI and I am preparing data for simple dashboard. I have records with two level date dimension (year and month). When I do query from saiku:
WITH SET [~ROWS] AS
Hierarchize({{[Date].[Year].Members}, {[Date].[Month].Members}})
SELECT
NON EMPTY {[Measures].[Count]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [data]
Pentaho create a sum for every first month, every second month... (1-12) and sum for each year. I need a sum for every year+month pair. How do I have to edit query?
Actual chart:
Target chart:
I assume you use Pentaho CDE to create a dashboard.
Set up Banded Mode property of MDX query to Classic (instead of Compact).

Date Range issue in MDX SSAS

I have one MDX query.
select [Measures].[Measure1] on columns,
[Locations].[Location].[LocationKey] on rows
from [MeasureLocation]
where
(
{[ServiceDate].[Date].[Date].[01-01-2013] : [ServiceDate].[Date].[Date].[01-01-2014]}
)
Here I gave date range between 01-01-2013 to 01-01-2014. So ideally SSAS should give record for this date range only. But the actual result is for 01-01-2013 to 31-01-2014. So, it's including whole month[31-01-2014].

Calculating a percentage of two "Counts" in SQL in Microsoft Access 2010

I have a Microsoft Access 2010 database of thyroid surgeries. I have a query that counts the number of surgeries in the entire database. I have a second query that counts the number of surgeries performed between certain dates. I created a new query using SQL to calculate the percentage of surgeries in that date range (a percentage of the total surgery number). Here is the code:
SELECT
((select count(ThyroidSurgeryType)
from [Thyroid Surgeries]
HAVING ([Thyroid Surgeries].SurgeryDate) Between #1/1/2011# And #12/31/2012#)/(select count(ThyroidSurgeryType)
from [Thyroid Surgeries])) AS Percentage
FROM [Thyroid Surgeries];
I get .33 (I then set the row format to percentage to get 33%), but I get 6 rows of 33% as opposed to just one. Why is it displaying this way? Thanks
The way you're using inline queries, you're executing the same query per row of the outer query. So if your table has six rows, you'd be executing it six time (and getting the same result for each query, naturally). You can simplify things by removing the outer query and using an iif expression:
SELECT SUM (IIF (SurgeryDate Between #1/1/2011# And #12/31/2012#, 1, 0)) /
COUNT(ThyroidSurgeryType) AS Percentage
FROM [Thyroid Surgeries];

How can I write an mdx query that slices by both a date range and dimension member value

I need to write an mdx query that limits its results by the value of a dimension but also by a date range. I know how to do one or the other but I can't figure out how to do both at once.
This works for the date range:
SELECT {[Measures].[Hours]} ON COLUMNS, [Time Type].[Type].Members ON ROWS
FROM [cube]
WHERE {[Date].[Date ISO].[2013-01-26]:[Date].[Date ISO].[2013-06-25]}
And this works for the member slicer:
SELECT {[Measures].[Hours]} ON COLUMNS, [Time Type].[Type].Members ON ROWS
FROM [cube]
WHERE [Time Type].[Allocation Type].[Direct]
How do I constrain the results by both of these WHERE clause values at the same time? I've tried putting them both in the same WHERE like so:
SELECT {[Measures].[Hours]} ON COLUMNS, [Time Type].[Type].Members ON ROWS
FROM [cube]
WHERE ([Time Type].[Allocation Type].[Direct],
{[Date].[Date ISO].[2013-01-26]:[Date].[Date ISO].[2013-06-25]})
but Mondrian replies with: No function matches signature (, ).
Note that Mondrian does not support subqueries or I would do it that way.
I think I might need to use a filter function on my rows for my member constraint but I need to filter on something that I don't want to display, which I am not sure how to do.
I think crossjoin is the answer like so:
SELECT {[Measures].[Hours]} ON COLUMNS, [Time Type].[Type].Members ON ROWS
FROM [cube]
WHERE CROSSJOIN([Time Type].[Allocation Type].[Direct],
{[Date].[Date ISO].[2013-01-26]:[Date].[Date ISO].[2013-06-25]})
CROSSJOIN creates all the combinations of the 'Direct" member and the dates in my range as tuples for my WHERE slicer. I think this is the right answer.