cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
SteveCampbell
Memorable Member
Memorable Member

Calculating time between steps

Hi,

 

I have been stuck on this now for a little and cannot seem to figure it out.

 

I have the following table:

 

item nostep astep bstep cstep d
item 111/20/2016 11/29/2016 
item 2 11/15/2016  
item 3    
item 4    
item 511/1/201611/22/201611/28/2016 
item 611/2/2016  11/29/2016
item 7    
item 8 11/29/2016  

 

 

What I'm trying to do is figure out how long the time difference is between steps. Not all steps are used for each item. My output could be something like this (but if there are better ways to output I don't mind):

 

item nostep astep bstep cstep d
item 1  9 
item 2    
item 3    
item 4 216 
item 5   27
item 6    
item 7    
item 8    

So for example, I could say on item 1 step C took 9 days since the last copmpleted step, which is enough detail. I'm struggling trying to find a solution, on how to arrange this in Power BI. Initially I've been trying along the lines of transpose and fill down, but this has not been working for me.

 

Thank you in advance for your help!

 



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Check this out:

 

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyixJzVUwVNJRMjLQNzTUNzIwNANyQHxLZH6sDlSpEUTW0BRVNUKBMVQATdgEu7ApkGdgiGSWkREyxwKrG0A8AyM0B6C4GK7UHLu1Ftj8CFIQCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"item no" = _t, #"step a" = _t, #"step b" = _t, #"step c" = _t, #"step d" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"item no"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "")),
    #"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows",{{"Value", type date}}),
    AddIndex = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(AddIndex, "Duration", each if [Index]>0 and [item no]=AddIndex[item no]{[Index]-1} then Number.From([Value])-Number.From(AddIndex[Value]{[Index]-1}) else "" ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Duration")
in
    #"Pivoted Column"

 

If you also need the empty item numbers, just let me know.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
ImkeF
Super User
Super User

Check this out:

 

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyixJzVUwVNJRMjLQNzTUNzIwNANyQHxLZH6sDlSpEUTW0BRVNUKBMVQATdgEu7ApkGdgiGSWkREyxwKrG0A8AyM0B6C4GK7UHLu1Ftj8CFIQCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"item no" = _t, #"step a" = _t, #"step b" = _t, #"step c" = _t, #"step d" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"item no"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "")),
    #"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows",{{"Value", type date}}),
    AddIndex = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(AddIndex, "Duration", each if [Index]>0 and [item no]=AddIndex[item no]{[Index]-1} then Number.From([Value])-Number.From(AddIndex[Value]{[Index]-1}) else "" ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index", "Value"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Duration")
in
    #"Pivoted Column"

 

If you also need the empty item numbers, just let me know.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

You are awesome - that works perfectly! I've just started learnign DAX / Power Query so walking through your steps really helps me unsderstand the logic.

Thanks a lot!



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors