Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
raajaswin
Creator III
Creator III

Max length of all fields in the Dashboard

Hi All,

I have a requirement to display the list of all the field names and its maximum value length.

I have tried max(len($Field)) in front end which gives me length of the field name not the value.

I have tried loops in script tried max(len(FieldName(Field,Table)) , again it gave length of the field name not the value..

Please suggest a solution.. Front end or in script any thing is fine

My desired o/p is

 

Table NAmeField NameMaxlength
Table1Field122
Table1Field210
Table2Field1121
Table2Field223
Table2Field334
Table3Field120

 

 

 

 

 

 

 

 

 

1 Solution

Accepted Solutions
Taoufiq_Zarra

Hi,

one solution on load Script :

Suppose I have those Tables :

Taoufiq_ZARRA_0-1592924675095.png

 

The Script :

Table1:
load * inline [
A,B,C
1,2564,56464 dfgs
10,25,56464 dfgssd
];


Table2:
load * inline [
AA,BB,CC
1sdfd,25sdfs64,56fdsfds464 dfgs
1fsdf,2ff5,56dfsdffsdfsdfd464 dfgssd
];


FOR i = NoOfTables()-1 to 0 STEP -1

  LET vTable=TableName($(i));
  
  
  FOR j =1 to  NoOfFields('$(vTable)')
 
FieldMax:
  let vFieldName=FieldName($(j),'$(vTable)') ;
 //let vfakue=Peek($(vname),'$(vTable)');

   
   LOAD 
   
     len($(vFieldName)) as lengthfield,
   '$(vTable)' as [Table Name],
   '$(vFieldName)' as [Field Name]
   
    RESIDENT [$(vTable)];
  
  NEXT j
   

NEXT i


outputFieldMax:
noconcatenate
load [Table Name],[Field Name], max(lengthfield) as Maxlength resident FieldMax group by [Table Name],[Field Name] ;

drop table FieldMax;

 

The output :

Taoufiq_ZARRA_1-1592924731702.png

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

5 Replies
yogi_myd
Contributor II
Contributor II

hi,

Find the Max length of the fields in each table while load itself and sort by Descending order. 

Do the Resident load where rowno=1 and concatenate as single table and present in the dashboard.

Regards

Yogesh.

Taoufiq_Zarra

Hi,

one solution on load Script :

Suppose I have those Tables :

Taoufiq_ZARRA_0-1592924675095.png

 

The Script :

Table1:
load * inline [
A,B,C
1,2564,56464 dfgs
10,25,56464 dfgssd
];


Table2:
load * inline [
AA,BB,CC
1sdfd,25sdfs64,56fdsfds464 dfgs
1fsdf,2ff5,56dfsdffsdfsdfd464 dfgssd
];


FOR i = NoOfTables()-1 to 0 STEP -1

  LET vTable=TableName($(i));
  
  
  FOR j =1 to  NoOfFields('$(vTable)')
 
FieldMax:
  let vFieldName=FieldName($(j),'$(vTable)') ;
 //let vfakue=Peek($(vname),'$(vTable)');

   
   LOAD 
   
     len($(vFieldName)) as lengthfield,
   '$(vTable)' as [Table Name],
   '$(vFieldName)' as [Field Name]
   
    RESIDENT [$(vTable)];
  
  NEXT j
   

NEXT i


outputFieldMax:
noconcatenate
load [Table Name],[Field Name], max(lengthfield) as Maxlength resident FieldMax group by [Table Name],[Field Name] ;

drop table FieldMax;

 

The output :

Taoufiq_ZARRA_1-1592924731702.png

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
raajaswin
Creator III
Creator III
Author

Yes This is working. Thanks..

 

But it loads all the columns again.. like if there are 200 columns in the dashboard. It loads all the columns again.. I am using this solution as of now. But please let me know if something can be done in a optimized way either in front end or scripting

Taoufiq_Zarra

yes!

Table1:
load * inline [
A,B,C
1,2564,56464 dfgs
10,25,56464 dfgssd
];


Table2:
load * inline [
AA,BB,CC
1sdfd,25sdfs64,56fdsfds464 dfgs
1fsdf,2ff5,56dfsdffsdfsdfd464 dfgssd
];


FOR i = NoOfTables()-1 to 0 STEP -1

  LET vTable=TableName($(i));
  
  
  FOR j =1 to  NoOfFields('$(vTable)')
 
FieldMax:
  let vFieldName=FieldName($(j),'$(vTable)') ;
 //let vfakue=Peek($(vname),'$(vTable)');

   
   LOAD 
   
     Max(len($(vFieldName))) as lengthfield,
   '$(vTable)' as [Table Name],
   '$(vFieldName)' as [Field Name]
   
    RESIDENT [$(vTable)];
  
  NEXT j
   

NEXT i
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
tresesco
MVP
MVP

A UI solution would be a tricky one but possible.

 

$(=concat('if($Field=' & chr(39) & $Field & chr(39) & ',Max({1}Len([' & $Field & ']))', ',') & concat(right($Field&')',1)))

 

tresesco_0-1592989487557.png

Credit goes to @rbecher