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
vat2do
Helper II
Helper II

How to show time duration using power bi chart with format as "text"

Hi there,

 

I have a column in text format as below:

 

Duration
9m 44s
10m 8s
36s
2m

 

I want to show the values in power bi chart, can anyone support. thanks in advance

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi @VahidDM 

 

vchenwuzmsft_0-1664173047140.png

Maybe you can try some m code like the following:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WssxVMDEpVorViVYyNMhVsIAwjc0gtFGuUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Duration = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.Contains([Duration],"m") then [Duration] else " "&[Duration]),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Custom.1", "Custom.2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Duration", type text}, {"Custom.1", type text}, {"Custom.2", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","m","",Replacer.ReplaceText,{"Custom.1"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","s","",Replacer.ReplaceText,{"Custom.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"Custom.1", Int64.Type}, {"Custom.2", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Custom.1", "m"}, {"Custom.2", "s"}}),
    #"Replaced Value2" = Table.ReplaceValue(#"Renamed Columns",null,0,Replacer.ReplaceValue,{"m", "s"}),
    #"Added Custom1" = Table.AddColumn(#"Replaced Value2", "value", each [m]*60+[s])
in
    #"Added Custom1"

 

Best Regards

Community Support Team _ chenwu zhu

 

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

VahidDM
Super User
Super User

HI @vat2do 

 

Can you post sample of the expected output?

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

 

Hi,

 

Thanks for your response,

I need to show the same values in chart for example each bar showing value as "9m 44s" or "10m 8s" etc

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.