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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User

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


@ 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!:
The Definitive Guide to Power Query (M)

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.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.