Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Solved] Need Row Count to Restart at the beginning of each member in a BY
Go
New
Search
Notify
Tools
Reply
  
[Solved] Need Row Count to Restart at the beginning of each member in a BY
 Login/Join
 
Gold member
posted
Hey All,

I am trying to calculate the number of rows based on a DB_EXPR command and it's working great. However, I would like it to restart the logic from the beginning of each Calendar Year.

For example right now my expression generates results like:

1. 2016: 1,2,3,4,5
2. 2017: 6,7,8,9,10

I would like 2017 to restart at 1. Is there any way to do this? Here is the code that I am working with:

 TABLE FILE _ADM_STAR
SUM
	SALES
	COMPUTE ROW_CNT/I4=DB_EXPR(ROW_NUMBER() OVER (PARTITION BY "CALENDARYEAR" ORDER BY "CALENDARYEAR","SALES" desc));
BY  CALENDARYEAR
BY  PROVIDERNAME
BY  PROVIDERTAXID
WHERE CALENDARYEAR EQ '2015' OR '2016' OR '2017'
END 


Thanks in advance!!

This message has been edited. Last edited by: Brandon Andrathy,


WebFOCUS 8204
 
Posts: 70 | Registered: July 10, 2018Reply With QuoteReport This Post
Master
posted Hide Post
I'm not 100% sure of what you're looking for. But, maybe look at the PARTITION_AGGR function.

Example below:
  
DEFINE FILE ggsales
CALENDARYEAR/YY=DATE ;
END
TABLE FILE ggsales
SUM DOLLARS
COMPUTE ROW_CNT/I11=PARTITION_AGGR(CNT.PCD, CALENDARYEAR, B, C, CNT);
BY CALENDARYEAR
BY PRODUCT
BY PCD
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET PAGE-NUM OFF
ON TABLE SET STYLE *
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/ibi_themes/flat.sty,$
TYPE=REPORT, LINES-PER-PAGE=UNLIMITED, $
ENDSTYLE
END
-RUN


Hallway
WF(Prod):8202M
WF(Test):8202M
OS/Platform:Win 10
Outputs:All
 
Posts: 485 | Location: Salt Lake City, UT, USA | Registered: November 18, 2015Reply With QuoteReport This Post
Member
posted Hide Post
Your SQL Server ROW_NUMBER function looks correct. The PARTITION BY part of it is the column that you want to reset back to 1 when the value changes.

Look at this code:
SQL SQLMSS
SELECT YEAR(CREATE_DATE) AS CREATED_YEAR,
ROW_NUMBER() OVER(PARTITION BY YEAR(CREATE_DATE) order by year(create_date) )
AS Row#,
name, recovery_model_desc
FROM sys.databases t1
WHERE database_id < 10
ORDER BY CREATED_YEAR;
END

Notice that for the change of each year the Row# goes back to 1.

Look at your translated SQL and make sure the translation of the ROW_NUMBER function looks correct. If it does and you still are not getting what you think is correct, please open a case.

Walter Brengel
Information Builders
Technical Director of FOCUS Support Services

FOCUS Virtual User Group
Please join us (Walter Blood and me) and other FOCUS/WebFOCUS coders for the next FOCUS Virtual User Group meeting.

FOCUS Virtual User Group - for the latest schedule and to sign up.
https://www.informationbuilder...wledgeshare-webinars

Virtual User Group Archives – for past sessions.
https://www.informationbuilder...-user-group-meetings
 
Posts: 3 | Registered: September 05, 2006Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Apologies if I am oversimplifying this, but if I were to use only WebFOCUS code, then I would simply do this:

	COMPUTE ROW_CNT/I4=IF CALENDARYEAR NE LAST CALENDARYEAR THEN 1 ELSE ROW_CNT + 1 ;


WebFOCUS 8.2.06 mostly Windows Server
 
Posts: 202 | Location: Johannesburg, South Africa | Registered: September 13, 2008Reply With QuoteReport This Post
Member
posted Hide Post
Hi Twanette,

Your suggestion and Hallway's are absolutely correct.

In my original involvement with this, the customer was trying to create WebFOCUS code based on complex select statement that contained subqueries. The subquery was using the ROW_NUMBER function which they wanted to continue to use.

The only difference between what you (and Hallway) posted and using DB_EXPR to use the ROW_NUMBER fucntion is where the work will be done (WebFOCUS side vs RDMBS).

Walter Brengel
Information Builders
Technical Director of FOCUS Support Services

FOCUS Virtual User Group
Please join us (Walter Blood and me) and other FOCUS/WebFOCUS coders for the next FOCUS Virtual User Group meeting.

FOCUS Virtual User Group - for the latest schedule and to sign up.
https://www.informationbuilder...wledgeshare-webinars

Virtual User Group Archives – for past sessions.
https://www.informationbuilder...-user-group-meetings
 
Posts: 3 | Registered: September 05, 2006Reply With QuoteReport This Post
Gold member
posted Hide Post
This has been solved. Turns out the reason it wasn't working was because Calendar Year was an integer and was being summed so the logic in the partition was never being met. Once we took the max year in a compute and then referenced that in the partition it worked beautifully. Thank you Walt and everyone else for your time with this!!


WebFOCUS 8204
 
Posts: 70 | Registered: July 10, 2018Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Solved] Need Row Count to Restart at the beginning of each member in a BY

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.