1. François Rossignol
  2. PowerBuilder
  3. Wednesday, 11 March 2020 14:27 PM UTC

Hi

I need help figuring out the correct expression (if at all possible) for the following case.

 

I have a datawindow

Each row have:

column1 which will have A B C or D as value

column2 a decimal value

 

In the header I want a compute to display a value depending and the column1 of the first line which I can do by testing first(column1 for all)

Now this is where it gets tricky

if column1 = "A" or "B" then column2 from row 1

if column2 = "C" then column2 from the first line where column1 is either "A" or "B"

if column2 = "D" then 0

 

I can't figure out the "then" part of the = "C" part.

 

I know I can do it without a compute with some code but I'd really like to have everything inside the DW in this case.

 

We're using PB 2017 R3

 

Thanks in advance for any usefull tip.

 

Regards

Accepted Answer
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Wednesday, 11 March 2020 15:08 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi François,

I think I understand what you are trying to do.

For your condition column1 = 'C' you will need to have a way of finding the first row that matches Column1 = 'A' or 'B'.

I have not tried this be her are my thoughts:

1. Compute a value on each row for the rownum, you can do this in the SQl query call it rownumx

2. Add a computed column that is something like this: if ( column1 = 'A' or  column1  = 'B',   rownumx , 999999) Call it abrow

3. Add a computed column: if(  rownumx = min(  abrow for all),  column2 , 0) call it firstrowcol2

4. Add a computed column in your header: if (first( column1 for all) = 'C', max(  firstrowcol2 for all), 0) 

Replace the else condition for your other values. Job done :)

 

Cheers

 

David

Comment
  1. François Rossignol
  2. Wednesday, 11 March 2020 15:39 PM UTC
Thank you



I did it with less computed field



on the detail I added a computed field named compute_valorisation



if

(

type_valorisation = "D" or type_valorisation = "V"

, valeur_totale

, if

(

type_valorisation = "C" and bool_cession_totale = "V"

, 0

, dec(describe('evaluate("compute_valorisation",'+string(getrow()+1)+')')) - valeur_totale

)

)



I won't have a problem with the getrow() + 1 because the last row of the datawindow always have the same "column1"



if my header I just used a first(compute_valorisation for all)
  1. Helpful
  1. David Peace (Powersoft)
  2. Wednesday, 11 March 2020 15:43 PM UTC
Your welcome.
  1. Helpful
There are no comments made yet.
François Rossignol Accepted Answer Pending Moderation
  1. Wednesday, 11 March 2020 15:05 PM UTC
  2. PowerBuilder
  3. # 1

Thank you for your answer

My bad all the tests are on column1

 

Actual values are not A B C D, are not ordered and the actual test uses two columns.

large (which I did not know about) won't apply here.

 

I think I'll need to use some intermediary computes

 

Comment
  1. René Ullrich
  2. Wednesday, 11 March 2020 15:08 PM UTC
The values must not be ordered. The largest takes the value from first row where the expression if (column1 = 'A' or column1 = 'B', 1, 0) has the value 1. This is the first row with A or B as you want (so I thought).
  1. Helpful
  1. François Rossignol
  2. Wednesday, 11 March 2020 15:35 PM UTC
I think I totally misunderstood how large works ;)



I tried it but there's something wrong if there's more than 1 C line at the start



Case 1:

Row 1 : C -> 1000

Row 2 : V -> 1200

Row 3 : V -> 900



Large return 1200



Row 1 : C -> 1000

Row 2 : C -> 200

Row 3 : V -> 1200

Row 4 : V -> 900



Large return 900 (and I want 1200)

  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 11 March 2020 14:55 PM UTC
  2. PowerBuilder
  3. # 2

Hi François,

I think what your are looking for you can do with the function "large":

 

large( column2, if (column1 = 'A' or column1 = 'B', 1, 0), 1 for all )

 

Means: Give me the value of column2 where in the expression the value is the first largest.

 

HTH,

René

Comment
  1. David Peace (Powersoft)
  2. Wednesday, 11 March 2020 15:25 PM UTC
Hi René



Large function, I'll remember that one... nice :)
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 11 March 2020 14:33 PM UTC
  2. PowerBuilder
  3. # 3

Hi François,

It is not clear what you want. In the second and third condition you compare column2 with a string. But column2 should be a decimal!?

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.