Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
hansdevr
Creator III
Creator III

Peek() is critical about field names

Hi Everyone,

A small word of warning on using the peek() function.

I ran into a problem when using this function and it took me quite some time to figure out what I was doing wrong. Finally, I found the answer and I thought I's share it with you all, so you can avoid spending all the time I lost with it.

I was trying to substract two amounts, to give me mutations in stead of amount cumulatives:

if(%key <> previous(%key),
[amount in €],
[amount in €] - peek('[amount in €]')
) as
[mutation in €]

But each time I only got 1 value for [mutation in €], the rest was NULL..

So what was I doing wrong?

I simply had to rename my fields containing spaces to fieldnames WITHOUT spaces.

Somehow, peek() doesn't respond kindly to fieldnames between brackets.

So when I did this, it worked fine:

if(%key <> previous(%key),
amount_in_€,
amount_in_€ - peek('amount_in_€')
) as
[mutation in €]

7 Replies
Gysbert_Wassenaar

peek('[amount in €]')

The problem is that peek expects the literal field name. And the field name is not [amount in €], but amount in €. So peek('amount in €') will work fine. Just leave out the square brackets and enclose the actual field name in single quotes. As long as your field name itself doesn't contain single quotes you'll be fine.


talk is cheap, supply exceeds demand
hansdevr
Creator III
Creator III
Author

This was new to me, Gysbert. I had to find out the hard way, this time (t&e).. Thanks for the addition!

aarkay29
Specialist
Specialist

Did you try like this??

I believe the below one should work because when a field name is given between quotes it will also consider [] as fieldname.So just give the field name without [] for any field within the quotes.


if(%key <> previous(%key),
[amount in €],
[amount in €] - peek('amount in €')
) as
[mutation in €]

hansdevr
Creator III
Creator III
Author

Gysbert just beat you to it, but thnx anyway!

Gysbert_Wassenaar

Whoa! Are you working on a 17'' screen at a 4K resolution? The rest of us can read text are normal sizes just fine. The size you're using makes it hard to read for us. Please use a smaller font size.


talk is cheap, supply exceeds demand
hansdevr
Creator III
Creator III
Author

aarkay29
Specialist
Specialist

Sorry guys i was using my mobile wasn't aware that it would display gigantic letters.