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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mcflurry
Helper I
Helper I

Column with both Mib and Gib values, convert Mib to Gib

I have a column like this:

mcflurry_0-1646902058386.png

 

I would lik to convert MiB to GiB, so that everything is in GiB, i have no idea of how to achieve it nor how to search for this... all the info i've found this far is converting from Mib to Gib, but nothing about MiB AND GiB to one of both.

Any help would be much appreciated.

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @mcflurry ,

 

For this need, I think there is a simpler way: use the replace value function in the power query, refer to the following test results:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIzMFVwz3RSitWJVjLUszSHc4AyIE4SRMbMVM/SUMEXptDcUs/cBMKNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","M","G",Replacer.ReplaceText,{"Column1"})
in
    #"Replaced Value"

vhenrykmstf_0-1647331435708.png

vhenrykmstf_1-1647331466964.png


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

15 REPLIES 15
v-henryk-mstf
Community Support
Community Support

Hi @mcflurry ,

 

For this need, I think there is a simpler way: use the replace value function in the power query, refer to the following test results:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIzMFVwz3RSitWJVjLUszSHc4AyIE4SRMbMVM/SUMEXptDcUs/cBMKNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","M","G",Replacer.ReplaceText,{"Column1"})
in
    #"Replaced Value"

vhenrykmstf_0-1647331435708.png

vhenrykmstf_1-1647331466964.png


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mcflurry
Helper I
Helper I

Ok, both codes are working... didn't worked because i had 2 blank rows in the column.

The problem now is that both codes display the same value in every row, like this:

 

mcflurry_1-1646998399329.png

 

Adescrit
Impactful Individual
Impactful Individual

Did you create a measure or a column?

My code was for a column.

 

 


Did I answer your question? Mark my post as a solution!
My LinkedIn
Adescrit
Impactful Individual
Impactful Individual

I'm assuming here that your column is a text field e.g. "2.05 GiB" is stored as a text value.

GiB = 
VAR __Datatype = RIGHT( 'Table'[Reclaimable Space] , 3) 
VAR __Length = LEN( 'Table'[Reclaimable Space] )
VAR __Value = VALUE( LEFT( 'Table'[Reclaimable Space] , __Length - 4) ) -- Return numeric value

RETURN
    SWITCH( TRUE(),
        __Datatype = "MiB", (__Value / 1024), -- Convert MiB value to GiB
        __Datatype = "GiB", __Value           -- Return GiB value
    )

Did I answer your question? Mark my post as a solution!
My LinkedIn

Yep, it's text value.

 

I've tried your code and it returns this error:

An argument of function 'LEFT' has the wrong data type or has an invalid value.

Adescrit
Impactful Individual
Impactful Individual

Open Power Query (Transform Data) and check that the column Reclaimable space is stored as text, i.e. the data type should be displayed as "ABC" and not "ABC 123". The latter would imply the column has not been explicitly formatted as text. One you have changed type to Text (if needed) close and apply. Then try the formula I previously shared. It works for me.


Did I answer your question? Mark my post as a solution!
My LinkedIn

It's stored as Text.

mcflurry_0-1646997131101.png

But it isn't working yet.

 

An argument of function 'LEFT' has the wrong data type or has an invalid value.

Adescrit
Impactful Individual
Impactful Individual

Or try this (once you're sure the column is stored as text)

 

GiB = 
VAR __Datatype = RIGHT( 'Table'[Reclaimable Space] , 3) 
VAR __Length = LEN( 'Table'[Reclaimable Space] )
VAR __Value = VALUE( LEFT( 'Table'[Reclaimable Space] , __Length - 4) ) -- Return numeric value

RETURN
    SWITCH( TRUE(),
        __Datatype = "MiB", (__Value / 1024), -- Convert MiB value to GiB
        __Datatype = "GiB", __Value,           -- Return GiB value
        0
    )

Did I answer your question? Mark my post as a solution!
My LinkedIn

Yep, working, but it displays the same result for every cell:

 

mcflurry_1-1646999529209.png

 

 

Same result:

 

An argument of function 'LEFT' has the wrong data type or has an invalid value.

Adescrit
Impactful Individual
Impactful Individual

How about this (wrapped in an IFERROR)

 

GiB = 
VAR __Datatype = RIGHT( 'Table'[Reclaimable Space] , 3) 
VAR __Length = LEN( 'Table'[Reclaimable Space] )
VAR __Value = VALUE( LEFT( 'Table'[Reclaimable Space] , __Length - 4) ) -- Return numeric value

RETURN
    IFERROR( 
      SWITCH( TRUE(),
        __Datatype = "MiB", (__Value / 1024), -- Convert MiB value to GiB
        __Datatype = "GiB", __Value,           -- Return GiB value
        0
      ) , 0)

 


Did I answer your question? Mark my post as a solution!
My LinkedIn

@mcflurry , Try this;

Column =
VAR char_ = RIGHT(YourTable[Reclaimable Space],3)
VAR num_ = ABS(LEFT(YourTable[Reclaimable Space],LEN(YourTable[Reclaimable Space])-LEN(char_)))

RETURN IF(char_="GiB", DIVIDE(num_,1024),num_)
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Hi, not working.

 

Cannot convert value '' of type Text to type Number.

@mcflurry  Nope syntax is not incorrect. I tested and then shared the code. As per the below screen shot I am not getting any kind of error.

 

Capture.JPG

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Yep, working, but it displays the same result for every cell:

 

mcflurry_0-1646999439754.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.