How to get distinct values of Year level in MDX? - mdx

I have a cube Work with two dimensions :
Dimension Date with 3 levels : Day, month and year.
Dimension Task with 2 levels : Task A and Task B.
I want to show tasks (A and B) by year, the problem is that when I execute my query I got duplicate values of the year. I tried using distinct but it didn't work.
Here is my query :
select {[Date].[Annee].Members} ON COLUMNS, {[Task][Task1].Members, [Task].[Task2].Members} ON ROWS from [Work]
And the result I got is :
Execution result
Which is like doing : Select [Date].[1].[1].[2014], [Date].[1].[1].[2015], [Date].[1].[2].[2014], [Date].[1].[2].[2015] and so on
Query
Where the first 1 is the day and the second 1 is the month, it returns results for years of every month and day. That's why I got duplicate years but I can't find how to resolve it.
I just want the results to be more general, I want to have values of tasks done by year.
Thank you in advance!

Usually you’d have a simple year hierarchy in the cube so you could query like this:
SELECT
{[Date].[Annee].[Annee].Members} ON COLUMNS,
{[Task][Task1].Members, [Task].[Task2].Members} ON ROWS
FROM [Work]

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

Group Sql query by month number and year number

I have written a query which is bring following data:
I want to further group it by month and year to bring total quiz and total pass for each month in the result set, I am stuck and i need help with this,
thank you
You can group by multiple columns
select QuizMont, QuizYear, .. aggregate values here
...
group by QuizMont, QuizYear

Count records in each month using Month(dateField) in SQL

I have a large table containing c650,000 records. They are individuals with email addresses and one of the fields is 'dateOfApplication'. I have been asked for a breakdown of how many people signed up in each month.
I'd like the results to look something like
Month Year Total
1 2017 50763
2 2017 34725
And have made a target table in this format to put the results in. I've been able to use Month(dateOfApplication) to get the month component of the date using
SELECT DISTINCT
(SELECT COUNT(1) FROM [UG_Master]
WHERE MONTH([UG_Master].dateOfApplication) = '6') as Total
To return particular months, but don't really know how to get one row for each month it finds.
but don't really know how to get one row for each month it finds.
You can use GROUP BY :
SELECT MONTH([UG_Master].dateOfApplication), COUNT(1)
FROM [UG_Master]
GROUP BY MONTH([UG_Master].dateOfApplication);
If you want year wise months then include year also :
SELECT YEAR([UG_Master].dateOfApplication), MONTH([UG_Master].dateOfApplication), COUNT(1)
FROM [UG_Master]
GROUP BY YEAR([UG_Master].dateOfApplication), MONTH([UG_Master].dateOfApplication);

MDX Calculation Tab

I am new to SSAS and I am trying to write a query in ssas caluculation tab that will show all customers (customername) and items ordered (ItemName) in last 40 days. I am not sure is calculation tab the best option to do this.
I have got only one measure VOLUME and dimension attributes (customername,itemname,officename,shipdate ...) I have got also Date Hierarchy with Year->Q->Month->Date.
I have got this statement that gives me netvolume for specific itemname in last 40 days, but what i am looking for is all customers and items ordered in last 40 days. I do not need measure. ( this 40 days might change to 20 or 60 days)
SELECT
{ [Measures].[NET VOLUME]} ON COLUMNS,
FILTER
(
{[CUBENAME].[SHIPDATE].&[2018-03-23T00:00:00]:[CUBENAME].[SHIPDATE].&[2018-05-01T00:00:00]},
[CUBENAME].[ITEMNAME].&[11# RPC 6411]
) ON ROWS
FROM[CUBENAME]
Try using named query in the DSV and filter based on the date field.

Year wise Average days SQL

Today i have below problem while perform an sql query. Please find below data.
I perform SQL query on my table and get the below resulted output. i perform Group by on ID, Name, Week, Year, Days now i want the Days column as average of All Days based on year column. means there is multiple value of year is exist so i need Avg of Days data in all rows of DAYS for particular row. expected result as per below.
Thanks in Advance!!!
Write in comment if you have any query.
You can use OVER:
SELECT
*,
AVG(Days) OVER (PARTITION BY LEFT(Year, 4)) AvgDays
FROM
Tbl
Note: Just grouped by year (2016)