I'm trying to do a query that calculate the sum of measures in a specified range of time in a period.
WITH MEMBER
[Measures].[calc] as
SUM (
{ [date.time].[day].CurrentMember.LEAD(-30):[date.time].[day].CurrentMember },
[Measures].[my_value]
)
SELECT NON EMPTY {[Measures].[calc]} ON COLUMNS,
{[date.time].[day].[2014-07-21 00:00:00.0]:[date.time].[day].[2016-07-21 00:00:00.0]} ON ROWS
FROM [my_cube]
this code works, it return to me the sum of the current member plus the last 30 members before it,but I'm looking for a way to subtract instead members(days in this case), months, because not all months have 30 days, there's some way to do this? because if there isn't, for each day of my interval will be needed to do one request to do what I want in my java code
If you you have a hierarchy with day-month relation (say, calendar), you can use the day's parent:
WITH MEMBER
[Measures].[calc] as
SUM (
{ [date.time].[calendar].CurrentMember.LEAD(-30):[date.time].[calendar].CurrentMember },
([date.time].[calendar].CurrentMember.Parent.Lag(1),[Measures].[my_value])
)
SELECT NON EMPTY {[Measures].[calc]} ON COLUMNS,
{[date.time].[day].[2014-07-21 00:00:00.0]:[date.time].[day].[2016-07-21 00:00:00.0]} ON ROWS
FROM [my_cube]
If you don't have the hierarchy, you can use the day key to regenerate it into the month key:
WITH MEMBER
[Measures].[calc] as
SUM (
{ [date.time].[day].CurrentMember.LEAD(-30):[date.time].[day].CurrentMember },
(StrToMember('[date.time].[month].[' + left([date.time].[day].CurrentMember.Properties('Key'),7) + ']').Lag(1),[Measures].[my_value])
)
SELECT NON EMPTY {[Measures].[calc]} ON COLUMNS,
{[date.time].[day].[2014-07-21 00:00:00.0]:[date.time].[day].[2016-07-21 00:00:00.0]} ON ROWS
FROM [my_cube]
Related
I need to find out the number of days in Month based on Time dimension. Time dimension is Month when Jan is selected it has to return 31 as value.
If you have Time dimension and Time hierarchy, this should work:
WITH MEMBER measures.NumOfDays AS
Count
(
Descendants
(
[Time].[Time].CurrentMember,
,LEAVES
)
)
SELECT Measures.NumOfDays ON 0,
[Time].[Time].Month on 1
FROM [MyCube]
The below sample shows how to get the count.
Please note the below query only show the idea how to do this. Your cube will note have these attributes you you need to replace them
with member
measures.t as Count(([Date].[Month of Year].&[1],[Date].[Day of Month].[Day of Month].members))
select {measures.t}
on columns
from [Adventure Works]
I have the following data:
Basically a normalized time series by country.
My problem is, not all countries data ends on the same day.
I am trying to obtain column "DateCount", which would give me --for the date in that row -- the rowcount for ALL countries.
So for Jan18-to-Mar18 I would have 2 entries at each date (Italy and USA), but for April I would have only one (USA).
Any input on how to do this?
Many thanks!
DAX formula:
DateCount =
CALCULATE (
DISTINCTCOUNT ( Table[Country] ),
ALL ( Table[Country] ),
VALUES ( Table[Date] )
)
Result:
How it works:
It's a common pattern in DAX: Unfilter/Refilter. We change filters by first unfiltering countries (ALL) so that we can access all of them, then re-filter countries with the list of dates (VALUE supplies dates visible in current context). After desired filter context is established, you just need to count distinct countries.
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.
In my cube I have dimension calculated in the following way:
Sum(PeriodsToDate([Year].[Data].[(All)]), [Quantity])
how to change this formula to calculate the sum only to the current day?
The time dimension contains data on future years.
Depending on what you want to do, try the following:
For the sum from start until today:
SUM( { NULL : StrToMember('[Year].[Data].&[' + FORMAT(NOW(),'yyyyMMdd') +']') }, [Quantity] )
Depending on your representation of the day you may need to change the 'yyyyMMdd'-part of FORMAT, for me it is 20180321 for today as of writing this.
For the sum from start until the 'current' selected day (on the rows or the filter):
SUM( { NULL : [Year].[Data].currentmember }, [Quantity] )
I want to create a calculated member. I have a time dimension hierarchy" YQM", which has Year/Quarter/Month. The calculated member should find YTD till the current month. However, the value of current month will come from database.
I have created a attribute, "CP" which returns the current month value.
Please tell me how to create the calculated member. Please note "CP" is not in the same hierarchy YQM.
I don't understand why you are using Aggregate. So, I will assume that it is there for some purpose, which you have't clarified. Now, if the members of [YQM].[Month] and [Dim].[CP] are of the same format, then you can try the code below:
Aggregate(
PeriodsToDate([Dim].[YQM].[Month].MEMBERS,
FILTER([Dim].[YQM].[Month].MEMBERS,
[YQM].[Month].CURRENTMEMBER.member_value = [Dim].[CP].FirstChild.member_value)
)
)
Why not try playing with the function YTD. The following should give you the monthly amount in the first column of data and then the YTD amount in the next column:
WITH MEMBER [Measures].[YearToDate] AS
AGGREGATE(
YTD()
,[Measures].[someMeasureInCube]
)
SELECT
{
[Measures].[someMeasureInCube],
[Measures].[YearToDate]
} ON 0,
[Dim].[YQM].[Month].MEMBERS ON 1
FROM [yourCube]