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
Anonymous
Not applicable

combine multiple rows into single row with one column as unique ID

Hi All,

 

Actually im struggling in below case where date needs to be added to all rows of key value of first col that is MST_TO

i tied fill up and fill down doesnt work out for this use case

 

MST_TOTransport_Order__c07_Order Booking date11_Order Depart (CFS/CY) Origin date13_Shipment In Gate Origin POL date14_Shipment Manifest date17_Shipment POL Depart date18_Shipment POD Arrival date19_Shipment POD Discharge date25_Shipment Freight Available26_Shipment Out Gate Dest POD date31_Shipment Out Gate Dest Interim date36_Shipment Delivered05_Order Pickup date01_Order Create date02_Order Approved date03_Order Requested Ship date04_Order Planned date04_Order Dispatched date06_Order Docs Validated date06_Order Docs Received date07_Order Booking Cancelled date08_Order Arrival (CFS/CY) Origin date17_Transship Depart date17_Transship Arrival date
AAADDDDnullnull4/10/20205/14/20205/12/2020nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
AAADDDDnullnull4/10/20205/14/20205/12/2020nullnullnullnullnull6/18/2020nullnullnullnullnullnullnullnullnullnullnullnull
AAA nullnull4/10/20205/14/20205/12/2020nullnullnullnullnullnull4/9/2020null4/8/20204/10/20204/8/20204/8/20204/14/20204/9/2020null4/10/2020nullnull
BBBEEEnullnull5/4/20205/5/20205/7/20205/24/20205/25/2020null5/28/2020nullnullnullnullnullnullnullnullnullnullnullnull5/13/20205/9/2020
BBBFFFnullnull5/4/20205/5/20205/7/20205/24/20205/25/2020null5/28/2020nullnullnullnullnullnullnullnullnullnullnullnull5/13/20205/9/2020
CCCCGGGGnullnull3/28/20205/22/20204/5/20205/25/20205/26/2020null6/4/2020nullnullnullnullnullnullnullnullnullnullnullnull5/19/20205/11/2020
CCCC nullnullnullnullnullnullnullnullnullnullnull3/27/20203/17/20203/18/20203/25/20203/25/20203/19/20204/2/20203/27/2020nullnullnullnull
CCCCHHHHnullnull3/28/20205/22/20204/5/20205/25/20205/26/2020null6/4/2020nullnullnullnullnullnullnullnullnullnullnullnull5/19/20205/11/2020

 

desired output is 

 

 

 

MST_TO_NO__cTransport_Order__c07_Order Booking date11_Order Depart (CFS/CY) Origin date13_Shipment In Gate Origin POL date14_Shipment Manifest date17_Shipment POL Depart date18_Shipment POD Arrival date19_Shipment POD Discharge date25_Shipment Freight Available26_Shipment Out Gate Dest POD date31_Shipment Out Gate Dest Interim date36_Shipment Delivered05_Order Pickup date01_Order Create date02_Order Approved date03_Order Requested Ship date04_Order Planned date04_Order Dispatched date06_Order Docs Validated date06_Order Docs Received date07_Order Booking Cancelled date08_Order Arrival (CFS/CY) Origin date17_Transship Depart date17_Transship Arrival date
AAADDDDnullnull4/10/20205/14/20205/12/2020nullnullnullnullnull6/18/20204/9/2020null4/8/20204/10/20204/8/20204/8/20204/14/20204/9/2020null4/10/2020nullnull
AAADDDDnullnull4/10/20205/14/20205/12/2020nullnullnullnullnull6/18/20204/9/2020null4/8/20204/10/20204/8/20204/8/20204/14/20204/9/2020null4/10/2020nullnull
AAA nullnull4/10/20205/14/20205/12/2020nullnullnullnullnull6/18/20204/9/2020null4/8/20204/10/20204/8/20204/8/20204/14/20204/9/2020null4/10/2020nullnull
BBBEEEnullnull5/4/20205/5/20205/7/20205/24/20205/25/2020null5/28/2020nullnullnullnullnullnullnullnullnullnullnullnull5/13/20205/9/2020
BBBFFFnullnull5/4/20205/5/20205/7/20205/24/20205/25/2020null5/28/2020nullnullnullnullnullnullnullnullnullnullnullnull5/13/20205/9/2020
CCCCGGGGnullnull3/28/20205/22/20204/5/20205/25/20205/26/2020null6/4/2020nullnull3/27/20203/17/20203/18/20203/25/20203/25/20203/19/20204/2/20203/27/2020nullnull5/19/20205/11/2020
CCCC nullnull3/28/20205/22/20204/5/20205/25/20205/26/2020null6/4/2020nullnull3/27/20203/17/20203/18/20203/25/20203/25/20203/19/20204/2/20203/27/2020nullnull5/19/20205/11/2020
CCCCHHHHnullnull3/28/20205/22/20204/5/20205/25/20205/26/2020null6/4/2020nullnull3/27/20203/17/20203/18/20203/25/20203/25/20203/19/20204/2/20203/27/2020nullnull5/19/20205/11/2020
1 ACCEPTED SOLUTION

