Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
rajiramk
Frequent Visitor

Convert Bytes to KB/MB/GB

I have used the below code to create a formula to convert Bytes into KB, MB, GB, TB. The calculation seems to be right but when we are validating the size between Azure cloud and Power BI there is slight difference in size. 

 

For example:

I have one file size 49106756748 bytes, when it is converted to GB , it shows 45.73GB in Power BI where as Azure shows 49.16GB.

 After doing google search, the size shown as 45.73 GB is Gibibytes where as 49.16 GB is the right Gigbyte size.

 

I am not sure how to change the calculation to show GB value nstead of Gibibyte value in Power BI. The current formula used is:

 

Size  =
VAR total =
    SUM ( Query1[Size of Data]) + 0
RETURN
    IF (
        total < 1024,
        FORMAT ( total, "#0.0# B" ),
        IF (
            total < POWER ( 2, 20 ),
            FORMAT ( total / POWER ( 2, 10 ), "#0.0# KB" ),
            IF (
                total < POWER ( 2, 30 ),
                FORMAT ( total / POWER ( 2, 20 ), "#0.0# MB" ),
                IF (
                    total < POWER ( 2, 40 ),
                    FORMAT ( total / POWER ( 2, 30 ), "#0.0# GB" ),                
                    FORMAT ( total / POWER ( 2, 40 ), "#0.0# TB" )
                   )
                )
            )  
        )
 
Appreciate all the help. Thank you.
6 REPLIES 6
Alef_Ricardo_
Resolver II
Resolver II

The reason for the discrepancy in the size representation between Power BI and Azure is due to the difference between "Gigabytes" (GB) and "Gibibytes" (GiB). Power BI's formatting is using "Gibibytes" (GiB), which is based on the binary system, while Azure might be using "Gigabytes" (GB), which is based on the decimal system. 1 GB is typically defined as 1,000,000,000 bytes, while 1 GiB is defined as 1,073,741,824 bytes.

If you want to display the size in "Gigabytes" (GB) as Azure does, you can modify your DAX formula to accommodate the decimal-based definition of a gigabyte. Here's an adjusted version of your formula:

```DAX
Size =
VAR total = SUM(Query1[Size of Data]) + 0
RETURN
IF (
total < 1024,
FORMAT(total, "#0.0# B"),
IF (
total < 1000000000, -- Check if the size is less than 1 GB (decimal)
FORMAT(total / 1024, "#0.0# KB"),
IF (
total < 1000000000 * 1000, -- Check if the size is less than 1 TB (decimal)
FORMAT(total / 1000000000, "#0.0# GB"),
FORMAT(total / (1000000000 * 1000), "#0.0# TB")
)
)
)
```

This modified formula uses decimal-based divisions to calculate the size in GB and TB. It should align more closely with the representation you see in Azure, which is typically based on decimal gigabytes and terabytes.

@Alef_Ricardo_ sorry for the late reply. I used this logic but for MB value I am getting 00.0000KB as there is no condition for MB, so I modified the logic to:

 

Also I get TB also 00000.00000TB (EX: 13903384.45TB).

 

Can you help me with this? I am new to PowerBI.

 
Size of Ingestion_MB =
VAR total =
    SUM ( Query1[Size of Data]) + 0
RETURN
    IF (
        total < 1024,
        FORMAT ( total, "#0.0# B" ),
        IF (
            total < 1000000000,
            FORMAT ( total / 1024, "#0.00# KB" ),
            IF (
                total < 1000000000,
                FORMAT ( total / 10000, "#0.0# MB" ),
                IF (
                    total < 1000000000*1000,
                    FORMAT ( total / 1000000000, "#0.0# GB" ),                
                    FORMAT ( DIVIDE(total / 1000000000*1000,1000000), "#0.00# TB" )
                   )
                )
            )  
        )
Greg_Deckler
Community Champion
Community Champion

@rajiramk Change 1024 to 1000? GB Vs GiB: What’s The Difference? - MASV (massive.io)



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg for the help. sorry for the dealy reply.

Thanks for your reply. I tried to change , it did not help. I got the same (45.73 GB)

@rajiramk Oh, duh, you need to modify your POWER statements as well. GiB is based on powers of 2^10 = 1024. GB is based on powers of 10, 10^3 = 1000.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.