I have two parameters: 'from month' and 'to month'. I would like to show data between those months. This is my situation:
with member [Measures].[Ordercount Y-1] as '([Year].PrevMember, [Measures].[Ordercount])'
member [Measures].[Growth] as IIF([Measures].[Ordercount Y-1] >0,
[Measures].[Ordercount]/[Measures].[Ordercount Y-1] *100,0)
select {[Measures].[Growth]} ON COLUMNS,
NON EMPTY {[Year].[" +year+ "]} ON ROWS
from [Ordercube]
Its a dialchart, I want to show the % of sales compared to last year in combination with a range between months.
In SQL it would be easy: Where month >= frommonth and month <= tomonth.
Since you can only slice once in a MDX query I don't know what to do.
I hope someone can help me.
Thanks in advance
Actually, you'd find that SQL wouldn't be quite as easy if the months weren't both in the same year :)
Either way, what you're looking for is something like this:
select NON EMPTY {[Measures].[Quantity]} ON COLUMNS,
NON EMPTY [Markets].Children ON ROWS
from [SteelWheelsSales]
where {([Time].[2003].[QTR1] : [Time].[2004].[QTR2])}
This query was written against pentaho's data warehouse. I haven't the faintest clue what your data wharehouse looks like so I don't know what to use in the time dimension for your query, but it's the ([Time].[2003].[QTR1] : [Time].[2004].[QTR2]) syntax you're looking for, I think.
(disclaimer: I'm one of the CDF core developers, but my MDX sucks)
EDIT: In this particular case (Range Operator Reference) the reference site isn't particularly explicit, but the MSDN reference site for MDX is pretty good, so here's the general MDX Reference Site.
Related
I have no idea how to do it in mdx as I have only worked in sql but how do I translate this query from sql to mdx?
select monthname, sum(sales) sales
from table
where dt between 20190315 and 20220204
group by monthname;
Thank you for your attention and help.
Be careful of assuming that SQL and MDX can be translated back and forth. The nature of multi-dimensional databases means that the basic concepts which apply to the two query languages are very different.
Sometimes you can get similar answers, of course. In your case, the following MDX would give the sort of thing you were after...
SELECT
{[All Time].[2019].[March]:[All Time].[2022].[February]} ON ROWS,
{[Measures].[Sales] ON COLUMNS
FROM [Cubename]
... although this would look at 20190301 to 20220228 which is not exactly what your SQL query did.
I am having a hard time trying to find something that would be equivalent to YEARFRAC (Excel) for Teradata. I messed around with the below, but want I want it to display the fraction of the year. So instead of 37 I would want to see 37.033. If possible would like it to account for leap years so wouldn't want to just divide it by 365. Any help would be greatly appreciated!
SELECT (CURRENT_DATE - CAST('1985-05-01' AS DATE)) YEAR
There is no direct function to get the desired output.
Excel YEARFRAC method uses different logic to calculate the output based on the optional parameter basis.
Syntax YEARFRAC(start_date, end_date, [basis])
Considering the basis parameter as 0 or omitted, you can achieve it in Teradata using below query.
SELECT
DATE'2022-05-13' AS Till_Date
,DATE'1985-05-01' AS From_Date
,(Till_Date - From_Date) YEAR TO MONTH AS Year_To_Month
,EXTRACT(YEAR FROM Year_To_Month)
+EXTRACT(MONTH FROM Year_To_Month)*30.0000/360
+( EXTRACT(DAY FROM Till_Date)-EXTRACT(DAY FROM From_Date))*1.0000/360 AS YEARFRAC
The basis parameter with 0 or omitted uses a 30/360 format to calculate the difference.
You can find more details about the YEARFRAC logic in below link.
https://support.microsoft.com/en-us/office/yearfrac-function-3844141e-c76d-4143-82b6-208454ddc6a8
I apologize if this has been covered somewhere, but I haven't found anything that quite meets my specific needs. In PeopleSoft Query Manager, we are trying to build a report that projects depreciation 5 or so years into the future. We want the columns to be the fiscal year and we want the returned values to be the annual depreciation by asset by business unit.
What we've tried so far is creating an aggregate expression that will sum the asset depreciation. This simple expression works in and of itself as it sums the monthly depreciation by asset. However, what we'd like to do is create 5+ columns with 5+ of these aggregate sum expressions, based on the fiscal year. So the first "numerical data" column would show 2019's depreciation, the second would show 2020's and so on.
Now, let me provide a disclaimer and say I'm an accountant and not a code person, so I'm less than a novice here. But we've tried embedding the aggregate sum function with case or decode and we have been unable to get it to work with any such conditional type functions. However, surely there must be a way? (For potential further clarity, if we had the data in excel we would use something like =SUMIFS(Depreciation column, fiscal year column, 2019) and then repeat that for the remaining years. We want to get this same result directly from the query though).
Below, we have two codes. The simple one that works but doesn't provide what we need exactly and the one with conditional functions that we can't quite get to work.
`SELECT A.BUSINESS_UNIT, A.ASSET_ID, sum( A.DEPR)
FROM PS_DEPR_RPT A
WHERE ( A.BOOK = 'CORPORATE'
AND A.BUSINESS_UNIT = '50226')
GROUP BY A.BUSINESS_UNIT, A.ASSET_ID
HAVING ( sum( A.DEPR) <> 0)`
`SELECT A.BUSINESS_UNIT, A.ASSET_ID, CASE
WHEN A.FISCAL_YEAR = 2019 THEN sum( A.DEPR)
END
FROM PS_DEPR_RPT A
WHERE ( A.BOOK = 'CORPORATE'
AND A.BUSINESS_UNIT = '50226')
GROUP BY A.BUSINESS_UNIT, A.ASSET_ID
HAVING ( CASE
WHEN A.FISCAL_YEAR = 2019 THEN sum( A.DEPR)
END <> 0)`
The first one works fine but does not have the necessary fiscal year information. Now, yes, we can use the fiscal year field as a criteria and then build an excel file using sumifs or other such formulas. But we really would like to not have to manipulate the data in excel, and it seems like we should be able to create this in PeopleSoft Query Manager.
Obviously, the second one looks off (I imagine people who are knowledgeable about SQL are banging their heads), and we get this error:
Error in running query because of SQL Error, Code=979, Message=ORA-00979: not a GROUP BY expression (50,380)
(In my preliminary research, it seems like the group by expression error was a common recurrence when using these conditional functions with aggregate functions).
Lastly, please keep in mind that I personally don't have the ability to create SQL that I could put into the system. The SQL is what query manager generates and my only ability to change it is by using expressions and criteria changes.
EDIT for current results and preferred results:
What It Looks Like As Is
What We Want It To Look Like
Thanks in advance!
How can i ignore repeated days values using MDX ?
For example, from this:
12/1/1997
12/2/1997
12/3/1998
12/4/1999
To this:
12
I'm already tried use Distinct, but i'ts like they still considere as unique dates.
SELECT
{} ON COLUMNS,
DISTINCT([Time].[Weekly].[Day].Members) ON ROWS FROM [Sales 2]
These are different values and your cube treats them as such. I guess you can do some mimicing of that behavior with MDX by creating a MEMBER which has just the date part and doing distinct on that member. Something like:
WITH MEMBER [MonthPart] AS LEFT([Time].[Weekly].[Day].currentMember, 2)
SELECT
{} ON COLUMNS,
DISTINCT([MonthPart].Members) ON ROWS FROM [Sales 2]
Something like that but I am not sure for the correct syntax.
The proper way to fix that though is to create a good Time Dimension for your dates in the cube. There you can define hierarchies, levels and just take the [Month] part which will give you what you want (and will be much faster than writing complex MDX queries)
Suppose ,I have a table which has all the billing records. Now I want to see the sales trend for a user given time duration group by each 3 days ...what should be the sql query regarding this?
please help,Otherwise I am gone ...
I can only give a vague suggestion as per the question, however you may want to have a derived column with a standardised date (as per MS date format, just a number per day) that you could then use a modulus (3) on so that days are equal per 3 day period. You can then group and aggregate over this column to get the values for a 3 day period. Obviously to display the date nicely you would have to multiply back and convert your column as well.
Again I'm not sure of the specifics, but I think this general idea could be achieved to get a result (may well not be the best way so it would help to add more to the question...)