I am trying to get the data fromt the present calender week to the previous two weeks. If I specify the date range as parameters in the MDX query, the table gets filled up properly.
SELECT NON EMPTY {[Measures].[planned_cumulative],[Measures].[Last Forecast CW] } ON COLUMNS,
NON EMPTY { ([Project].[Projekt-Task].[Task].ALLMEMBERS* { [Date].[Date - CW].[Week].&[2014]&[201420] : [Date].[Date - CW].[Week].&[2014]&[201422]})} ON ROWS FROM [DWH]
But if I try and use the lag function, I get an error. Here is the MDX query.
SELECT NON EMPTY {[Measures].[planned_cumulative],[Measures].[Last Forecast CW] } ON COLUMNS,
NON EMPTY { ([Project].[Projekt-Task].[Task].ALLMEMBERS* [Date].[DATECW - CW].[Week].CurrentMember.Lag(2) ) } ON ROWS
FROM [DWH]
Your first query (quite rightly) identifies a range of two weeks, by using two members from the dimension separated by a colon i.e. [Week X] : [Week Y].
Your second query uses the LAG function, which will return a member on your dimension, not a range of members.
Try this:
SELECT NON EMPTY {[Measures].[planned_cumulative],[Measures].[Last Forecast CW] } ON COLUMNS,
NON EMPTY {[Project].[Projekt-Task].[Task].ALLMEMBERS * TAIL([Date].[Date - CW].[Week],3) } ON ROWS
FROM [DWH]
Also, your first query refers to [Date].[Date - CW].[Week] whereas your second query uses [Date].[DATECW - CW].[Week]. I have gone with the first option as you say that query works.
Let me know if that helps.
Ash
EDIT: Apologies for that. I have amended the query to use the TAIL function, which will give you a number of tuples from a set starting at the end and working backwards. So with TAIL ({Set Of Weeks},3) this should give you the current week and the previous two weeks. I have tested a similar query on my cube and it seems produce the expected results.
Hope that solves it for you.
Ash
Related
How can do I write an array formula in such a way that both following factors apply:
Results give me the names of sales that have either TRUE OR FALSE next to it in a different column/sheet.
Results are sorted chronologically based on the date that is connected to each sale. Each sale has a different date next to it. This can be found in the same sheet as where the "TRUE OR FALSE" result is displayed. Column with the dates is called "AY:AY". I use an indirect formula to target the correct sheet within the spreadsheet.
I currently only have the first criteria implemented, don't know how to do the 2nd one.
Since the raw data is not ordered I need this to happen when I use the Index Match Array formula. So far I have this formula in my Google Sheets spreadsheet.
=ArrayFormula(iferror(index(indirect("'"&$B$5&" 2023'!c:c");small(if(TRUE=indirect("'"&$B$5&" 2023'!ca:ca");row(indirect("'"&$B$5&" 2023'!ca:ca"))-row(indirect("'"&$B$5&" 2023'!$ca$1"))+1);row(1:1)));""))
I know I could use the Index Array formula below with multiple criteria, but don't know how to implement the date component.
INDEX(indirect("'"&$B$5&" 2023'!c:c");SMALL(IF(COUNTIF(_______)*COUNTIF("true"; indirect("'"&$B$5&" 2023'!CA:CA"); ROW(indirect("'"&$B$5&" 2023'!A:CA"))-MIN(ROW(indirect("'"&$B$5&" 2023'!A:CA"))+1); ROW(indirect("'"&$B$5&" 2023'!A1));COLUMN(indirect("'"&$B$5&" 2023'!A1))
Thanks in advance.
A query like this could help?
=QUERY(INDIRECT("'"&$B$5&" 2023'!C:CA"),"SELECT C,AY WHERE CA = TRUE order by AY")
I am using an ARRAYFORMULA to extract unique values from a list of names and total up a second column for each of those names.
Here is some example data and the ARRAYFORMULA I am using
Example Data
ARRAYFORMULA in cell E3
=ARRAYFORMULA({{unique(B3:B11)},{sumif(B3:B11, (unique(B3:B11)),C3:C11)}})
What I would like to do is filter out those names where the total number of tokens is zero - i.e. I would like Peter to be filtered out of the list because he has a net total of zero Tokens.
[I'd also like to have Peter, and any others, displayed in a separate list, but I guess if you can help me crack this first part I can help myself crack the second part]
Is there a way I can achieve what I want with a single ARRAYFORMULA? Is there another (better) way to achieve the same result?
I've bashed my head against this for a while so would be grateful for any help
use:
=QUERY(QUERY({B3:C};
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label sum(Col1)''");
"where Col2 is not null"; )
Query and Filter
=FILTER(QUERY(A2:B10,"select A, SUM(B) group by A"),QUERY(A2:B10,"select SUM(B) group by A") > 0)
You don't need an array formula. The FILTER on the outside of the QUERY takes care of our zero token problem. And the QUERY selects column A and SUM of B and returns the proper names and sums, so that there are no repeating names. We need a second identical QUERY for the FILTER to compare 0s against, Because our QUERY doesn't exist outside of the formula. Every reference you make to the QUERY requires you to perform the QUERY again.
I am trying to get a count of all Unique values listed in Col A, by state and within a date range, for example all records up to the end of April 2018.
I am able to get the count of Unique values by state (result is 2) with the below formula:
{=SUMPRODUCT(1*(FREQUENCY(IF($C$2:$C$14=F10,MATCH($A$2:$A$14,$A$2:$A$14,0)),ROW($A$2:$A$14)-ROW($A$2))>0))}
but I am unable to get the IF function to work with EDATE. I tried the following but I'm getting 0 as the result. The result should be 1.
{=SUMPRODUCT(1*(FREQUENCY(IF(D2:D14="<"&EDATE(G1,1),IF($C$2:$C$14=F10,MATCH($A$2:$A$14,$A$2:$A$14,0))),ROW($A$2:$A$14)-ROW($A$2))>0))}
I am unable to use Pivot as I need to include date range filter. Could someone please look at my code and tell me what I'm doing wrong? I am using CSE with my formulas. Thankyou!
I managed to work it out. EDATE wasn't working so I entered the Month date in cell:G1 then referenced it in the IF formula using "<=" eg: IF(D2:D14<=G1).
Whole array formula is:
`{=SUMPRODUCT(1*(FREQUENCY(IF(D2:D14<=G1,IF($C$2:$C$14=F10,MATCH($A$2:$A$14,$A$2:$A$14,0))),ROW($A$2:$A$14)-ROW($A$2))>0))}
I now receive the correct count of 1, though I have to ensure I have entered the last day of the Month in G1. State is referenced in F10 and count of unique values is in Column A.
My full data set is sourced from multiple documents over 5000 rows each and growing daily so my workbook is quite slow to calculate over 1000 array formulas... but it works!
If anyone knows of a faster (possibly non-array) formula, I would appreciate the advice! Thanks!
I'm very new to Crystal Reports and I've one little problem.
I'll be quick and on point.
The columns are as follow:
2016-01-05, 2016-01-06, 2016-01-07, 2016-01-08, 2016-01-09 (list goes on till end of year)
These dates come from Database field called NextDueDate and it populates the report with all the dates.
My question, is it possible to combine these rows or group them by weeks or perhaps by month?
Result I'm looking for is:
2016-01 (All january days combined here) or something like maybe even just January etc.
NextDueDate field is type string by the way.
Also, I'd like to do this without getting involved in the actual database itself due to specific reasons.
you can use this simple formula as
#year_month = left ({NextDueDate},7);
create formula as year_month
and put left ({NextDueDate},7); in formula editor click on save.
now you can see this formula under formula field in field explorer.
Drag this one to your detailed section.
You can group the result based on this formula.
OR
user these formula
#year_month = left ({NextDueDate},7);
#monthOnly = right( #year_month , 2);
#FullMonthName = if #monthOnly = '01' then 'January'
else if {#month} = '02' then 'February'
........................................
else 'December';
I was hoping someone could help me with this problem.
In a sum type measure, i need to know if this measure has been pivoted with my time dimension. If is not, the measure must show the sum of the last day. In other case, the measure must show the sum of the day with has been pivoted.
I have the measure "Users", if this measure hasn't been pivoted with my time dimensiĆ³n, it shows the sum of all users of all the time. For example it shows: 5,000,000. When it has pivoted with the time dimension, it shows de users from the day. For example: 100,000 for today 21/05/2015.
When this measure hasn't been pivoted with the "time" dimension, the measure must show 100,000 and not the total sum of all days.
I've been trying white some MDX formulas but i have not found some solution for this.
Thanks
I've interpreted this as when pulling your Users measure without pivoting on the Time dimension you would prefer to see the value that corresponds to the current date.
This can be achieved by modifying the Default Member of your Time dimension. Setting the default date to this last available date
Within your Dimension in SSAS, browse to the Dimension Structure tab and select the attribute which represents the key column (ie. the Usage property is set to Key for only one column)
Within the Properties pane (strike F4 if you do not see it already to open it) select the Default Member property, then select the elipses (...)
The Set Default Member - [Dimension Name] pane will have 3 options, select the last Enter an MDC expression that specifies the default member
Use ONE of the following expressions
TAIL([Date].[DateAttribute].Members).Item(0)
TAIL(NONEMPTY([Date].[DateAttribute].Members)).Item(0)
TAIL(EXCEPT([Date].[Date].Members,{[Date].[Date].[Unknown]}),1).Item(0)
In my case I used the last as I only want to exclude my UnknownMember member
Now when you pull the measure down the value will be for the last date in your cube. This will affect other cubes built on this date dimension of course.