# Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

New Contributor III

## 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 MVP & Luminary

## Re: How to Calculate Mb and Kb to byte in QlikSense Script?

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))

2 Replies
Honored Contributor II

## Re: How to Calculate Mb and Kb to byte in QlikSense Script?

Something like:

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

## Re: How to Calculate Mb and Kb to byte in QlikSense Script?

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))