Function for Digital Unit Conversion in Power BI (KB, MB, GB...)
While displaying reports it is very common to convert the units. So today I will be displaying the function that can be used in order to convert the Units
Space =
VAR total =
SUM ( Table1[Used Space] ) + 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" ),
FORMAT ( total / POWER ( 2, 30 ), "#0.0# GB" )
)
)
)
So if you look into the function the core logic is
B --> KB then divide by POWER ( 2, 10 )
B --> MB then divide by POWER ( 2, 20 )
B --> GB then divide by POWER ( 2, 30 )
And...
KB --> B then multiply by POWER ( 2, 10 )
MB --> B then multiply by POWER ( 2, 20 )
GB --> B then multiply by POWER ( 2, 30 )
Use the above method in order to convert the units and display them in a friendly text
Happy Coding..!!
This is great! can you keep going to PB?
ReplyDeleteSure, Thanks
Delete