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
Thewill4u
New Member

Find average time between statuses

Hello all,

 

How would one go about finding the average time between states using the data set I have below? For example, the average time something is in the RUNNING state before it changes to the QUAL state or the average of the UALARM time before it's back to RUNNING.

 

 

Thewill4u_0-1652814901578.png

 

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Thewill4u ,

If you want to calculate the average duration of each same status like below, here's my solution.

vkalyjmsft_0-1653375219614.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc/RCoMwDAXQX5E8O0zShtq8CZMhuMIEn6T//xsrlhacutdwuDd322BZQ5jCC1pgZO6kI9OQVfHpgg/0ih5ie+1ExVVGO1uHeVjev8pmhYrmX5ipDG8YN9Qr5lIitbK7T2o9IlcQUgk7o7Syz4jLyuk5j3eovnXamBlW5iDGLw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Status = _t, #"Change Date" = _t, Duration = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status", type text}, {"Change Date", type datetime}, {"Duration", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","-",".",Replacer.ReplaceText,{"Duration"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Duration", type duration}}),
    #"Reversed Rows" = Table.ReverseRows(#"Changed Type1"),
    #"Added Index" = Table.AddIndexColumn(#"Reversed Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Min", each if[Index]=0 then 0 else List.Max(Table.SelectRows(#"Added Index",(x)=> x[Index]<[Index]and x[Status]<>[Status])[Index])+1),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Max", each if List.Min(Table.SelectRows(#"Added Index",(x)=> x[Index]>[Index]and x[Status]<>[Status])[Index])-1=null then List.Max(#"Added Custom"[Index]) else List.Min(Table.SelectRows(#"Added Index",(x)=> x[Index]>[Index]and x[Status]<>[Status])[Index])-1),
    #"Added Custom3" = Table.AddColumn(#"Added Custom1", "Custom", each if[Index]>=[Min]and [Index]<=[Max]then 1 else 0),
    #"Grouped Rows" = Table.Group(#"Added Custom3", {"Min", "Max"}, {{"Table", each _, type table [Status=nullable text, Change Date=nullable datetime, Duration=nullable duration, Index=number, Min=number, Max=number, Custom=number]}}),
    #"Added Custom4" = Table.AddColumn(#"Grouped Rows", "Average", each List.Average([Table][Duration])),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Custom4", "Table", {"Status", "Change Date", "Duration"}, {"Table.Status", "Table.Change Date", "Table.Duration"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Count",{"Max", "Min"}),
    #"Reversed Rows1" = Table.ReverseRows(#"Removed Columns")
in
    #"Reversed Rows1"

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Thewill4u ,

If you want to calculate the average duration of each same status like below, here's my solution.

vkalyjmsft_0-1653375219614.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc/RCoMwDAXQX5E8O0zShtq8CZMhuMIEn6T//xsrlhacutdwuDd322BZQ5jCC1pgZO6kI9OQVfHpgg/0ih5ie+1ExVVGO1uHeVjev8pmhYrmX5ipDG8YN9Qr5lIitbK7T2o9IlcQUgk7o7Syz4jLyuk5j3eovnXamBlW5iDGLw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Status = _t, #"Change Date" = _t, Duration = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status", type text}, {"Change Date", type datetime}, {"Duration", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","-",".",Replacer.ReplaceText,{"Duration"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Duration", type duration}}),
    #"Reversed Rows" = Table.ReverseRows(#"Changed Type1"),
    #"Added Index" = Table.AddIndexColumn(#"Reversed Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Min", each if[Index]=0 then 0 else List.Max(Table.SelectRows(#"Added Index",(x)=> x[Index]<[Index]and x[Status]<>[Status])[Index])+1),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Max", each if List.Min(Table.SelectRows(#"Added Index",(x)=> x[Index]>[Index]and x[Status]<>[Status])[Index])-1=null then List.Max(#"Added Custom"[Index]) else List.Min(Table.SelectRows(#"Added Index",(x)=> x[Index]>[Index]and x[Status]<>[Status])[Index])-1),
    #"Added Custom3" = Table.AddColumn(#"Added Custom1", "Custom", each if[Index]>=[Min]and [Index]<=[Max]then 1 else 0),
    #"Grouped Rows" = Table.Group(#"Added Custom3", {"Min", "Max"}, {{"Table", each _, type table [Status=nullable text, Change Date=nullable datetime, Duration=nullable duration, Index=number, Min=number, Max=number, Custom=number]}}),
    #"Added Custom4" = Table.AddColumn(#"Grouped Rows", "Average", each List.Average([Table][Duration])),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Custom4", "Table", {"Status", "Change Date", "Duration"}, {"Table.Status", "Table.Change Date", "Table.Duration"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Count",{"Max", "Min"}),
    #"Reversed Rows1" = Table.ReverseRows(#"Removed Columns")
in
    #"Reversed Rows1"

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Vijay_A_Verma
Super User
Super User

Could you please also post the result so that experts here can post the solution?

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.

Top Solution Authors
Top Kudoed Authors