I have MDX query fetching last 3 months data based on customer names/previous month sales<>0. Please note to calculate previous month sales, i am using parallelperiod in cube calculation hence I keep [Dim EIS Time].[By Fiscal Year].[Period] along with customername. Executing MDX query getting results in row wise where as looking for month wise sales on column wise.
MDX query::
select
{[Measures].[Sales]} on columns,
Filter((except(
[Dim Customer].[CustomerName].[CustomerName].MEMBERS,
{[Dim Customer].[CustomerName].&[NA],[Dim Customer].[CustomerName].&[UNKNOWN]}),
LastPeriods(3,[Dim Time].[By Fiscal Year].[Period].&[Jul-21])),
abs(round([Measures].[PreviousMonthSales],6))<>0.000000) on rows from [CSIS]
Getting results::
enter image description here
Expected results::
enter image description here
Related
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
This is a question regarding SSAS Cubes, MDX formulas and Power BI.
I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.
So I have this formula which works almost fine if querying in MS Management Studio:
with member [Measures].[Last existing SOCIOS] AS
Max(
EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
iif([Measures].[ACTIVOS] = 0,null,
[Measures].[ACTIVOS])
)
select {[Measures].[Last existing SOCIOS]} on columns,
[DIM FECHA].[MES NOMBRE].members on rows
from [cubo_Compromisos]
where [DIM FECHA].[AÑO].&[2018]
I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.
In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:
If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:
Does anyone know the right MDX function to use or an alternative?
Edited: 23-11-2018
It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.
The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.
I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:
SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0
FROM [Adventure Works]
To get the last month of the 1st quater (I used example from microsoft and another post on the subject )
I've one MDX query where i want to show each of my product month wise count and along with that want to show YTD, MTD, WTD etc.
I've first created following MDx query on Adventure Works which give me YTD but its shows each months. instead i need output as below and I want to provide current month+year(Mar 2015) in MDX filter or where clause
EXPECTED Results:
Category YTD
--------- ------
Bike 4500
Accessories 78000
Clothing 8900
Can you please correct below MDX query to get above results sets
SELECT
{
([Product].[Category].CHILDREN,[Measures].[Order Quantity])
} ON 0,
{
YTD([Date].[Calendar].[Month].[August 2008])
} ON 1
FROM [Adventure Works];
or i've built another MDX query which give same results either one should be corrected to show above EXPECTED results.
SELECT
{
([Product].[Category].CHILDREN ,[Measures].[Order Quantity])
} ON Axis(0),
{
PERIODSTODATE([Date].[Calendar].[Calendar Year],[Date].[Calendar].[Month].[August 2008])
} ON Axis (1)
FROM [Adventure Works];
I don't think I have the same version of the AW cube as you (or what version of SSAS you are using), but try this. In the 2014 multidimensional cube, I have to change the measure to Order Count rather than quantity and change the date to March 2012 to get data back.
WITH MEMBER [Date].[Calendar].[CalendarYTD] AS
Aggregate(
YTD([Date].[Calendar].[Month].[March 2015])
)
SELECT
[Date].[Calendar].[CalendarYTD] ON COLUMNS,
[Product].[Category].Children ON ROWS
FROM
[Adventure Works]
WHERE
[Measures].[Order Quantity]
I want to create a member based on this problem
I have a Product A being sold
I want to find the largest range of consecutive days without sale
example:
days 1,2,3 the product not sale, after that,it sold for 15 consecutive days, at 19th day it didnt sell for 2 days and after that it sold every day until the end of the month
so my maximum days without sale was 3
The following query delivers in the Microsoft sample cube Adventure Works what you want:
WITH Member Measures.[days without sales] AS
IIf( [Measures].[Internet Sales Amount] > 0
, 0
,(Measures.[days without sales], [Date].[Calendar].CurrentMember.PrevMember) + 1
)
Member Measures.[Max days without sales] AS
Max( [Date].[Calendar].[Date].Members
,Measures.[days without sales]
)
SELECT { [Measures].[Max days without sales] }
ON COLUMNS
FROM [Adventure Works]
WHERE [Product].[Product].&[486]
The measure days without sales is defined recursively, and returns how many days up to and including the current member of the [Date].[Calendar] hierarchy there was no sales. You may need to adapt the criteria for "without sale", bearing in mind that in MDX, numerical comparisons treat NULL as 0 - which is different from SQL.
This measure only works correctly if there is a member in this hierarchy for each day, i. e. there are no gaps in this hierarchy. And actually, the definition is more general than just working for days: If you use months for the [Date].[Calendar].CurrentMember, it would give you the number of months without sales, etc. It works with each level of the hierarchy.
The measure Max days without sales does not contain the product in its definition, it delivers the maximum days for whatever is in context (in this case the product in the WHERE clause).
Please note that - as actually there is a loop over all days in the [Date].[Calendar] hierarchy when calculating Measures.[Max days without sales], and within that the recursion again iterates along the previous days, and all this for each cell in the result set - this may be slow for large reports.
I have a query:
select non empty
order ([Item].Children
,([Measures].[Total Line Value]
,[January 2010])
,DESC)
on Columns,
non empty
[January 2010]
on Rows
from [Sales Analysis]
where [Measures].[Total Line Value]
This query shows, in order from highest to lowest, the total sales a particular item has made for the month January 2010. What I would like to do is show the total sales an item has made between 2 specified dates, say January 2010 - March 2011. It just has to be the total value and not the value for each month. Any help would be appreciated, thanks.
Use "WITH" statement to declare new measure
Sum({[Your dim-n].[January 2010]:[Your dim-n].[March 2011]}, [Measures].[Total Line Value])
Use this new measure on the axis Rows and remove WHERE clause.
p.s. I can't test it now, so I can make a mistake :).