Immediate Solutions for Everyday Business Problems

Calculated Column Formula Tips – Aggregating Calculations Over 1000

Original Publication Date: Thursday, August 6, 2009
Filed Under: Calculated Column, Data View Web Part, Jim Bob Howard, Libraries and Lists, Web Parts
SharePoint User Level: Power User

 

Contributing Author: Jim Bob Howard

Congratulations, Mark, on the posting of the 1000th article on EndUserSharePoint.com! Thanks for letting me be a part of it. In honor of passing that milestone, maybe this will come in handy for you as you continuing calculating the number of articles here. —Jim Bob

Aggregating data with a DVWP and a Linked Data Source can really save you lots of time and make your SharePoint lists do some great online reporting.

I was recently working on a Mileage Reimbursement application and was able to use some tricks I learned from Laura Rogers in her screen cast, 4 Minute Screencast: Join View of SharePoint Lists, to link data from different lists. Her techniques gave me the direction I needed to display all of the mileage records for a given employee for a given month, as well as show aggregated totals based on the data brought in through the linked data source.

Calculated Column Formula Tips
Figure 1 – Data Form Web Part, plus a Data View Web Part

In Figure 1, two of the fields in the Data Form Web Part come from a Linked Data source, as shown in Figure 2.

Calculated Column Formula Tips
Figure 2 – Data Form Web Part – XSLT aggregation

The DVWP also has some aggregated fields that sum up Calculated Columns, as show in Figure 3.

Calculated Column Formula Tips
Figure 3 – Data View Web Part – XSLT aggregation

But, if you are aggregating Calculated Columns—using XSLT calculations on columns that are SharePoint Calculated Columns—you may have noticed, like in Figure 4, that your data disappears from your form when the calculated value goes over 1,000.

Calculated Column Formula Tips
Figure 4 – Calculated column data disappears

Notice, though—in Figure 5, that the data is actually calculated correctly. It’s just not displayed correctly in the DVWP row, nor is XSLT able to perform the summation of that column.

Calculated Column Formula Tips
Figure 5 – Calculated Column functioning and displaying properly

Why 1,000?

The answer is in the answer. That’s right, it’s the comma.

The Calculated Column is stored as a string (Single Line of Text). SharePoint formulas will automatically cast a string that "looks like a number" into a number, when necessary, for a given formula that requires numbers. Let me explain.

Consider the following situation
X = 100
Y = 6X

X is a string with a value of "100" and Y is a number with a value of 6 times X. The formula (6*[X]) will convert the string "100" to the number 100, multiply it by 6 and return 600, storing it either as a string or a number depending on how Y is defined.

But a Calculated Column which results in a value of "1,000" no longer "looks like a number" because of the comma. So, if X has a value of "1,000", Y will not equal 6000. Further XSLT cannot cast a non-number-looking string to a number, either.

To make matters worse, the Calculated Column doesn’t give you the option of turning off the comma.

Calculated Column Formula Tips
Figure 6 – Typical Calculated Column definition

So, what do you do?

Formula Tip – FIXED

Since you are already working with a Calculated Column, simply add another formula to make sure the number stays a number. Here’s the description for just thing you need.


Calculated Column Formula Tips
Figure 7 – The FIXED function

That last parameter—no_commas—is what is going to save us. The default for this parameter is FALSE, meaning: "No, don’t show no commas." Nice, huh? TRUE, on the other hand, says: "Yes, we want no commas."

Remember, that even though this function is used to "convert" our number to text, that’s OK, because the Calculated Column is going to be text anyway. What we want to ensure is that the text "looks like a number," meaning, no commas.

Let’s try this out on our Calculated Column, Trip Miles, by wrapping our calculation in this new formula:

=FIXED([Ending Odometer]-[Beginning Odometer],1,TRUE)

Since we want to have only one decimal place, the decimals parameter is set to 1. But, since we don’t want commas, we’ll set no_commas to TRUE.

Is that all? Yes, that’s all.

The Result

