Trying to get max date grouped by type
hello,
i have a request table with:
request name
request start date
The requests run daily so i have multiple records. In answers i want to display request name and the max(request start date), grouped by request name. Is it possible to due this in answers only? if i must use the repository how do i do it? I'm new to building subject areas.
You can do this in answers only, If you dont have access to RPD.
Sol1: Create a report with two columns request name,request start date. Open pivot table and add request start date to measures and apply Aggregation of Max on date.
sol2: Create a report with two columns request name,request start date, Change the Fx of request start date to max(request start date by request name) . This way table view also show request max date by request names.
Similar Messages
-
In mdx how to get max date for all employees is it posible shall we use group by in mdx
in mdx how to get max date for all employees is it posible shall we use group by in mdx
example
empno ename date
1 hari 12-01-1982
1 hari 13-06-2000
by using above data i want to get max dataHi Hari3109,
According to your description, you want to get the max date for the employees, right?
In your scenario, do you want to get the max date for all the employees or for each employee? In MDX, we have the Max function to achieve your requirement. You can refer to Naveen's link or the link below to see the details.
http://www.sqldbpros.com/2013/08/get-the-max-date-from-a-cube-using-mdx/
If this is not what you want, please provide us more information about the structure of you cube, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support -
Trying to get old data off a g4 tower
Hi- I am trying to get old data off a g4 tower using macbook and firewire but I am not succeeding. My old monitor doesn't seem to work. Any suggestions greatly appreciated. I also have a Gdrive if that might work.
Here's another method.
Buy one of these hard drive adapters.
http://cgi.ebay.com/USB-2-0-SATA-PATA-3-5-2-5-Hard-Drive-Adapter-Cable-/14041077 1759?cmd=ViewItem&pt=LHDefaultDomain0&hash=item20b122592f
Remove the hard drive from the G4. Using the above adapter, connect the drive to your MacBook. Copy the files you want.
Cheers, Tom -
How to get max date in variable using dynamic query
Hi,
the following code gets all dates from sourcetable i want only max date , so i thought max function can be added and it will work
but still i have to create a table for one value(scalar) can get it in any other effeciant way.
declare
TYPE date_string IS TABLE OF VARCHAR(1000);
date_obj date_string;
BEGIN
EXECUTE IMMEDIATE 'SELECT to_char('''||day1||'-'||month1||'-'||year1||''') FROM '||source_schema||'.'|| sourcetable ||'' bulk collect INTO date_obj;
FOR indx IN date_obj.FIRST..date_obj.LAST loop
dbms_output.put_line(
date_obj(indx));
END loop;
DBMS_OUTPUT.PUT_LINE('Sample output');
END;
yours sincerely944768 wrote:
the following code gets all dates from sourcetableNo it doesn't. What is the datatype of day1, month1 and year1? They cannot be DATE datatypes otherwise your TO_CHAR would fail with all that concatenation going on. And your TO_CHAR is returning a VARCHAR2 datatype... so you cannot say that it is getting all dates... because there are no DATE datatypes returned. It's getting a lot of strings, but certainly not DATE's.
i want only max date , so i thought max function can be added and it will work You can use the MAX function on a DATE datatype, but not on strings (at least not in the way you intend it to work).
Converting it to a DATE before doing the MAX will allow you to get the maximum date (assuming the date format is correct)
EXECUTE IMMEDIATE 'SELECT max(to_date(to_char('''||day1||'-'||month1||'-'||year1||'''),''DD-MM-YYYY'')) FROM '||source_schema||'.'|| sourcetable ||'' bulk collect INTO date_obj;Then you will find have the other issues...
a) you are then going to be fetching your DATEs in to a collection of VARCHAR strings. (Not even VARCHAR2, very poor). This should be DATE datatype
b) you are bulk collecting into a collection, when you are using MAX which will return a single value in your example
And you really should address the design issues:
c) why are day, month and year, not being stored in the database as a single DATE datatype in the first place
d) why does your code not know the name of the table it's querying requiring the use of very poor dynamic SQL techniques.
e) why are you loading data in a collection in expensive PGA memory... what can't you do in SQL that requires you to collect the data into memory first? -
OPEN SQL - use of subquery to get max date
Hello,
I am trying to use a subquery to get the latest record, but cannot get the syntax correct.
select single from hrp1001 into mydata
where objid = '122334'
where begda = ( select max ( begda ) from hrp1001 where objid = '122334' )
but cannot get it right.
I am just trying to get the record with the max(date).
ThanksHello,
To get a better performance, I suggest you the following:
select single * from hrp1001 into corresponding fields of mydata
where objid = '122334'
order by begda descending.
Regards, -
SQL Help getting Max() date....
Hi gurus, Here is my situation:
Here is the sample data:
Policy_Id Policy-Exp_Dt COl_1
123_____10/30/2008 __ 333
123_____ 09/25/2008___445
123_____ 08/30/2008___443
Here i have to get the Policy-Exp_Dt from the second row; In other words for all rows which have a similar Policy_Id i should first find out the max(Policy-Exp_Dt) and get the next smallest available date to that.
I have tried using
select Policy_Id, COl_1, Policy_Exp_Dt from
table_1
where Policy-Exp_Dt = (select max(Policy-Exp_Dt)-1 from
table_1 a
where a.policy_id = table_1.policy_id)
but here i am getting the value = 10/30/2008 - 1 which is 10/29/2008 but i need the value 9/25/2008 which is the next available date less than the max() date.
Please Advise.
Edited by: user521009 on Jan 9, 2009 1:56 PMI thought to use lag - maybe not as appropriate a ranking functions.
Also we have a case where there is only One record for a policy - exclude this I guess!
drop table Max_but_One;
create table Max_but_One
Policy_Id integer not null,
Policy_Expires date not null,
Policy_Note varchar2(20) not null
-- Standard data
insert into Max_but_One values (123, to_date('30-08-2008','dd-mm-yyyy'), 'First note');
insert into Max_but_One values (123, to_date('25-09-2008','dd-mm-yyyy'), 'Second note');
insert into Max_but_One values (123, to_date('30-10-2008','dd-mm-yyyy'), 'Third note');
-- Standard data again for double check
insert into Max_but_One values (223, to_date('01-11-2008','dd-mm-yyyy'), 'First note');
insert into Max_but_One values (223, to_date('02-11-2008','dd-mm-yyyy'), 'Second note');
-- Only one record for a policy!
insert into Max_but_One values (323, to_date('01-12-2008','dd-mm-yyyy'), 'First note');
-- Two or more records for a policy both having the same date which is prior to the max
insert into Max_but_One values (423, to_date('10-12-2008','dd-mm-yyyy'), 'First note');
insert into Max_but_One values (423, to_date('10-12-2008','dd-mm-yyyy'), 'Second note');
insert into Max_but_One values (423, to_date('11-12-2008','dd-mm-yyyy'), 'Third note');
break on Policy_ID
select Policy_Id, Policy_Expires, Policy_Note
from Max_but_One
order by Policy_Id, Policy_Expires
POLICY_ID POLICY_EX POLICY_NOTE
123 30-AUG-08 First note
25-SEP-08 Second note
30-OCT-08 Third note
223 01-NOV-08 First note
02-NOV-08 Second note
323 01-DEC-08 First note
423 10-DEC-08 First note
10-DEC-08 Second note
11-DEC-08 Third note
-- Max Policy_Expires
select t.*
from (select Policy_Id, Policy_Expires, Policy_Note
,max(Policy_Expires) over (partition by Policy_Id) as Max_Policy_Expires
from Max_but_One
) t
where t.Policy_Expires = t.Max_Policy_Expires
POLICY_ID POLICY_EX POLICY_NOTE MAX_POLIC
123 30-OCT-08 Third note 30-OCT-08
223 02-NOV-08 Second note 02-NOV-08
323 01-DEC-08 First note 01-DEC-08
423 11-DEC-08 Third note 11-DEC-08
-- Using LAG
select t.Policy_Id
,t.Prior_Policy_Expires as Policy_Expires
,t.Prior_Policy_Note as Policy_Note
from (select Policy_Id, Policy_Expires, Policy_Note
,max(Policy_Expires) over (partition by Policy_Id) as Max_Policy_Expires
,lag(Policy_Expires) over (partition by Policy_Id order by Policy_Expires) as Prior_Policy_Expires
,lag(Policy_Note) over (partition by Policy_Id order by Policy_Expires) as Prior_Policy_Note
from Max_but_One
) t
where t.Policy_Expires = t.Max_Policy_Expires
POLICY_ID POLICY_EX POLICY_NOTE
123 25-SEP-08 Second note
223 01-NOV-08 First note
323
423 10-DEC-08 Second note
-- To exclude the single record policy then add and t.Prior_Policy_Expires is not null
select t.Policy_Id
,t.Prior_Policy_Expires as Policy_Expires
,t.Prior_Policy_Note as Policy_Note
from (select Policy_Id, Policy_Expires, Policy_Note
,max(Policy_Expires) over (partition by Policy_Id) as Max_Policy_Expires
,lag(Policy_Expires) over (partition by Policy_Id order by Policy_Expires) as Prior_Policy_Expires
,lag(Policy_Note) over (partition by Policy_Id order by Policy_Expires) as Prior_Policy_Note
from Max_but_One
) t
where t.Policy_Expires = t.Max_Policy_Expires
and t.Prior_Policy_Expires is not null
POLICY_ID POLICY_EX POLICY_NOTE
123 25-SEP-08 Second note
223 01-NOV-08 First note
423 10-DEC-08 Second note
-- 423 is randomly picked here - could equally have got {423, 10-DEC-08, First note} -
Problem while trying to get meta data from entity in CRM 2011 using java
Hi,
I have been trying to get the meta data from entity. Below is the code what i have tried.
EntityFilters entfilter = new EntityFilters();
EntityFilters_type0 eftypes [] = new EntityFilters_type0[]{EntityFilters_type0.Attributes};
entfilter.setEntityFilters_type0(eftypes);
EntityFiltersE entityFiltersE = new EntityFiltersE();
entityFiltersE.setEntityFilters(entfilter);
Boolean RAIP = new Boolean(true);
OrganizationServiceStub.ParameterCollection parameterCollection = new OrganizationServiceStub.ParameterCollection();
OrganizationServiceStub.KeyValuePairOfstringanyType entityFilters = new OrganizationServiceStub.KeyValuePairOfstringanyType();
entityFilters.setKey("EntityFilters");
entityFilters.setValue(entityFiltersE);
OrganizationServiceStub.KeyValuePairOfstringanyType retAsIfPublished = new OrganizationServiceStub.KeyValuePairOfstringanyType();
retAsIfPublished.setKey("RetrieveAsIfPublished");
retAsIfPublished.setValue(RAIP);
parameterCollection.addKeyValuePairOfstringanyType(entityFilters);
parameterCollection.addKeyValuePairOfstringanyType(retAsIfPublished);
OrganizationServiceStub.OrganizationRequest request=new OrganizationServiceStub.OrganizationRequest();
request.setRequestName("RetrieveAllEntities");
request.setParameters(parameterCollection);
OrganizationServiceStub.Execute org_execute = new OrganizationServiceStub.Execute();
org_execute.setRequest(request);
ExecuteResponse resp = serviceStub.execute(org_execute);
And getting the below error.
[ERROR] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter
http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException
message was 'Element value from namespace http://schemas.datacontract.org/2004/07/System.Collections.Generic cannot have child contents to be deserialized as an object. Please use XmlNode[] to deserialize this pattern of XML.'. Please see
InnerException for more details.
Please help me if any one have an idea on this error.
Thanks in advance.Hi
Did you get this resolved ? -
How to get max(date) with BI Answers?
Hi,
I have a fact table with costs of projects and several dimension tables. The data in the fact table is stored day-based and is related to a time dimension. Additionally there is a relation between the fact table and the project dimension. A project has several dimension attributes like "current"
Now I want to create the following query in BI Answers:
Get the costs to a project where the "current" attribute was set to Y and show the related date.
My thoughts were, that I'm looking in the project dimension where the "current" attribute is set to Y and do a join on the fact table. Therefore I get several dates, because there are more than one day where the project status was set to Y. How can I get the last, highest date?
GreetingsHi,
Maybe you could order by date descending and show the Top N (=1).
Good Luck,
Daan Bakboord -
"Get External Data Group" greyed out
I'm having the same problem as someone else whose Excel 2010 the "Get External Data" is grayed out was also greyed out. There was a suggestion to clear the old external data. How do you clear old external data?
Hi,
Please confirm the following situations:
Once double click a cell, the “Get External Data” will be greyed out.
One you select a cell in a table, the “Get External Data” will be greyed out.
Check whether the workbook or worksheet is protected.
Jaynet Zhang
TechNet Community Support -
Help to get max date of the group
Hi, How I can get the max(date1) for the group on the basis of Code1,Code2,Code3.
Code1 Code2 Code3 Date1 RTCODE
A A1 A2 1/1/2012 SER
A A1 A2 1/1/2013 SER
A A1 A2 1/1/2015 TER
B B1 B2 1/1/2011 JTS
B B1 B2 1/1/2012 JTR
C C1 C2 1/1/2010 HYR
C C1 C2 1/1/2011 JST
Expected results from query should be:
Code1 Code2 Code3 Date1 RTCODE
A A1 A2 1/1/2015 TER
B B1 B2 1/1/2012 JTR
C C1 C2 1/1/2011 JSTHi,
You can try this:
CREATE TABLE #T
CODE1 VARCHAR(5),
CODE2 VARCHAR(5),
CODE3 VARCHAR(5),
DATE1 DATE,
RTCODE VARCHAR(5)
--DROP TABLE #T
INSERT INTO #T
VALUES
('A','A1','A2','20120101','SER'),
('A','A1','A2','20130101','SER'),
('A','A1','A2','20150101','TER'),
('B','B1','B2','20110101','JTS'),
('B','B1','B2','20120101','JTR'),
('C','C1','C2','20100101','HYR'),
('C','C1','C2','20110101','JST');
--TRUNCATE TABLE #T
WITH TEST AS
SELECT CODE1, CODE2, CODE3, MAX(DATE1) AS DT_MAX
FROM #T
GROUP BY CODE1, CODE2, CODE3
SELECT T.CODE1,T.CODE2, T.CODE3, T.DT_MAX,#T.RTCODE
FROM TEST AS T
INNER JOIN #T ON T.CODE1=#T.CODE1
AND T.CODE2=#T.CODE2
AND T.CODE3=#T.CODE3
AND T.DT_MAX=#T.DATE1
ORDER BY T.CODE1,T.CODE2,T.CODE3
Regards,
Reshma
Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered -
I'M SORRY FOR THE CAPS BUT I HAVE OLE EYES, ARTHRITIS AND CARPEL TUNNEL!!!!
I STARTED HAVING THIS PROBLEM A FEW WEEKS AGO AND IT HAS PROGRESSED TO TOTALLY BLOCKING ME FROM GETTING INTO MY YAHOO GROUPS AT ALL!!! EVERY TIME I TRY IT GIVES ME THIS SAME MESSAGE AFTER IT TELLS ME AT THE BOTTOM THAT IT IS CONNECTED TO THE GROUP -
The connection was interrupted
The connection to groups.yahoo.com was interrupted while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
THE CONNECTION IS OK - BUT I DON'T KNOW ABOUT FIREWALLS AND PROXY THINGS BUT I GET ALL THE OTHER SITES I LOG TO!
THIS ALSO KEEPS HAPPENING WHEN I TRY TO ACCESS FACEBOOK BUT IT DOES LET ME IN SOMETIMES?!?!
I HAVE NO IDEA WHAT TO DO OR WHERE TO LOOK ON MY SYSTEM TO FIX THIS (NEED COMPUTERS FOR DUMMIES 100!!!! 101 IS TOO ADVANCED!!!!) I'M ON AN HP 2000 NOTEBOOK PC WITH WINDOWS 8.
THANKS FOR ANY HELP!!!!
DEE MAYERYou can use the NoSquint extension to set font size (text/page zoom) and text color on web pages.
*NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/
It is possible that your security software (firewall, anti-virus) blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
Remove all rules for Firefox and the plugin-container from the permissions list in the firewall and let your firewall ask again for permission to get full, unrestricted, access to internet for Firefox and the plugin-container process and the updater process.
See:
*https://support.mozilla.org/kb/Server+not+found
*https://support.mozilla.org/kb/Firewalls
*https://support.mozilla.org/kb/fix-problems-connecting-websites-after-updating
You can try these steps in case of issues with web pages:
Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
*Hold down the Shift key and left-click the Reload button
*Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
*Press "Command + Shift + R" (Mac)
Clear the cache and cookies only from websites that cause problems.
"Clear the Cache":
*Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
"Remove Cookies" from sites causing problems:
*Firefox/Tools > Options > Privacy > Cookies: "Show Cookies"
Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
*Do NOT click the Reset button on the Safe Mode start window.
If it works in Safe Mode and in normal mode with all extensions (Firefox/Tools > Add-ons > Extensions) disabled then try to find which extension is causing it by enabling one extension at a time until the problem reappears.
Close and restart Firefox after each change via "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit)
*https://support.mozilla.org/kb/Safe+Mode
*https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes -
SQL Query - Max Date - Group By
Please see SQL below - this code is counting customers and grouping by their tenure since activation
However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of records
SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
FROM FACT_RESULT_VW a,
PLAN_VW b,
SUB_VW c ,
CUST_VW d,
FACT_TRANS e,
WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )+
AND a.PP_KEY = b.PP_key
AND a.ID = c.ID
AND c.CUST_ID = d.CUST_ID
AND c.ID = E.ID
AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND a.DATE_KEY = 20100601
AND A.PEF_ID = 1
GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')Hi,
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
Simplify the problem as much as possible.
Would you have the same problem if only two tables, fact_result_vw and fact_trans, were involved? Then post a question involving only those two tables. Once you have a solution for the simplified problem, adding the other tables will be easy.
Would the problem be essentially the same if you were pivoting only 2 or 3 columns, instead of 13? Then post a question where you're only pivoting 2 or 3 columns. Once you have a solution, adding the others will be easy.
787771 wrote:
Please see SQL below - this code is counting customers and grouping by their tenure since activation
However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of recordsDo you want only the latest transaction from the fact_trans table, or the latest transaction for each customer ?
What if there's a tie, and the same customer has two (or more) transactions at the same date, and none later?
Since you're not using any of the data from the fact_trans table, the effect is just to eliminate customers who are not in fact_trans. You can do that more simply with an IN or EXISTS sub-query.
If you really do need something from the fact_trans table in the main table, then one way you can get the results you want is to use the analytic RANK (or ROW_NUMBER) function to number the rows in fact_trans by trans_date (latest first), with a separate set of numbers (1, 2, 3, ...) for each customer, like this:
WITH fact_trans_1 AS
SELECT id -- all columns that you need
, RANK () OVER ( PARTITION BY id
ORDER BY date_trans DESC
) AS r_num
FROM fact_trans
SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
FROM FACT_RESULT_VW a,
PLAN_VW b,
SUB_VW c,
CUST_VW d,
FACT_TRANS_1 e,
WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )
AND e.r_num = 1
AND a.PP_KEY = b.PP_key
AND a.ID = c.ID
AND c.CUST_ID = d.CUST_ID
AND c.ID = E.ID
AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND a.DATE_KEY = 20100601
AND A.PEF_ID = 1
GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')I hope this answers your question.
If not, post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data. -
Help - Need to Get Max(Date) from An Unrelated Table in PowerPivot
I have two tables in my Power Pivot model:
Table A (a many table)
Asset
SerialNumber
User
CTUT111
YC112233
Bob
CTUT222
ZZ221144
Susy
CTUT222
ZZ221144
Larry
CTUT333
AB332244
Bob
Table B (a many table, a CSV import from another system)
Asset
SerialNumber
CheckIn_Date
CTUT111
YC112233
6/15/2014
CTUT111
YC112233
6/20/2014
CTUT222
ZZ221144
6/18/2014
CTUT333
AB332244
6/20/2014
I know it appears odd that Table B would have two entries for the same Asset (CTUT111), but it does.
I know I could write a SQL query that gave me the MAX(CheckIn_Date), but I’m not staging these datasets in a SQL server first.
I’m pulling directly from CSV tables.
I don’t want to have bridge tables either, if possible.
So, I’m left with a many-to-many situation in Power Pivot.
I want to add a Calculated Column to Table A, called ‘Latest CheckIn Date’ – which I get from Table B, matching on Serial Number.
So, when I’m done, I would expect the value for Asset=CTUT111 to be 6/20/2014 (since it’s the MAX of a value of dates)
I’m trying this pattern from Marco Russo in which you don’t need to relate two tables to exchange information, but it doesn’t appear to be working.
=CALCULATE (
MAX ( VALUES ( TableB[CheckIn_Date] ) ),
FILTER (
TableB,
'TableA'[SerialNumber]
= TableB[SerialNumber]
I’ve also tried to use LOOKUPVALUE, but I can’t seem to figure it out.
Would appreciate the help.
Thanks in advance.
-EricHi Eric,
Please, try this one formula:
=CALCULATE (
MAXX ( VALUES( TableB[CheckIn_Date] ); TableB[CheckIn_Date] );
FILTER (
TableB;
'TableA'[SerialNumber] = TableB[SerialNumber]
P.S. In my locale I use ";". According to your locale you should use ",".
Truly yours,
Paul -
How to get max date in child table
I have tow tables Departments as the master table and Employees as the child table
The employees table (the child) has employee_hiring_date Field .
I want to get the maximum hiring date in the employee table for every department to make validation over it.
How to make this.It's more or less described in the doc I gave you.
OK, lets do it with your sample.
I assume you have accessors defined to navigate between the master and the detail (in both directions). The accessors on entity level are named
"Employees1" to get the employees of a department
"Departments1" to get the department of an employee
1. In the Departments entity you add a transient attribute "MaxSalary" as type Number, select 'Expression' as 'Value Type' and type "Employees1.max("Salary")" in the value field. Make sure to uncheck the 'Persistent' attribute in the dialog. This will mark the attribute as transient.
2. in the entity Employees open the 'Business Rules' and select the 'Saraly' attribute. Add a rule by clicking the green plus. 'Rule Type' is 'Compare', 'Operator' is 'LessOrEqualTo' and in the 'Compare With' drop down select 'Expression'. In the Dialog enter "Departments1.MaxSalary". Switchto the 'FailureHandling' tab and type in a message you like to see (e.g. 'The Salary is too high!") and save your work. The magic is done in the expression "Departments1.MaxSalary" which selects the department of the employee and gets the value of the attribute 'MaxSalary' which is an other Groovy expression which gets the max salary of all employees in the department.
3. To get the 'MaxSalary' attribute from the entity to the view object, you can open the VO editor and select the 'Attributes' section. Click the arrow down right of green plus and select 'Add Attribute from Entity, shuffle the MaxSalary attribute you see in the Department entity to the right and save your work.
If you now test the app in the Tester try changing the salary of an employee to a value higher then max of the department and you should see your error message.
Timo -
Trying to get a date value from a string
Hi All,
I'm not sure I am doing this right, so I figured I would ask the experts...
I have built a file upload page that is working the way I need it, but I have found that I need to determine the date from the uploaded file name. I tried to create a PL/SQL computation and do some substr / instr to the filename, but I'm not getting it as I get "ORA-01843: not a valid month" error. Here is the code I'm trying:
declare
v_underscore integer;
v_date varchar2(15); --have also tried using date datatype...
begin
v_underscore := INSTR(:P20_EXPRESS,'_',1,1);
v_date := to_date(substr(:P20_EXPRESS,v_underscore + 1,6),'YYMMDD');
return v_date;
end;And here is a sample filename:
F15047/proc_10607161001.csv
Is this the best way to achive what I'm trying to do?
Thanks,
CoreyHi,
v_underscore := INSTR(:P20_EXPRESS,'_',1,1);
v_date := to_date(substr(:P20_EXPRESS,v_underscore + 1,6),'YYMMDD');What this is saying is:
Get the position of the "_" character
Move to the next character to the right (which is a "1" in your case)
Get 6 characters (106071) from the string value
Convert them to a date using the format 'YYMMDD'
This results in:
Year: 10
Month: 60
Day: 71
Which of course is not valid.
For example:
select
substr('F15047/proc_10607161001.csv', instr('F15047/proc_10607161001.csv', '_', 1, 1) + 1, 6)
from
dual;
SUBSTR
106071It looks like you want to move two positions to the right rather than a single position:
select
substr('F15047/proc_10607161001.csv', instr('F15047/proc_10607161001.csv', '_', 1, 1) + 2, 6)
from
dual;
SUBSTR
060716Hope that helps a bit,
Mark
Maybe you are looking for
-
How do you get the hot keys / keyboard shortcuts to work?
I have the free trial version of Photoshop. I am new to Photoshop, I am just starting to learn how to use it. I notice that some of the shortcuts/hot keys don't work. For example, one basic hot key that does not work is the F7-key. The F7-key opens a
-
HT3819 I cannot add a new pc to my apple id ,
I have deauthorised 2 computers, and only have 5 devices associated with my apple ID , yet when I try to add a new computer the message reminds me I can only have 5 commputers associated with this account + I need to de-authorise one any ideas ? Than
-
Automatically upload documents to list items in Sharepoint Online
Hi I need to upload pdf documents to a list (not a document library, this is not an option) on SharepointOnline (Office365). In practice, whenever a document is "sent" or "uploaded" to the list, a new list item would be created automatically and the
-
Hi All, I have one requirement to get weekly snap shot and monthly snap shot reports which are open. we planned to load ODS daily in that keffield is ocalday and bill no . so we will get all staus to ods as new records in ods
-
Can we have everything about Oracle in one drive?
Hello, everybody, We got a backup database server. Since it is just for backup, we don't want to spend too much $ on this one. My question is: can we have everything about Oracle installled in the same drive? It means that Archive, Redo Logs, Oracle