Sort Column Total - lotus-notes

I have a view with column totals.
What I want is to sort the totals-column in a Xpages-view or repeat-control.
I am able to get the totals to display but cannot sort them.
Any suggestions?

Not very clean. I wouldn't do that in production - for performance reasons - it's a brute force solution, but it should work for fair amount of categories (up to few hundreds).
Assume the view can be used for category lookups (similar to show single category). Then all you need is list of categories in correct order - based on totals and not alphabetical order. Therefore, in first cycle, loop through all categories (use NotesNavigator with cache) and store them as pair of values - (category, totals). It may be Map[String,Double] or Set[Category] where Category is POJO with category and totals attributes. In both cases you will need your own Comparator. If your categories are hierarchical, use only top level category (sorting of tree structure is more complicated).
For example:
Australia (5)
Brazilia (10)
Chile (7)
will sort as
Brazilia (10)
Chile (7)
Australia (5)
Cache this collection in viewScope (assuming totals are "static" for short period of time, user will need to reload the page to get updated data).
Feed this collection to repeater with simple data table (or view or repeater) showing only selected category.
GUI will be a bit odd with pagers (pager for categories and pager for content of category), but you will handle this, I hope.

It's probably better to ask can this type of sorting or resorting be done in Notes rather than can it be done in XPages. If it can be done in Notes then you should be able to do the same in XPages - sometimes automatically.
XPages can only do so much with the view datasource. So if the datasource can't sort the categories by the totals then you won't be able to do this in XPages. At least not out of the box.
You might be able to do something with repeats - doing a lookup of the datasource, retrieving all documents under a certain category that has the highest total before moving on to the next category in the sequence - but it likely to become pretty complicated and not worth it in the end.
Sorry if it's not the answer you're looking for.

I will try to clarify it.
There is an categorized view. Category is for example Company name.
In the view is a column with totals, so the category has also a total.
The wish is that this categorized view will show the company category, who has the highest total at the top of the view, without losing the categorization

Related

Filtering lotus-domino views that have multiple categories and multiple values