Now that our text field looks like a number, the DVWP can treat it like one when doing calculations or formatting. See Figure 8 to see how it looks now.

Calculated Column Formula Tips
Figure 8 – DFWP and DVWP both now properly display Calculated Columns with values 1000 or higher

Jim Bob HowardContributing Author: Jim Bob Howard
Jim Bob Howard is a web designer / web master in the healthcare industry. He has been working with SharePoint only since March 2009 and enjoys sharing what he has learned. You can email him at [email protected].

Spread the word...
  • Digg
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • LinkedIn
  • Reddit

Articles in this series

  • Calculated Column Formula Tips - Aggregating Calculations Over 1000

Notify me of comments to this article:


Comments

8 Responses to “Calculated Column Formula Tips – Aggregating Calculations Over 1000”

  1. Tobias Zimmergren on August 6th, 2009 2:01 pm

    Great tip. Needed this a while back for a project but ended up doing a custom solution for it. Will definately add this to my memorybank for the future.

  2. Greg on August 6th, 2009 4:11 pm

    Jim,
    This is a definite gem. How did you:
    - create the aggregated values
    - create the ‘Submit Report’ button.
    I am assuming this run a submit for approval workflow?

  3. Jim Bob Howard on August 6th, 2009 4:21 pm

    Greg,

    Aggregated valued, see Laura’s screencast, then check out the XSLT I display for each of the aggregated fields. Also, see my answer to this STP question: http://www.endusersharepoint.com/STP/topic/sp-designer-average-on-column-not-working

    I’ll be writing an article on the Submit Report button, too. I’ve not finished the functionality of it, yet. ;) But, I’m building it on a post from Nataly Voskresenskaya at http://spforsquirrels.blogspot.com. (Can’t remember the exact article off the top of my head, but I mentioned it on Twitter yesterday – http://www.twitter.com/jbhoward.)

    And yes, this will be using a two-step submit for approval workflow.

    Glad you liked the article. I’m planning more in the series on Calculated Column Formula Tips.

    Blessings,
    Jim Bob

  4. Jim Bob Howard on August 10th, 2009 7:57 am

    Here’s the link to Nataly’s post: http://bit.ly/15hEz2

  5. Greg on August 12th, 2009 11:51 pm

    Hi Jim,
    Thanks a lot for the pointers.
    Will definitely investigate Nataly’s blog!
    Also really impatient to see your post introduce the end users to buttons.
    The out of the box workflow tab is always a training issue.
    Greg

  6. Jim Bob Howard on August 13th, 2009 7:09 am

    Be sure, also, to join in to the SharePoint Shop Talk (open Q&A) 8/13 @ 12:30PM EDT http://bit.ly/oZLv4

    Laura Rogers, Paul Galvin, Nataly Voskresenskaya, Harry Jones, and I will be there. Mark Miller joined in last time, but I don’t know if he will this week from his fishing trip. ;)

    And I’ll get to that button post just as soon as I can. ;)

    Blessings,
    Jim Bob

  7. Greg on September 8th, 2009 5:45 pm

    Hi Bob,
    You totally opened my eyes on the XSLT customisation possibilities. Your post above and Laura’s screencast http://www.endusersharepoint.com/2009/09/01/get-it-together-groups-and-totals-in-the-data-view-web-part-screencast/
    definitely triggered my interest.
    As far as the button to trigger workflows, did you have a chance or time to work on it?
    I checked the following post http://nextconnect.blogspot.com/2009/06/using-jquery-to-update-item-without.html but it is trigerring a javascript – not a workflow…

    Greg

  8. Jim Bob Howard on September 9th, 2009 7:51 am

    Dear Greg,

    Yes, I have several button workflows going on a project I’m finishing up. I’ll work up some screenshots/screencasts in the near future.

    I’ll also be covering button-initiated workflows in my EUSP workshop, Business Solution: Manage Milage Reimbursements, scheduled for December 3.

    Blessings,
    Jim Bob

    TIP: Keep an eye out at EventBrite for the EUSP workshops as they’re scheduled.

Leave a Reply