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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AdamM
Frequent Visitor

Convert table of status changes by date to end-of-week status records

My need is to convert a table of status changes for Requests to a dataset that shows the status of each request as of the end of each week. To illustrate:

 

This is a table populated by a SharePoint workflow that logs Status changes for Requests.

 

Parent Request IDRequest Status Change IDDateStatus
114/4/2018New (Not Started)
124/20/2018In Process
235/1/2018New (Not Started)
345/7/2018New (Not Started)
355/10/2018In Process
265/17/2018In Process
475/17/2018New (Not Started)
185/21/2018Complete

 

 

My desired state, preferably using Get & Transform as opposed to DAX, is to arrive at the below table. One row per week for each Request ID, representing the current Status of the Request at the end of each week (Fridays), regardless of whether or not a Status change occurred in that week.

 

Parent Request IDWeek of YearStatus Date (Fridays)Status
1144/6/2018New (Not Started)
1154/13/2018New (Not Started)
1164/20/2018In Process
1174/27/2018In Process
1185/4/2018In Process
1195/11/2018In Process
1205/18/2018In Process
1215/25/2018Complete
2185/4/2018New (Not Started)
2195/11/2018New (Not Started)
2205/18/2018In Process
2215/25/2018In Process
3195/11/2018In Process
3205/18/2018In Process
3215/25/2018In Process
4205/18/2018New (Not Started)
4215/25/2018New (Not Started)

 

My apologies to the community for the vague title. My challenge is that I am not knowledgeable enough with advanced transformation steps to characterize the specific M functions needed here.

 

Thank you!