I am trying to design a view with multiple categories, and each document can belong to multiple categories at the same time.
For example, File A is in category:
1->a;
2
I can achieve this effect by specifying the columns as categories and access the document through various routes. However, I fail to specify which category the sub-categories belong to. This is what I am getting instead:
1->a;
2->a
The case doesn't seem too big of a difference but basically the view is returning every combination of the categories and the amount of entries can get very large.
I have tried to add the super category in front of the sub-category and try to filter out entries which the categories do not match the prefix of the sub-categories(e.g. 1,a), but I cannot find a way filter them out. Although the multiple values are shown in different entries, when I try to use the variable it extracts all the values.
Is there a way I can filter the entries based on that particular row instead of all the values? Or is there anyway I can achieve the effect through other methods? Thank you in advance.
You need to collapse Categories and subcategories into a single field. The Domino way to do this is to separate category and subcategory by backslash. So your category field would be something like:
"1\a":"2"
That ties the subcategory to the category. Or if you want to be able to find a document by subcategory only:
"1\a":"a":"2"
You then can use a little formula magic to get from the subcategory back to the main category (presuming the subcategories don't duplicate):
AllCategories := "1\a":"a":"2";
foundCategory := "a";
#Trim(#Replace(AllCategories;foundCategory:#Trim(#ReplaceSubstring(allCategories;foundCategory)));
This would return "1\a" (Note: the formula above is written is classic #Formula language, it is left as an exercise to the reader to translate that to the JavaScript formula equivalent)
Hope that helps

Pros and cons of two types of PivotTables for BI purposes

I am trying to figure out how to create the most useful PivotTable for a user to view data for BI purposes. Here are two options I was considerating:
(1) Traditional PivotTable, pivot values on top:
(2) Drill-down type PivotTable:
What are the pros and cons of each method? For example, one for each to start might be:
Drilldown
PRO: trivial to add additional drilldown variables.
Pivot:
PRO: can easily sort by the column headers in the table UI.
And, are there any other possible tabular displays of data, either another type of PivotTable or another type altogether?
I'll suggest to keep it simple. If the objective is to present a view of the revenue figures of each region summarized by gender then pivot table in option 1 is the most effective of both, as it shows everything relevant in one simple look, keeping similar data at the same level making easier to compare.
Bear in mind that management requested that view to be able to effectively see how each region is performing on that specific category.
If the focus is revenue by different gender. Option 1 shows that in same row continuously for each region. It can easily be seen that the best performer on revenue generated by females is US, while best performer on revenue generated by males is Canada. While is not easy to see that in option 2.
If the focus is revenue by same gender. Option 1 shows that in same column continuously, which is not the case with option two.
Option 2 will be useful if the primary focus is set on revenue by region then if there is a need to see additional details based on the performance of any region management can drilldown to see the details of what makes the primary number. Which in this case is not the objective as the request is to show both.
Also best advice is to always agree requirements with clients (internal and/or external) you might find that they might have requested only what they believe it is possible to achieve and after they have that they will apply some "manual steps" to achieve their ultimate goal, something you could have done entirely if only you would have known.
Pivot Tables are used to -
summarize data
analyze data
explore data
present summary data
Both ways (traditional and drill down) of Pivot table can do the above listed.
It depends on what you want to achieve in BI.
If detailed data is not required to show or sort then you can use drill down.
Mostly in BI, data used in summarised form. So Drill down method will be good for display of data. Anyways you can double click and see the detailed data. See how to get details of drill
Drill Down:
a. Pros
Summarise Easily
Add sub points for summary
"Get Details" of Pivot for more details
b. Cons
The way you are doing sorting by pivot is not possible. Instead I would suggest to use pivot to drill down. So you can sort (And will move to Pros section :P) and check pivot details in another form.
Traditional Way
This way you are making to use pivot tables of your data. You should explore more in given links below.
5 pivot tables you probably haven't seen before
pivot tables save your job
23 things you should know about Excel pivot tables
Generally every representation of data has a purpose and with this purpose there come certain advantages and disadvantages.
Obviously with any kind of report, the audience matters most. Which would put you in the classical Requirement Analysis situation where you need to figure out what your customer wants (What data is of interest? How should it be sliced? What medium is it consumed on?)
Is the Revenue by Gender an important KPI?
If it is not, why including it at all?
If it is, let's see what a potential reader would do to answer a question like "How does the womens sale for Mexico compare with Canada?"
Drill down table:
Understanding the table will take a couple of second since they have to understand the different levels and their representation, the meaning of the bold and regular lines and realize that the man and women values accumulate to the total value for a region
Find Mexico in the list
Find the row for women and the value of it on the right
Find Canada in the list
Find the row for women and the value of it on the right
Remember the the value for Mexico or look it up again
Important here is also that this process will be repeated more or less exactly for every follow up question.
Traditional table
Understanding the table will be faster, they see a country name on the left and male/female on the top. Generally people are used to these tables since primary school and won't need further explanation.
Find Mexico in the list, go to the right until they find the value for women (if you try it you will see that you automatically see the values and the heading)
Find Canada in the list, (realize that it is only one line above) go to the right and have both values on top of each other.
For all the following questions the structure is easy to remember and it's a find and match game between rows and columns
I know that might be a bit subjective, but I hope the general idea is understandable
If you know have a question like "In which region do we sell more to men than women?" the advantage of a traditional over a drill down table becomes even more obvious.
With the drill down you will have to juggle several rows and their values while with the traditional you just skim through one column and look for the biggest value.
Is the Revenue per Region the main KPI?
You should then rather use a drill down table, possibly with additional levels (ie. North America in case it's international data or US State since I would assume it would be of interest if your product sells better in Alaska than Florida).
Your audience can then decide which granularity they want to see and adjust it accordingly. The gender is on the bottom of the hierarchy so either you have curious people who are interested in just another figure or they don't care and just don't drill down that deep.
The assumption here is that you deliver the table on the highest aggregate level.
One could argue that the same problem of finding row etc. exists as well for this case but I would assume you wouldn't necessarily compare the sales for Yucatán with Alberta so you stay in one group of states for example and again just have to skim up or down to find the states of the same country so you can compare it.
Using drilldowns in pivot tables is, in my opinion, a tool to be used by analysts, and not managers. Pivot tables are not quite intuitive enough to be used on reports that are being sent on for BI review by management. Typically any report which is being circulated for review by the powers that be should be consistent from user to user. That means using drilldowns would display different numbers if different items are selected - which could lead to 2 people talking about different values without knowing it.
Many people in management level positions outside of the core analytical group will still print anything you e-mail them before they look at it. I suspect that this is more likely to be true in a less technologically advanced company (ie: one which uses Excel as its database analysis tool instead of a full ERP-type system). In either case, anything being submitted for high level review should already be formatted exactly as you want them to see it.
The key in Excel deliverables within the workbplace is to make review as easy as possible. That means all necessary information should be immediately visible on each tab, with a minimum of scrolling (maybe scrolling down if necessary, but never scrolling right), and absolutely no clicking required.
Conclusion - Do not force a reviewer to manipulate your Excel file to use it
You may like drilldowns because you see how powerful it is to adjust reports as you are analyzing data - but once you have made your own analytical conclusions, those conclusions should be immediately apperent from the visible workspace that you leave for review.
Therefore, in order to achieve simplicity in high level review documents, you should use the 'traditional' format as you have shown it, which shows all numbers next to eachother in an easy to read table.

repeat control from categorized view

I have tried to get the column values in repeat control from Categorized view in xPages,that time i got the column values are coming with single row,and the same row repeated
How to get the column values in "repeat control from categorized view"?
Thanks
I had a situation where I had to drill down from a much larger view and repeated the info back out with the following.
View is categorized in first column by what I'm drilling down by. I achieve this in the XPage/Custom Control by defining the view as a source in the data tab, then select "filter by category name", bind my repeater to that view data source, and compute the value I'm drilling down.
Then in my repeated table, each of my computed fields for each of the column entries read like:
rowData.getColumnValues()[1]
Adjust for your other columns by position with the array modifier after your getColumnValues method. This is not an elegant solution, but worked for my needs. Hope this helps if it's what you're looking for.
[Update]
It's worth noting that doing this can potentially create a memory handle for any DateTime objects which may be returned in the entirety of the getColumnValues method. If you're going to use this approach, I strongly recommend getting a handle on the column values separately, so you can perform a session.recycle(colVals); on them to prevent any memory creep.
[/Update]

How to Sort View control by Lookup column

I have two forms that are related and I would to combine them in a view control. Not that difficult. This is for a "1 to Many" type scenario.
Say I have a customer view with the columns customerID and Customer Name. Then I have a view showing the "many" documents that has the columns masterCustomerID, orderNumber, orderDate.
On the XPage I create a view control of the many documents and add the columns masterCustomerID, orderNumber, orderDate. Then I add a column in the front to do a DbLookup to pull in the actual name of the customer. Nothing too fancy really.
My question is, in this situation, where the lookup column is the FIRST column. What are the strategies to sort the view column by that column. By default it would sort by the Key Value in the order view which is likely different then the Name values.
I'm not averse to using repeat controls if that would be easier.
My first thought would be to employ TreeMaps somehow, but I don't know if that's practical in the event that there might be a LOT of documents. Maybe there's something I'm missing...
Any advice would be appreciated. Thanks
Use view with (Customer name, Customer ID) structure as main view. Then based on Customer ID populate other columns by lookup from view with structure (Customer ID, Order ID, Order date). Hence it is 1:N relationship, you can't use single view component, but two nested - repeat inside view column would do.
I hope you are aware of performance impact (orders looked up for every customer row), so don't try to show too many customers at once.

Can I create a COUNTIF calculated column in SharePoint?

Is there a way to create a SharePoint calculated column that returns a count of the number of entries in a list? So If I have 3 customers in my list with the company "Starbucks" I'd like the field to return "3"
(Edited some wording for clarity per suggestion from dariom).
You may be able to get what you want with another list using a not-so-well-known variation of a lookup column.
Let's say you have a list called Companies with values in the title column like "Starbucks", "Peets", etc. Now you also have the Customers list you refer to, but the "Company" column is a lookup column pointing to the title column in the Companies list.
You can add a count very similar to what you described to your Companies list. Go to your Companies list, add a column of type "Lookup" referring to the Customers list and you'll notice that in the drop-down area where you define the lookup if you point back to the Customers list, you'll have a new option called "Count Related". This is here automatically because it recognizes that the Customers list has a lookup pointing back to this one. Select that Count Related option and now your Companies list will have a column counting how many customers are associated with that company.
No coding, Javascript hacks, or anything. Just hidden SharePoint auto-magic.
No, I don't think there's a way to do this using the out-of-the-box calculated column.
Some other ways you could accomplish this are:
Create a view for your list that with a group by on the company field and include the total count. This is easiest, but might not be exactly what you're looking for.
Create a custom column type that executes a CAML query to find items that you're interested in. There is a learning curve if you've not done it before and if the list that you're adding this custom column to has lots of rows, you'll be executing a query for each row which is inefficient - it'll be OK for a small number of rows.
Use an event handler on the list that updates a column value each time a new item is added or removed from a list. This is easier, but can also be inefficient if you have a large number of items in your list.
As dariom said (damn my slow typing skills, +1!), only the current row can be operated on with calculated columns by default in SharePoint. There are a couple of documented workarounds involving SharePoint Designer or jQuery, though.
You can get a Count of specific list items in an XSLT Data View
To do this you will need SharePoint Designer.
Right click on your SharePoint List view (ensure the list view contains the field you want to filter by) select convert to XSLT Data View. Then in the Data Source Windows select Data Source Tab and drag and drop the field you want to get a total on for the specific items into where you want it displayed in your XSLT Data View. Click on the numerical value that is showing you should get a lightening bolt icon, select the drop down and choose Count, then select again and choose Filter. Select "Click here to add a new clause" then choose your field name again and enter your unique value as Starbucks and click OK, you can repeat this process for other fields you want the totals on. You will now see the total number of Starbucks items in the list.
I got something similar to work in a way similar to Niall. Basically, I:
Based on the source list, created a Data View Web Part (DVWP) on a "test" web
part page.
Added the footer column, which gives a count.
Set the filter for my conditions (i.e., the items I want to count).
In the code, deleted the recurring items row.
I was left with just the footer, which displayed a filtered count for all the list items. I further customized the footer by taking out the shaded background. Finally, I exported this web part and imported it onto the page where I wanted users to see a total of items in the list (which met the criteria).

Resources