Ok, I think I understand now. To summarize the problem: 

 

ItemDate

AA

null
AAJuly 1, 2020
AAnull
BBnull

BB

null
BBnull
BBJuly 20, 2020

 

Desired result: 

 

ItemDate

AA

July 1, 2020
AAJuly 1, 2020
AAJuly 1, 2020
BBJuly 20, 2020

BB

July 20, 2020
BBJuly 20, 2020
BBJuly 20, 2020

 

SOLUTION:

My thinking is to group by item, find the MAX Date for each item, then merge back into table. You could possibly create a custom function to do this for you, but here is the M code for the sample data I created to do this. You will need to paste this into three blank queries in Advanced Editor and name the tables as below to see it in action. 

 

RawData

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUVKK1YEwDBW8SnMqdRSMDIwM4IKoDCdkhpEBugYnrOqUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Date", type date}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1)
in
#"Added Index"

 

FillDate

let
Source = RawData,
#"Grouped Rows" = Table.Group(Source, {"Item"}, {{"Date", each List.Max([Date]), type date}})
in
#"Grouped Rows"

 

Merge1

let
Source = Table.NestedJoin(RawData, {"Item"}, FillDate, {"Item"}, "FillDate", JoinKind.LeftOuter),
#"Expanded FillDate" = Table.ExpandTableColumn(Source, "FillDate", {"Date"}, {"Date.1"})
in
#"Expanded FillDate"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

11 REPLIES 11
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

You can use Calculated Columns or Measure to achieve your goal.

You can click this place and create calculated columns or new measure.

1.png

Use Column(06_Order Docs Received date) and Column (36_Shipment Delivered) as an example.

1.     Calculated columns:

C_06_Order Docs Received date =

CALCULATE(MAX('Table'[06_Order Docs Received date]),FILTER('Table','Table'[MST_TO]=EARLIER('Table'[MST_TO])))
C_36_Shipment Delivered =

CALCULATE(MAX('Table'[36_Shipment Delivered]),FILTER('Table','Table'[MST_TO]=EARLIER('Table'[MST_TO])))

Note:More info about Earlier Function Dax:https://docs.microsoft.com/en-us/dax/earlier-function-dax

2.     Measure:

M_06_Order Docs Received date = 
CALCULATE(MAX('Table'[06_Order Docs Received date]),FILTER(ALL('Table'),'Table'[MST_TO]=MAX('Table'[MST_TO])))
M_36_Shipment Delivered = 
CALCULATE(MAX('Table'[36_Shipment Delivered]),FILTER(ALL('Table'),'Table'[MST_TO]=MAX('Table'[MST_TO])))

Result:

2.png

Other columns use the same DAX.

You can download the pbix file form this link:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/tongzhou_qiuyunus_onmicrosoft_com/EVbEypVbkD5Nqgyan0RnOZoBjob1rFrCcNcK2j8revxvcg?e=l0dS86

 

