Tip of the Week

Retrieving values from one column to use in an expression in another Column

A couple weeks ago we did a post that discussed how to rank something over various groups in their dataset. As a variation of this, many situations arise where customs need to find values in a specific column inside an expression available in another column. We will explain this scenario with an example.

Let’s assume we have the following data set:

 


 

As part of the analytics required for a workflow, we may need to retrieve the value from the Volume column that corresponds to the last Date entry per month.  This value will eventually be used in another expression. So , for example, using the data above, for November 2009, we want to use the Volume value from Nov 20,2009 (the last entry in November). This value is 32212.


First, we need to use what we learned in our post from a couple weeks ago to create a unique id column for each month. For this we can create a calculated column using the expression below , and call the column UID:

      integer(Year([Date])*100 + Month([date]))

 

Now, what we need to do is ideally use the expression below to get the value from the Volume column:

      Sum(if(([Date])=(Max([Date]) OVER [UID]),[Volume],0))

However, this will not work, as we cannot put the Max([Date]) aggregate function inside another expression like this.

To solve this, we need to add an intermediate step, which is to create another calculated column. This calculated column will contain the last date entry per each month:

      Max([Date]) OVER UID


 


Once we have this, assuming the newly created column is called “Max Date per Month”, we can use the following expression to retrieve the value from the Volume column for the last entry in each Month:

    if(([Date]) = ([Max Date per Month]),[Volume],0)

 


To go one step further, what if we wanted each row to have  the value corresponding to the last entry for that month, so all rows from November 2009 would have  the value 32212? For this, we would need to add another OVER statement to group by the Max Date per Month.

    Sum(if(([Date])=([Max Date per Month]),[Volume],0)) OVER ([Max Date per Month])

Since this has an OVER method in it, we need to add an aggregation method.  For this, we used Sum.

 

 

Comments

 

Raj said:

i have a question....

I have following situation:-

ID           RequirmentID                                     ReviewPhase                     Score

1                      35                                              First                                      34

1                      36                                             First                                       34

1                      38                                             Second                                   38

1                     37                                             Third                                           39

i want to calculate the highest score depending on the review phase. But, there is a condition in it.... the condition is:-  i need to find the greater value (score) between  first and second review phase if third phase is 0.. other wise if third phase is not zero it should always take third phase score....

so i cannot use max function for this....which function should i use to compare two values out of three values,, and how to access individual value of a column..i was thinking if this is possible:- review_Phase.First or review_phase. second....

if anyone knows it..i would be thank ful.....

November 23, 2011 11:57 AM
 

Raj said:

i have a question....

I have following situation:-

ID           RequirmentID                                     ReviewPhase                     Score

1                      35                                              First                                      34

1                      36                                             First                                       34

1                      38                                             Second                                   38

1                     37                                             Third                                           39

i want to calculate the highest score depending on the review phase. But, there is a condition in it.... the condition is:-  i need to find the greater value (score) between  first and second review phase if third phase is 0.. other wise if third phase is not zero it should always take third phase score....

so i cannot use max function for this....which function should i use to compare two values out of three values,, and how to access individual value of a column..i was thinking if this is possible:- review_Phase.First or review_phase. second....

if anyone knows it..i would be thank ful.....

November 23, 2011 11:57 AM
 

uggkensington said:

http://www.uggkensingtons.org/

http://www.uggkensingtons.org/ugg-fox-fur-short-boots-5531-c-54.html | UGG Fox Fur Short Boots 5531

http://www.uggkensingtons.org/ugg-kensington-boots-5678-c-2.html | UGG Kensington Boots 5678

http://www.uggkensingtons.org/ugg-rainier-eskimo-boots-5189-c-85.html | UGG Rainier Eskimo Boots 5189

http://www.uggkensingtons.org/ugg-retro-cargo-boots-1895-c-3.html | UGG Retro Cargo Boots 1895

December 27, 2011 8:13 PM
 

uggskensingtonsale said:

www.uggskensingtonsale.org

www.uggskensingtonsale.orgugg-adirondack-boots-ii-c-6.html | UGG Adirondack Boots II

www.uggskensingtonsale.orgugg-adirondack-tall-boots-c-11.html | UGG Adirondack Tall Boots

www.uggskensingtonsale.orgugg-amberlee-boots-c-34.html | UGG Amberlee Boots

www.uggskensingtonsale.orgugg-annabelle-boots-c-35.html |

December 28, 2011 4:09 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Syndication

Other Spotfire Blogs

Spotfire's interactive information visualization and analytic solutions give users a remarkable experience for quickly and easily querying data and reporting results for superior business intelligence. From portfolio management and customer retention programs to key processes such as CRM, marketing, research, bioinformatics, yield and asset management and design for manufacturing, enterprises around the world rely on Spotfire's business analytics software to improve operational performance.

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center