logo
search
Power Query Problems

How to Convert KB, MB, and GB File Sizes to Bytes in Excel

Maira MehtabMaira Mehtab Sep 22, 2026 869 views

Question details

The user wants to import a directory listing into Excel and view or convert file sizes in bytes so they can easily sort and manage large files.

Product
Microsoft Excel
Device & OS
not provided
Scenario
Importing hundreds of file listings from a folder into a spreadsheet to organize them by size for archiving or offline storage purposes.
Observed behavior
Windows File Explorer displays file sizes in mixed formats (KB, MB, GB), which makes sorting files by actual size difficult in a raw spreadsheet without standardizing them to bytes.
Before you start

Ensure you have the exact file path of the folder you want to analyze and verify that you are using Excel 2016 or later, which has the Power Query feature built-in.

Solution 1Recommended

Use Power Query to Import Folders and Extract Sizes in Bytes

Power Query can automatically pull folder contents into Excel, extracting exact file attributes like sizes in bytes, which allows for perfect sorting and conversion.

Power Query is the most robust method for this task because it dynamically links to your folder. It extracts the raw file size in bytes automatically, bypassing the mixed-unit display of Windows Explorer.

1
Launch Get Data

Open Excel, go to the 'Data' tab on the ribbon, click on 'Get Data', select 'From File', and then click 'From Folder'.

2
Select the Target Folder

Browse to the folder containing the files you want to sort, select it, click 'Open', and then click 'Transform Data' in the preview dialog box to launch the Power Query Editor.

3
Expand File Attributes

In the Power Query Editor, locate the 'Attributes' column and click the double-arrow expand icon in the column header. Ensure the 'Size' box is checked and click 'OK'.

4
Set Data Type to Whole Number

Select the newly expanded 'Size' column (which displays values in bytes natively). Go to the 'Home' tab, click the 'Data Type' dropdown, and choose 'Whole Number'.

5
Load and Sort Data

Click 'Close & Load' in the top-left corner to output the data into an Excel table. You can now use the dropdown arrow on the 'Size' column header to sort from Largest to Smallest.

Dynamic Updating: If you add or remove files in the target folder later, simply click 'Refresh All' on the Excel Data tab to update your spreadsheet instantly.
Convert File Sizes Seamlessly

Sort and Convert File Data with WPS Spreadsheet

WPS Spreadsheet provides powerful data processing capabilities. Once you import your file data, you can quickly convert bytes into KB, MB, or GB using built-in mathematical functions and sort them efficiently.

  1. 1. Open Your Dataset: Launch WPS Spreadsheet and open the document containing your raw file listing and byte sizes.
  2. 2. Calculate KB, MB, or GB: In an empty column next to your byte sizes (e.g., column B), type `=A2/1024` for KB, `=A2/1048576` for MB, or `=A2/1073741824` for GB, and press Enter.
  3. 3. Apply Formula to All Rows: Click the bottom-right corner of the cell containing your new formula and drag it down to apply the size conversion to all files in the list.
  4. 4. Sort by Size: Highlight your data range, navigate to the 'Data' tab, click 'Sort', and choose to sort by your new file size column from largest to smallest.
100% format compatibility with Microsoft Excel (.xlsx) filesRobust built-in formulas for instant unit conversionLightweight application with high performance for large datasets
microsoft office alternative - wps office

Frequently Asked Questions

Can I convert file sizes from MB back to Bytes in Excel?

Yes. If you have a column with file sizes in Megabytes (MB), you can convert it to Bytes by multiplying the value by 1,048,576 (which is 1024 x 1024). Use a formula like `=A2*1048576` to get the exact size in bytes.

Why use Power Query instead of manual entry for file sizes?

Power Query automates the extraction of file attributes directly from Windows Explorer. This eliminates manual data entry, prevents human error, and ensures that you can handle thousands of files in just a few clicks.

Does Power Query automatically update if files are added to the folder?

Yes. Once you have set up the Power Query folder connection, it acts as a live link. You can simply go to the Data tab and click 'Refresh All', and Excel will automatically pull in the latest file listings and sizes.