Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Keitaru
Creator II
Creator II

How to Calculate Mb and Kb to byte in QlikSense Script?

I'm working on a data set I've attached below looking to convert Mb and Kb down to bytes, however I don't really know how to do so do so... I've done it on python but not sure with QlikSense Load Script how can I do the calculation.

 

Python Code looks somewhat like this:
df1.Size = (df1.Size.replace(r'[kM]+$', '', regex=True).astype(float) * \ df1.Size.str.extract(r'[\d\.]+([KM]+)', expand=False)
.fillna(1).replace(['k','M'], [10**3, 10**6]).astype(int))

 

 

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

With your data "nnS', the process would be to remove the S (scale character) to get the numeric part and multiply by the appropriate scale value.  There are numerous ways to write the conditional scale value, but here is perhaps a simple and clear (to me) way. 

keepchar(Size, '0123456789') * if(Size like '*M', (1024*1024), if(Size like '*k', 1024, 1))

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

View solution in original post

2 Replies
m_woolf
Master II
Master II

Something like:

If Label = 'KB',Value*1024,
      If Label = 'MB',Value*1024*1024)) as Bytes

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

With your data "nnS', the process would be to remove the S (scale character) to get the numeric part and multiply by the appropriate scale value.  There are numerous ways to write the conditional scale value, but here is perhaps a simple and clear (to me) way. 

keepchar(Size, '0123456789') * if(Size like '*M', (1024*1024), if(Size like '*k', 1024, 1))

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com