Page 1 of 1

Generating sums from variables = Newbie question

Posted: Thu Jun 26, 2014 10:00 am
by mixim
Disclosure: I have only used TM1 for a couple of hours ! Just solving this small thing would help me to get going =)

I have data regaring amounts of parking spaces in each column in a CSV. In TM1 i want a variable to be the sum of these as it does not exist in the source file and i want TM1 to do the calculation.

Should I create a new variable in TI and add a formula?

e.g.
parkingAreaMain = 2
parkingAreaSecondary = 3

Pseudo formula :
parkingAreaTot (parkingAreaMain + parkingAreaSec) = 5

^^ If yes could someone help me with the syntax in formula ?

Otherwise, are there other recommended approaches for this purpose?
e.g. Creating some hierarchy with parkingAreaTot as parrent and with some kind of SUM rollup??) Kind of not knowing what im doing hehe.

Re: Generating sums from variables = Newbie question

Posted: Thu Jun 26, 2014 10:10 am
by Alan Kirk
mixim wrote:Disclosure: I have only used TM1 for a couple of hours ! Just solving this small thing would help me to get going =)

I have data regaring amounts of parking spaces in each column in a CSV. In TM1 i want a variable to be the sum of these as it does not exist in the source file and i want TM1 to do the calculation.

Should I create a new variable in TI and add a formula?

e.g.
parkingAreaMain = 2
parkingAreaSecondary = 3

Pseudo formula :
parkingAreaTot (parkingAreaMain + parkingAreaSec) = 5

^^ If yes could someone help me with the syntax in formula ?

Otherwise, are there other recommended approaches for this purpose?
e.g. Creating some hierarchy with parkingAreaTot as parrent and with some kind of SUM rollup??) Kind of not knowing what im doing hehe.
You need to hit the manuals. Seriously. And get some training. And I don't mean that in an "I'm telling you to RTFM" sense, I'm telling you that in the "If you don't nail down the basics, you're going to have a really frustrating time with trying to understand TM1" sense. That's the short answer to your question.

The longer answer is it depends on how you plan to analyse the data. Do you actually need these to be separated when you're doing your analysis? If so, you will need to have two elements in your dimension, and will add a consolidation element to the dimension to add them together.

If not, you can still do that but your other alternative is to use a method called aggregation. You have only a single parking area element in your dimension. As you process your source data, you use a CellGetN to read the value that is already there, add the current data row's value to it, then write the total back using CellPutN. Though in your case the numbers appear to be in different columns of the same row in which case you could just add them together before writing the total. The syntax is to simply use the + operator to add them together.

If you're in one of the more recent versions there is a function that will do both Get and Put operations in a single step; consult the Reference Guide (a link to which will be found in the Request For Assistance Guidelines post, and which some of the hyperlinks in this post take you to) for the full range of functions available to you in a TI process, as well as the calculation syntax operators.

Re: Generating sums from variables = Newbie question

Posted: Thu Jun 26, 2014 12:23 pm
by mixim
Hello Alan, thanks for your reply!
Alan Kirk wrote: You need to hit the manuals. Seriously. And get some training. And I don't mean that in an "I'm telling you to RTFM" sense, I'm telling you that in the "If you don't nail down the basics, you're going to have a really frustrating time with trying to understand TM1" sense. That's the short answer to your question.
Well, that is pretty evident and I know. At this point, I did not want to consider how the data would be analysed. Just a quick test for understanding the basics.
But do you possibly have a tip for good literature around the subject. I mean, complete beginners/dummies guide? Maybe with some excercises? The things i have searched on the web are many times incomplete.
Alan Kirk wrote: The longer answer is...
What i wanted to do is just to summarize the values, with no requirement of analyzing the data on the lower than summarized levels.
What i did try was to: write this in the Turbo Integrator , create a new variable (parkingAreaTot) which simply added them.

parkingAreaTot = 'parkingAreaMain' + 'parkingAreaSec'... Either way it was not accepted as syntax.

Re: Generating sums from variables = Newbie question

Posted: Thu Jun 26, 2014 1:26 pm
by deepakjain2020
mixim wrote:Hello Alan, thanks for your reply!

But do you possibly have a tip for good literature around the subject. I mean, complete beginners/dummies guide? Maybe with some excercises? The things i have searched on the web are many times incomplete.
Following link willb e helpful
http://www-01.ibm.com/support/docview.w ... wg27039342

but it needs lot of patience and interest to go through the concepts.
mixim wrote:
What i wanted to do is just to summarize the values, with no requirement of analyzing the data on the lower than summarized levels.
What i did try was to: write this in the Turbo Integrator , create a new variable (parkingAreaTot) which simply added them.

parkingAreaTot = 'parkingAreaMain' + 'parkingAreaSec'... Either way it was not accepted as syntax.
Can you please share the screen shot along with the error?

Regards,
Deepak Jain

Re: Generating sums from variables = Newbie question

Posted: Thu Jun 26, 2014 1:35 pm
by jim wood
mixim wrote:parkingAreaTot = 'parkingAreaMain' + 'parkingAreaSec'... Either way it was not accepted as syntax.
A couple of things to note. When referncing another variable you don't need to put the names in quotes. So for example if I was adding values for variables A & B the forumula would be: C=A+B; not C='A'+'B';

Secondly if you are actually trying to bring together text you use the |. So for example: C='This is ' | 'way to do it'; again if you are trying to concatanate the text in two variables it would be C=A|' '|B; (assuming you need a space between the 2 strings.

I hope this helps,

Jim.

Re: Generating sums from variables = Newbie question

Posted: Thu Jun 26, 2014 10:24 pm
by Alan Kirk
mixim wrote:parkingAreaTot = 'parkingAreaMain' + 'parkingAreaSec'... Either way it was not accepted as syntax.
Just to expand on what Jim was saying, it's not that you don't need to put the quotes around the variables, it's that you don't. The difference is that if you put quotes around something (not just in TI but in programming languages generally) you're telling the language to treat those as literal strings (text); that is, add the text 'parkingAreaMain' to the text 'parkingAreaSec'. As Jim also noted in TI you can in fact link two strings together with the pipe (|) symbol but that's clearly not what you want here.

When you use the variable name without quotes you are telling TI that you want to use the value that is stored in the variable. Thus in the example above you would use:

Code: Select all

parkingAreaTot = parkingAreaMain + parkingAreaSec;
(remember the semi-colon at the end as well) after which you can use the new, user-defined variable parkingAreaTot in other functions like CellPutN. (Of course, you could also use the expression parkingAreaMain + parkingAreaSec directly as the first argument to CellPutN without needing to assign it to a third variable, though I'd commonly use the variable anyway as it helps make the code more transparent and self-documenting.)