Jump to content
Sign in to follow this  
Maarten Witberg

Expanded exploded key, how?

Recommended Posts

Maarten Witberg

I have this string:

 

123456

 

And I want to produce this result:

 

1

12

123

1234

12345

123456

2

23

234

2345

23456

3

34

345

3456

4

45

456

5

56

6

 

Right now I am tackling this as follows:

 



[b]ExplodedKeyRight ( Text ) =[/b]

If (
 Length ( Text ) > 1 ;
 ExplodedKeyRight ( Right ( Text ; Length ( Text ) - 1 ) ) & "¶" & Text ;
 Text
 )

slightly modified from the original found at Briandunning.com, this produces

 

6

56

456

3456

23456

123456

 

But I want to see the exploded keys of all of the values in that list, so I run it through the original :

[b]ExpandedExplodedKey ( Text ) =[/b]
ExplodedKey 
(  
Case 
 (
  Length ( Text ) > 1 ;
  ExplodedKeyRight ( Right ( Text ; Length ( Text ) - 1 ) ) & "¶" & Text ;
  Text
  )
)
/*
[i]btw the original is: 
Explodedkey ( Text ) =
Case
(
 Length ( Text ) > 1 ;
 ExplodedKey ( Left ( Text ; Length ( Text ) - 1 ) ) & "¶" & Text ;
 Text
 )[/i]
*/

Now while this produces a result that holds all values, there are many duplicates. I have tried many versions of this approach, but I can't figure out a way to produce a list that has only unique values. I hope someone can help me, I am running in circles.

Share this post


Link to post
Share on other sites
Ender

Hi kjoe,

 

Here's the version that I made a while back for this thread:

 

http://fmforums.com/forum/showtopic.php?tid/149072/

 

//ExplodedPermutations(text)
//by Mike Hackett

//for making a multi-key with all groupings of consecutive letters

Let(
 right = Right(text;Length(text)-1);
 ExplodedKey(text)  & ¶ & 
 Case(Length(right) > 1; 
     ExplodedPermutations(right); 
     right)
)

 

That uses the original ExplodedKey() from Andrew LaCates as a sub-function.

Share this post


Link to post
Share on other sites
LaRetta

Mike's CF works quite well. I've used it in very large record-sets and it's pretty quick as well (considering the work it has to do). smiley-smile

Share this post


Link to post
Share on other sites
Maarten Witberg

Hi Mike, it is working great. Thank you very much!

 

Maarten

 

:cool:

Share this post


Link to post
Share on other sites
mfleong1

I hope this is the right place for me to post this question. I have been trying to write a CF that is somewhat like explode key. Here is what I am trying to do.

 

I have a list of values like:

 

AB

XYZ

THE

 

I need to generate a list that will have all the combination like this below:

AB,XYZ

XYZ,AB

AB,THE

THE,AB

XYZ,THE

THE,XYZ

AB,XYZ,THE

AB,THE,XYZ

XYZ,AB,THE

XYZ,THE,AB

... and so on

 

The resulted list can get very long depending on how many values are there in the original list ..

 

Thanks in advanced

Share this post


Link to post
Share on other sites
Ender

I believe you would need two recursive CFs to do this. But before we get into it, can you tell us what this is for? Why are the combinations important?

Share this post


Link to post
Share on other sites
mfleong1

Pardon for my English. I will try to explain what I am trying to achieve

 

I have two table: Table A and Table B. Then there is a valuelist that contain the list of value

 

What I am thinking is to have a calculated field in Table A to store the 'Expanded key' (from the valuelist) that has all the combination. Then this field is link (relationship) to one field in Table B. The value in this field in Table B contains one of the combination in the Expanded Key. The purpose is to have a portal to display those records in Table B that has at least one of the match combination.

 

Thank you

Share this post


Link to post
Share on other sites
Ender

Well, I can't really picture generallities like "Table A" and "Table B", but if you're looking to build a relational key, it should be possible without concatonating values. I can't say more without knowing what you're really doing.

Share this post


Link to post
Share on other sites
oleung

Hi,

 

I have a similar situation as what you mentioned here. Do you have a solution to share.

 

Yes, agree with you. This is essential when there is a look up between two table where the master table key to join a secondary table with a combined of value from different fields. The secondary table needs a calculation field to prepare the multi-key fields. The question here is how to build up the multi-key which can produce all the combination keys.

 

e.g

Secondary Table has three fields with drop down value "A", "B", "C" or "D"

and one calculated field

 

field1 value = "A"

field2 value = "C"

field3 value = "D"

 

I like to generate a calculated field with result like the following:

 

calculated field value should return:

A

A,C

A,C,D

C,D

C,A

C,D,A

D

D,C

D,A

D,C,A

 

 

Advice would be much appreciated.

 

Thanks,

 

Pardon for my English. I will try to explain what I am trying to achieve

 

I have two table: Table A and Table B. Then there is a valuelist that contain the list of value

 

What I am thinking is to have a calculated field in Table A to store the 'Expanded key' (from the valuelist) that has all the combination. Then this field is link (relationship) to one field in Table B. The value in this field in Table B contains one of the combination in the Expanded Key. The purpose is to have a portal to display those records in Table B that has at least one of the match combination.

 

Thank you

Share this post


Link to post
Share on other sites
Maarten Witberg

I'm not sure I follow everybody's purpose, but here's a bit of theory (and a sample by David Head) that may help.

Share this post


Link to post
Share on other sites
Ender

oleung,

 

I have the same problem with your question as I did with mfleong1. Without knowing the purpose, it's hard to come up with a CF that fits. Also, the A,B,C short-hand makes it harder to understand than if you used a real-world example.

 

So basically, my answer is the same: It will likely require two recursive CFs (or maybe one CF with two iterative counters). The algorithm itself should be pretty simple.

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



×
×
  • Create New...

Important Information

Terms of Use