Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

yamananalytic
Contributor II

How to convert GUID to int !!!

Hi guys,

i want to use Peek function to get a value of a specific row but the IDs of field is not a type of integer ,it is a type of uniqueidentifier like

00000000-0000-0000-0000-000000000001

so i want to convert this id to number of type int like :   00000000-0000-0000-0000-000000000001  ==>  1

please can help me to do that .

stalwar1

swuehl

jvs

Tags (1)
1 Solution

Accepted Solutions
chauhans85
Esteemed Contributor

Re: How to convert GUID to int !!!

using this , i getting  1 as a result.

Take below expression in text box

=mid( '00000000-0000-0000-0000-000000000001',FindOneOf('00000000-0000-0000-0000-000000000001','123456789'),len('00000000-0000-0000-0000-000000000001')-1) 


here i am taking '00000000-0000-0000-0000-000000000001' as Example screen which


you can use this for genralized


use below in script

mid( fieldname,FindOneOf( fieldname,'123456789'),len( fieldname)-1) as Newfieldname ///try this in script


and see the result in Newfieldname at front end

21 Replies
MVP
MVP

Re: How to convert GUID to int !!!

Not sure why you want to use the Peek() function or what your final result should be.

It would be good to see a sample of input data and an expected result table.

To convert a text value (that's how I see your GUID, right?) into a number, you can for example use one of the Autonumber() or AutonumberHashXXX() functions.

autonumber - script function ‒ Qlik Sense

OmarBenSalem
Esteemed Contributor

Re: How to convert GUID to int !!!

table:

load num( right(YourField, 1) )as NewField

from source;

let vYourRow= Peek('NewField',Position(numeric), 'table'); //exp : let vYourRow= Peek('NewField',0, 'table');

Re: How to convert GUID to int !!!

‌Are you just looking to get a numeric value from your GUID? If that is what you want, then may be you need to use KeepChar()... or PurgeChar()

KeepChar(FieldName, ‘0123456789’) * 1

yamananalytic
Contributor II

Re: How to convert GUID to int !!!

Hi Mr.Stefan

i want to know the position of the raw which i want to peek value from ,since the ID field is GUID and i tried to pass it to Peek function but the result was NULL. so i want to convert GUID to int to pass it to Peek function

yamananalytic
Contributor II

Re: How to convert GUID to int !!!

Hi Mr.Sunny

what i want to do is to get the specific value of the specific field but in order to use peek function i have to pass the index of the row where the value exist but the ID Field of my table is GUID like 00000000-0000-0000-0000-000000000001 not int like 2,3,4 so i want to convert this GUID to number in order to pass it to Peek fucntion.

yamananalytic
Contributor II

Re: How to convert GUID to int !!!

Hi Mr. Stefan

what i want to do is to get the specific value of the specific field but in order to use peek function i have to pass the index of the row where the value exist but the ID Field of my table is GUID like 00000000-0000-0000-0000-000000000001 not int like 2,3,4 so i want to convert this GUID to number in order to pass it to Peek fucntion.

Re: How to convert GUID to int !!!

‌Don’t think I understand what you are after. Can you explain with more example data points?

MVP
MVP

Re: How to convert GUID to int !!!

Not sure I understand your request.

Maybe create a row number in your load by using Recno() or RowNo() functions when loading the table:

Counters in the Load

Table:

LOAD

     Recno() as RecID,

     GUID,

     OtherField,

     AnotherField,

     ...

FROM ...;

Or use Lookup() function to pass a field value (GUID) as search value in your table search and to retrieve another field value in the same row.

LookUp - script function ‒ Qlik Sense

yamananalytic
Contributor II

Re: How to convert GUID to int !!!

yes that what i want

my problem will be solved by using Recno() but my data coming from SQL server and i tried to write :

select Recno() as RecID,GUID,... from my table after opening connection but there is an runtime error

Community Browser