Best Regards,

Rico Zhou

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

Ashish_Mathur
Super User
Super User

Hi,

Why does the Fill Down not work?  WHat problem do you face?  Please elaborate.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AllisonKennedy
Super User
Super User

Is it just columns 13, 14, 17 that you're concerned with? Please explain how you know which date to put and why fill up/down won't work,, as from the sample data you provided it looks like it could.
Otherwise this might be a conditional column?

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Hi Allison,

 

Thanks for checking my concerns

Fill up or fill down will wrongly fills up the data where it should not.

what i want is to have all the date values in all the rows corresponding to only first column only. not to other key.

in my example AAA as MST_TO rows should contain all the dates in all three rows in their rows only

 

 

sanjusanj21_0-1595214668407.png

 

In other words 
I can say that for key value of MST_TO number , if Second column Transport_order_cc is null, those values should be combined with both other rows of the key value MST_TO

sanjusanj21_0-1595216375239.png

 

 

 

Ok, I think I understand now. To summarize the problem: 

 

ItemDate

AA

null
AAJuly 1, 2020
AAnull
BBnull

BB

null
BBnull
BBJuly 20, 2020

 

Desired result: 

 

ItemDate

AA

July 1, 2020
AAJuly 1, 2020
AAJuly 1, 2020
BBJuly 20, 2020

BB

July 20, 2020
BBJuly 20, 2020
BBJuly 20, 2020

 

SOLUTION:

My thinking is to group by item, find the MAX Date for each item, then merge back into table. You could possibly create a custom function to do this for you, but here is the M code for the sample data I created to do this. You will need to paste this into three blank queries in Advanced Editor and name the tables as below to see it in action. 

 

RawData

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUVKK1YEwDBW8SnMqdRSMDIwM4IKoDCdkhpEBugYnrOqUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Date", type date}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1)
in
#"Added Index"

 

FillDate

let
Source = RawData,
#"Grouped Rows" = Table.Group(Source, {"Item"}, {{"Date", each List.Max([Date]), type date}})
in
#"Grouped Rows"

 

Merge1

let
Source = Table.NestedJoin(RawData, {"Item"}, FillDate, {"Item"}, "FillDate", JoinKind.LeftOuter),
#"Expanded FillDate" = Table.ExpandTableColumn(Source, "FillDate", {"Date"}, {"Date.1"})
in
#"Expanded FillDate"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy  

I really appreciate your help here. you made my day 🙂 

sanjusanj21_0-1595485497539.png



Will try it out on my actual data. 

@Anonymous glad to help. Hope it works well on your data!

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy 

How do I write my expand the table colum in Merg1 when I have more than 1 date columns from FillDate

 

FillDate

let
Source = RawData,
 #"Grouped Rows" = Table.Group(Source, {"MST_TO_NO__c"}, {{"01_Order Create date", each List.Max([01_Order Create date]), type date},{"02_Order Approved date", each List.Max([02_Order Approved date]), type date}})
in
#"Grouped Rows"

 

Merge1

let
Source = Table.NestedJoin(Derived_Event, {"MST_TO_NO__c"}, Group_Derived, {"MST_TO_NO__c"}, "Group_Derived", JoinKind.LeftOuter),
#"Expanded FillDate" = Table.ExpandTableColumn(Source, "Group_Derived", {"01_Order Create date"}, {"01_Order Create Date"},{"02_Order Approved date"},{"02_Order Approved Date"} )
in
#"Expanded FillDate"

Anonymous
Not applicable

@AllisonKennedy 

 

#"Expanded FillDate" = Table.ExpandTableColumn(Source, "Group_Derived", {"01_Order Create date","02_Order Approved date"}, {"01_Order Create Date","02_Order Approved Date"})

I used this in this way, hope its correct

You can also do this using the Settings cog next to the name of the step in the Applied Steps pane on the right hand side of the Power Query Editor, then you don't need to write custom M code. 🙂

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy 

how do we do same thing in custom function?

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.