Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


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

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[Solved] Need Row Count to Restart at the beginning of each member in a BY
 Login/Join
 
Platinum 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: 152 | Registered: July 10, 2018Report 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

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs:
 
 
 
 
 
Posts: 608 | Location: Salt Lake City, UT, USA | Registered: November 18, 2015Report 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, 2006Report 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: 195 | Location: Johannesburg, South Africa | Registered: September 13, 2008Report 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, 2006Report This Post
Platinum 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: 152 | Registered: July 10, 2018Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

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-2020 Information Builders