AdamM

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Just recognized that you wanted dates in the future as well. So I've extended the dates until the end of week in this code. For the Friday, you might need to change the number in step "IdentifyFridays", if your local settings start at a different date:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWMDE10gMrQAMv1SyxU0/PJLFIJLEotKUlM0lWJ1IAqNgNhE38gAiMAqPfMUAoryk1OLi8FKQNLGILNMdQ0M8ZkFUmQCVWhOSKEpRKGhgS4uO81AqvQNzXE4C2STOZoS3H60AKs0MoSpdM7PLchJLUlVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Parent Request ID" = _t, #"Request Status Change ID" = _t, Date = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent Request ID", Int64.Type}, {"Request Status Change ID", Int64.Type}, {"Date", type date}, {"Status", type text}}),
    PartitionOnParentRequestID = Table.Group(#"Changed Type", {"Parent Request ID"}, {{"All", each _, type table}}),
    AddListOfAllDates = Table.AddColumn(PartitionOnParentRequestID, "List", each { Number.From(List.Min([All][Date])) .. Number.From(Date.EndOfWeek(Date.From(DateTime.LocalNow()))) }),
    TransformToTableAndDates = Table.AddColumn(AddListOfAllDates, "Date", each Table.FromRows(List.Transform([List], (ListItem) => {Date.From(ListItem)}))),
    JoinWithSource = Table.AddColumn(TransformToTableAndDates, "Join", each Table.NestedJoin([Date], {"Column1"}, [All], {"Date"}, "StatusChanges",1)),
    Cleanup = Table.SelectColumns(JoinWithSource,{"Join"}),
    Expand = Table.ExpandTableColumn(Cleanup, "Join", {"Column1", "StatusChanges"}, {"Column1", "StatusChanges"}),
    ExpandSource = Table.ExpandTableColumn(Expand, "StatusChanges", {"Parent Request ID", "Request Status Change ID", "Date", "Status"}, {"Parent Request ID", "Request Status Change ID", "Date", "Status"}),
    FillDown = Table.FillDown(ExpandSource,{"Parent Request ID", "Request Status Change ID", "Date", "Status"}),
    IdentifyFridays = Table.AddColumn(FillDown, "Status Date (Fridays)", each if Date.DayOfWeek([Column1]) = 5 then [Column1] else null),
    FilterOnlyFridays = Table.SelectRows(IdentifyFridays, each ([#"Status Date (Fridays)"] <> null)),
    AddWeek = Table.AddColumn(FilterOnlyFridays, "Week of Year", each Date.WeekOfYear([#"Status Date (Fridays)"]))
in
    AddWeek

 

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

3 REPLIES 3
ImkeF
Community Champion
Community Champion

Hi Adam,

please paste this code into the advanced editor and follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWMDE10gMrQAMv1SyxU0/PJLFIJLEotKUlM0lWJ1IAqNgNhE38gAiMAqPfMUAoryk1OLi8FKQNLGILNMdQ0M8ZkFUmQCVWhOSKEpRKGhgS4uO81AqvQNzXE4C2STOZoS3H60AKs0MoSpdM7PLchJLUlVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Parent Request ID" = _t, #"Request Status Change ID" = _t, Date = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent Request ID", Int64.Type}, {"Request Status Change ID", Int64.Type}, {"Date", type date}, {"Status", type text}}),
    PartitionOnParentRequestID = Table.Group(#"Changed Type", {"Parent Request ID"}, {{"All", each _, type table}}),
    AddListOfAllDates = Table.AddColumn(PartitionOnParentRequestID, "List", each { Number.From(List.Min([All][Date])) .. Number.From(Date.From(DateTime.LocalNow())) }),
    TransformToTableAndDates = Table.AddColumn(AddListOfAllDates, "Date", each Table.FromRows(List.Transform([List], (ListItem) => {Date.From(ListItem)}))),
    JoinWithSource = Table.AddColumn(TransformToTableAndDates, "Join", each Table.NestedJoin([Date], {"Column1"}, [All], {"Date"}, "StatusChanges",1)),
    Cleanup = Table.SelectColumns(JoinWithSource,{"Join"}),
    Expand = Table.ExpandTableColumn(Cleanup, "Join", {"Column1", "StatusChanges"}, {"Column1", "StatusChanges"}),
    ExpandSource = Table.ExpandTableColumn(Expand, "StatusChanges", {"Parent Request ID", "Request Status Change ID", "Date", "Status"}, {"Parent Request ID", "Request Status Change ID", "Date", "Status"}),
    FillDown = Table.FillDown(ExpandSource,{"Parent Request ID", "Request Status Change ID", "Date", "Status"}),
    IdentifyFridays = Table.AddColumn(FillDown, "Status Date (Fridays)", each if Date.DayOfWeek([Column1]) = 6 then [Column1] else null),
    FilterOnlyFridays = Table.SelectRows(IdentifyFridays, each ([#"Status Date (Fridays)"] <> null)),
    AddWeek = Table.AddColumn(FilterOnlyFridays, "Week of Year", each Date.WeekOfYear([#"Status Date (Fridays)"]))
in
    AddWeek

 

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

ImkeF
Community Champion
Community Champion

Just recognized that you wanted dates in the future as well. So I've extended the dates until the end of week in this code. For the Friday, you might need to change the number in step "IdentifyFridays", if your local settings start at a different date:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWMDE10gMrQAMv1SyxU0/PJLFIJLEotKUlM0lWJ1IAqNgNhE38gAiMAqPfMUAoryk1OLi8FKQNLGILNMdQ0M8ZkFUmQCVWhOSKEpRKGhgS4uO81AqvQNzXE4C2STOZoS3H60AKs0MoSpdM7PLchJLUlVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Parent Request ID" = _t, #"Request Status Change ID" = _t, Date = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent Request ID", Int64.Type}, {"Request Status Change ID", Int64.Type}, {"Date", type date}, {"Status", type text}}),
    PartitionOnParentRequestID = Table.Group(#"Changed Type", {"Parent Request ID"}, {{"All", each _, type table}}),
    AddListOfAllDates = Table.AddColumn(PartitionOnParentRequestID, "List", each { Number.From(List.Min([All][Date])) .. Number.From(Date.EndOfWeek(Date.From(DateTime.LocalNow()))) }),
    TransformToTableAndDates = Table.AddColumn(AddListOfAllDates, "Date", each Table.FromRows(List.Transform([List], (ListItem) => {Date.From(ListItem)}))),
    JoinWithSource = Table.AddColumn(TransformToTableAndDates, "Join", each Table.NestedJoin([Date], {"Column1"}, [All], {"Date"}, "StatusChanges",1)),
    Cleanup = Table.SelectColumns(JoinWithSource,{"Join"}),
    Expand = Table.ExpandTableColumn(Cleanup, "Join", {"Column1", "StatusChanges"}, {"Column1", "StatusChanges"}),
    ExpandSource = Table.ExpandTableColumn(Expand, "StatusChanges", {"Parent Request ID", "Request Status Change ID", "Date", "Status"}, {"Parent Request ID", "Request Status Change ID", "Date", "Status"}),
    FillDown = Table.FillDown(ExpandSource,{"Parent Request ID", "Request Status Change ID", "Date", "Status"}),
    IdentifyFridays = Table.AddColumn(FillDown, "Status Date (Fridays)", each if Date.DayOfWeek([Column1]) = 5 then [Column1] else null),
    FilterOnlyFridays = Table.SelectRows(IdentifyFridays, each ([#"Status Date (Fridays)"] <> null)),
    AddWeek = Table.AddColumn(FilterOnlyFridays, "Week of Year", each Date.WeekOfYear([#"Status Date (Fridays)"]))
in
    AddWeek

 

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

AdamM
Frequent Visitor

Absolutely brilliant! Thank you ImkeF!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.