Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
LeHaoNguyen
Contributor III
Contributor III

Use String as Field in Diagram Function

Hi all,

i want to make a diagram to show the working stock of each process point.

So i got two tables.

One with all Timestamps from CheckIn to CheckOut with the following Columns:

Projectnumber, Documentbarcode, CheckInDate, PreparationDate, ClassificationDate, CheckOutDate

if a Datefield isnt filled it didnt went through this processstep yet and is NULL.

And one Table with the Process Order with following Columns:

Projectnumber, Processnumber, Processname

Because every Project can have different Process Orders we need the 2nd Table to see the right order.

My Goal is now if the user filter on a Projectnumber to show how many Documentbarcodes are already gone through processnumber 1 but not 2,3... and how many are gone through processnumber 2 but not 3,4... and so on.

My Idea was to create a new Field in the 2nd Table: tmp_field.  The Fieldvalue of this field contains the name of the Column it need to go to. So if  Processname of the Row is Checkin in the new Field would be CheckInDate. Now i want to parse the string i get somehow

=Only({$<Processnumber={1}>}tmp_field)

or

=FieldValue('tmpfield','1')

both return CheckInDate. But i need the List of Values from the first Table. is there a way to return all Entries of the Column CheckInDate from the first Table somehow?

 

Labels (1)
1 Solution

Accepted Solutions
gmenoutis
Partner - Creator II
Partner - Creator II

Unfortunately, it seems that when using the evaluation operator, it gets executed at table level and not at row level, so we cant have a custom formula for each row.

Fortunately though, it can be done with some table modifications. Run the following script, and replace A with the name of your first table (the one with the date values) and B with your second table (the one with Processnumber). In the end, you will have a new column in the first called "NextProcessStep" which shows...what it says. Now the set analysis for your metrics is a simple sum.

// This creates a crosstable (unpivoted) table: For each Documentbarcode there are as many rows as non-null dates
C: Crosstable (Processstep,ProcessDate,2)
LOAD
Projectnumber,Documentbarcode // qualifiers
,CheckInDate as CheckIn
,PreparationDate as Preparation
,ClassificationDate as Classification
,CheckOutDate as CheckOut
resident A;

// Depending on the Projectnumber let's get the next processstep for each line
left join(C)
LOAD Projectnumber,Processnumber,Processstep,if(previous(Projectnumber)=Projectnumber,previous(Processstep),null()) as NextProcessstep
resident B
order by Projectnumber,Processnumber desc;

// We return the info to the first table by joining. We only keep the latest filled date record, and we have the next step.
left join(A)
LOAD Projectnumber,Documentbarcode, firstsortedvalue(NextProcessstep,-Processnumber) as NextProcessstep
resident C
group by Projectnumber,Documentbarcode;

drop table C;

View solution in original post

12 Replies
gmenoutis
Partner - Creator II
Partner - Creator II

Can you tell us your source data structure? It seems the first table is a pivoted version of the second which is how your source data are structured.

LeHaoNguyen
Contributor III
Contributor III
Author

So this is my first Table i only show 4 dates but we got much more like 11:

ProjectnumberDocumentbarcodeCheckInDatePreparationDateClassificationDateCheckOutDate
123456123456A00000111.02.201915.02.201913.02.201919.02.2019
123456123456A00000211.02.2019NULL14.02.2019NULL

 

the 2nd table:

ProjectnumberProcessnumberProcessnametmp_field
1234561CheckInCheckInDate
1234562ClassificationClassificationDate
1234563PreparationPreparationDate
1234564CheckOutCheckOutDate

 

i hope now its clear for you what i want

marcus_sommer

A string couldn't be used as fieldname and I also think that any approach with fieldvalue() won't be working respectively be practically.

I think I would just use a mapping-approach maybe something like this:

m: mapping load
      Projectnumber, CheckInDate & '|' & ClassificationDate & '|' & PreparationDate & '|' &   CheckOutDate
      from table1;

t:   load *, subfield(applyamp('m',Projectnumber, null()), '|', Processnumber) as New
      from table2;

- Marcus

LeHaoNguyen
Contributor III
Contributor III
Author

Hi Marcus,

i think your soulution wont help me at my problem let me describe it a bit further we got two initial tables with one with dates of each processstep:

ProjectnumberDocumentbarcodeCheckInDatePreparationDateClassificationDateCheckOutDate
123456123456D00000111.02.201915.02.201916.02.201923.02.2019
123456123456D00000215.02.2019NULLNULLNULL
123456123456D00000314.02.201916.02.2019NULLNULL
123456123456D00000417.02.2019NULLNULLNULL
654321654321D00000111.02.201914.02.201913.02.2019NULL
654321654321D00000213.02.2019NULL15.02.2019NULL
654321654321D00000314.02.2019NULL19.02.2019NULL

and one with processorder for each project:

ProjectnumberProcessnumberProcessstep
1234561CheckIn
1234562Preparation
1234563Classification
1234564CheckOut
6543211CheckIn
6543212Classification
6543213Preparation
6543214CheckOut

 

So in project 123456 we got following process order:CheckIn>Preparation>Classification>CheckOut

and in Project 654321 we got following process Order: CheckIn>Classification>Preparation>CheckOut

now i want to create a third table which has the workstock for each processstep grouped by Projectnumber:

ProjectnumberPreparationWorkstockClassificationWorkstockCheckOutWorkStock
123456210
654321201

 

So the Workstock of each processstep is determined by the order of the processsteps but i dont know how to link those two tables together to get the desired table.

So the Logic is if field is filled then check what is the next projectstep if its empty and all following till the end are empty the count of the workstep after the filled one get +1.

I hope you understand what the goal is. it is not easy to explain 🙂

gmenoutis
Partner - Creator II
Partner - Creator II

What you hope to achieve is VERY complex, and certainly not possible with one line of code.

Do you have the ability to make changes to the script?

marcus_sommer

Instead of using the Processnumber you could apply a numeric value for each Processstep maybe in beforehand with a dual() or just within the subfield(), for example:

subfield(applyamp('m',Projectnumber, null()), '|',
   match(Processstep, 'CheckIn', 'Classification', 'Preparation', 'CheckOut'))

- Marcus

gmenoutis
Partner - Creator II
Partner - Creator II

Also: Can there be missing dates? For example, could a projectnnumber 654321 with barcode 654321D000004 have a checkin date (step 1), a prepeartaion date (step 3), but be missing the value for classification date (step 2)? If yes, then how would this barcode be counted in that case?

LeHaoNguyen
Contributor III
Contributor III
Author

yes this can happen but is not really common then its in the workstock for checkout(step 4)

and i can make any changes to the script(data structure if needed)

gmenoutis
Partner - Creator II
Partner - Creator II

Unfortunately, it seems that when using the evaluation operator, it gets executed at table level and not at row level, so we cant have a custom formula for each row.

Fortunately though, it can be done with some table modifications. Run the following script, and replace A with the name of your first table (the one with the date values) and B with your second table (the one with Processnumber). In the end, you will have a new column in the first called "NextProcessStep" which shows...what it says. Now the set analysis for your metrics is a simple sum.

// This creates a crosstable (unpivoted) table: For each Documentbarcode there are as many rows as non-null dates
C: Crosstable (Processstep,ProcessDate,2)
LOAD
Projectnumber,Documentbarcode // qualifiers
,CheckInDate as CheckIn
,PreparationDate as Preparation
,ClassificationDate as Classification
,CheckOutDate as CheckOut
resident A;

// Depending on the Projectnumber let's get the next processstep for each line
left join(C)
LOAD Projectnumber,Processnumber,Processstep,if(previous(Projectnumber)=Projectnumber,previous(Processstep),null()) as NextProcessstep
resident B
order by Projectnumber,Processnumber desc;

// We return the info to the first table by joining. We only keep the latest filled date record, and we have the next step.
left join(A)
LOAD Projectnumber,Documentbarcode, firstsortedvalue(NextProcessstep,-Processnumber) as NextProcessstep
resident C
group by Projectnumber,Documentbarcode;

drop table C;