There are lot of ways you can achive this.
BOB Forum had wondeful macro.
Credit goes to author of this script( not me) I am just sharing. NOTE: Logon to the site inorder to download the file.
http://www.forumtopics.com/busobj/viewtopic.php?t=143071&start=66
Also use Querry builder. Refer to the link below to see the querries provided by Manikandan,
https://scn.sap.com/community/bi-platform/blog/2012/10/11/businessobjects-query-builder-queries