Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi everyone,
I am having some issues with doing this as underneath:
I would like to groupBY RemoteID_shaped column and keep only rows =6 in MediaType column while substracting for each RemoteID_shaped number row in column TerminatedDateTimeUTC that has column MediaType =6 from MAX(TerminatedDateTimeUTC ) rows that has column MediaType =0.
any help will be much appreciated.
Thank you in advance.
Gmooh.
Solved! Go to Solution.
Hi @Anonymous
please paste this code into the advanced editor and follow the steps:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZU5bsMwEEWvEqg2YM7GrXQOkAMYLpyki5E08f1DUXDD4QjjdMKHnt6I+CTP5wUDF2EBSstheb3ebqfrx1d7BDoGPGLA8AJSuQxRrCLL5TDwb/ff95/796fiBWaRl+8yyy8hh9I+IPb8qcLIp4qkecPv5g1/rhRUxOz2Nx4tngOlDAWY9vyo/USaN/2o/e2XnH4MNUQVUfb6/bzpZ1GRTOY3/RO+bYnOQ6QgGQvb6x8rRdUfjpo3+9+nU5GXT2r9tsg7fyu77j9N/t/0o/Y/+uPj0yza+CwJAkXY7X8eolJhwpv9F55FXr7LPH6zv8A6Eq9/e9ngBbhkwshxr7849q8diaR5s784rl+P/P5x/61ResI/4SU/w4/9jY/92/kEEfbXb7w/03okKP4f95/Hn6bnT3DzRfVvjfzz95c9vH1/oIpgMr99f2i+RZfLHw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [RemoteID = _t, MediaType_name = _t, ConnectedDate = _t, TerminatedDate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"RemoteID", Int64.Type}, {"MediaType_name", type text}, {"ConnectedDate", type datetime}, {"TerminatedDate", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"RemoteID"}, {{"CallBacks", each Table.SelectRows(_, each [MediaType_name] = "CallBack")}, {"Outbounds", each Table.SelectRows(_, each [MediaType_name] = "Outbound")}}),
#"Expanded CallBacks" = Table.ExpandTableColumn(#"Grouped Rows", "CallBacks", {"MediaType_name", "ConnectedDate", "TerminatedDate"}, {"MediaType_name", "ConnectedDate", "TerminatedDate"}),
DiffTerminatedDate = Table.AddColumn(#"Expanded CallBacks", "Diff-TerminatedDate", each [TerminatedDate] - List.Max([Outbounds][TerminatedDate])),
#"Added Custom" = Table.AddColumn(DiffTerminatedDate, "Diff-ConnectedDate", each [ConnectedDate] - List.Min([Outbounds][ConnectedDate]))
in
#"Added Custom"
The reason for asking for sample data is that seeing the desired result helps understanding the explanations for the problem/requirements. And prevents silly code, as one can detect small errors or typos in the description.
This was missing from what you've sent so I have not been able to check if the negative amounts are really correct here.
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
Hi @Anonymous
that's possible, for sure. Please provide link to some sample data that provides the original data and the desired output.
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
Hi @ImkeF ,
I would like to GROUPBY RemoteID Column as well as add to columns:
Diff-TerminatedDate = TerminatedDate(for each row: CallBack)-MAX(TerminatedDate(of all Outbound rows for the same RemoteID)
Diff-ConnectedDate = ConnectedDate(for each row: CallBack)-Min(ConnectedDate( of all Outbound rows for the same RemoteID))
Here is my table Data sample synthesized with 2 added Columns:
RemoteID | MediaType_name | ConnectedDate | TerminatedDate | Diff-Terminated |
2046125564 | CallBack | 2020-02-13 12:23:01 | 2020-02-13 12:34:36 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2046125564 | Outbound | 2020-02-13 12:26:09 | 2020-02-13 12:32:36 | - |
2049545137 | CallBack | 2020-02-13 15:49:11 | 2020-02-13 16:55:25 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2049545137 | Outbound | 2020-02-13 15:51:34 | 2020-02-13 15:51:37 | - |
2049545137 | Outbound | 2020-02-13 16:55:13 | 2020-02-13 16:55:15 | - |
2508094515 | CallBack | 2020-02-13 17:15:09 | 2020-02-13 17:23:44 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2508094515 | Outbound | 2020-02-13 17:15:31 | 2020-02-13 17:23:26 | - |
2508094515 | CallBack | 2020-02-13 18:30:08 | 2020-02-13 18:44:36 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2508094515 | Outbound | 2020-02-13 18:32:25 | 2020-02-13 18:44:09 | - |
4037819143 | CallBack | 2020-02-13 18:20:51 | 2020-02-13 18:33:21 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4037819143 | Outbound | 2020-02-13 18:22:17 | 2020-02-13 18:30:01 | - |
4037819143 | CallBack | 2020-02-13 20:06:07 | 2020-02-13 20:38:01 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4037819143 | Outbound | 2020-02-13 20:06:19 | 2020-02-13 20:38:30 | - |
4037819143 | CallBack | 2020-02-13 20:45:12 | 2020-02-13 20:50:58 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4037819143 | Outbound | 2020-02-13 20:45:21 | 2020-02-13 20:49:49 | - |
4163058294 | CallBack | 2020-02-13 16:36:59 | 2020-02-13 17:46:31 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4163058294 | Outbound | 2020-02-13 16:43:00 | 2020-02-13 16:43:07 | - |
4163058294 | Outbound | 2020-02-13 17:06:36 | 2020-02-13 17:06:42 | - |
4163058294 | CallBack | 2020-02-13 17:25:49 | 2020-02-13 17:39:23 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4163058294 | Outbound | 2020-02-13 17:26:12 | 2020-02-13 17:30:21 | - |
4163058294 | Outbound | 2020-02-13 17:27:15 | 2020-02-13 17:27:22 | - |
4185710361 | CallBack | 2020-02-13 18:28:51 | 2020-02-13 19:17:59 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4185710361 | Outbound | 2020-02-13 18:54:52 | 2020-02-13 18:54:55 | - |
4185710361 | Outbound | 2020-02-13 19:17:37 | 2020-02-13 19:17:52 | - |
4185710361 | CallBack | 2020-02-13 20:14:57 | 2020-02-13 20:15:48 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
4185710361 | Outbound | 2020-02-13 20:15:42 | 2020-02-13 20:15:53 | - |
5149832646 | CallBack | 2020-02-13 16:23:34 | 2020-02-13 17:13:09 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
5149832646 | Outbound | 2020-02-13 16:24:16 | 2020-02-13 16:24:43 | - |
5149832646 | CallBack | 2020-02-13 16:45:31 | 2020-02-13 16:47:50 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
5149832646 | Outbound | 2020-02-13 16:45:57 | 2020-02-13 16:58:45 | - |
5149832646 | Outbound | 2020-02-13 16:46:54 | 2020-02-13 16:46:59 | - |
5149871616 | CallBack | 2020-02-13 16:29:57 | 2020-02-13 17:36:47 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
5149871616 | Outbound | 2020-02-13 16:55:03 | 2020-02-13 16:55:10 | - |
5149871616 | CallBack | 2020-02-13 17:36:00 | 2020-02-13 17:40:44 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
5149871616 | CallBack | 2020-02-13 19:14:54 | 2020-02-13 19:16:58 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
5149871616 | Outbound | 2020-02-13 19:16:19 | 2020-02-13 19:16:48 | - |
5149871616 | CallBack | 2020-02-13 20:02:13 | 2020-02-13 20:10:39 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
5149871616 | Outbound | 2020-02-13 20:02:16 | 2020-02-13 20:02:35 | - |
Here is the Output that I would like to have:
RemoteID | MediaType_name | ConnectedDate | TerminatedDate | Diff-Terminated |
2046125564 | CallBack | 2020-02-13 12:23:01 | 2020-02-13 12:34:36 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2049545137 | CallBack | 2020-02-13 15:49:11 | 2020-02-13 16:55:25 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2508094515 | CallBack | 2020-02-13 17:15:09 | 2020-02-13 17:23:44 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
2508094515 | CallBack | 2020-02-13 18:30:08 | 2020-02-13 18:44:36 | TerminatedDate(CallBack)-MAX(TerminatedDate(Outbound) |
Thank you in advance.
Hi @ImkeF ,
I would like to do a GROUP BY RemoteID Column and then add 2 new columns Diff-TerminatedDate and Diff-ConnectedDate as below:
Diff-TerminatedDate = TerminatedDate(for each row: CallBack)-MAX(TerminatedDate(of all Outbound rows for the same RemoteID)
Diff-ConnectedDate = ConnectedDate(for each row: CallBack)-Min(ConnectedDate( of all Outbound rows for the same RemoteID))
Here is my table Data sample synthesized:
RemoteID | MediaType_name | ConnectedDate | TerminatedDate |
2049545137 | CallBack | 2020-02-13 15:49:11 | 2020-02-13 16:55:25 |
2049545137 | Outbound | 2020-02-13 15:51:34 | 2020-02-13 15:51:37 |
2049545137 | Outbound | 2020-02-13 16:55:13 | 2020-02-13 16:55:15 |
2508094515 | CallBack | 2020-02-13 17:15:09 | 2020-02-13 17:23:44 |
2508094515 | Outbound | 2020-02-13 17:15:31 | 2020-02-13 17:23:26 |
2508094515 | CallBack | 2020-02-13 18:30:08 | 2020-02-13 18:44:36 |
2508094515 | Outbound | 2020-02-13 18:32:25 | 2020-02-13 18:44:09 |
4037819143 | CallBack | 2020-02-13 18:20:51 | 2020-02-13 18:33:21 |
4037819143 | Outbound | 2020-02-13 18:22:17 | 2020-02-13 18:30:01 |
4037819143 | CallBack | 2020-02-13 20:06:07 | 2020-02-13 20:38:01 |
4037819143 | Outbound | 2020-02-13 20:06:19 | 2020-02-13 20:38:30 |
4037819143 | CallBack | 2020-02-13 20:45:12 | 2020-02-13 20:50:58 |
4037819143 | Outbound | 2020-02-13 20:45:21 | 2020-02-13 20:49:49 |
4163058294 | CallBack | 2020-02-13 16:36:59 | 2020-02-13 17:46:31 |
4163058294 | Outbound | 2020-02-13 16:43:00 | 2020-02-13 16:43:07 |
4163058294 | Outbound | 2020-02-13 17:06:36 | 2020-02-13 17:06:42 |
4163058294 | CallBack | 2020-02-13 17:25:49 | 2020-02-13 17:39:23 |
4163058294 | Outbound | 2020-02-13 17:26:12 | 2020-02-13 17:30:21 |
4163058294 | Outbound | 2020-02-13 17:27:15 | 2020-02-13 17:27:22 |
4185710361 | CallBack | 2020-02-13 18:28:51 | 2020-02-13 19:17:59 |
4185710361 | Outbound | 2020-02-13 18:54:52 | 2020-02-13 18:54:55 |
4185710361 | Outbound | 2020-02-13 19:17:37 | 2020-02-13 19:17:52 |
4185710361 | CallBack | 2020-02-13 20:14:57 | 2020-02-13 20:15:48 |
4185710361 | Outbound | 2020-02-13 20:15:42 | 2020-02-13 20:15:53 |
5149832646 | CallBack | 2020-02-13 16:23:34 | 2020-02-13 17:13:09 |
5149832646 | Outbound | 2020-02-13 16:24:16 | 2020-02-13 16:24:43 |
5149832646 | CallBack | 2020-02-13 16:45:31 | 2020-02-13 16:47:50 |
5149832646 | Outbound | 2020-02-13 16:45:57 | 2020-02-13 16:58:45 |
5149832646 | Outbound | 2020-02-13 16:46:54 | 2020-02-13 16:46:59 |
5149871616 | CallBack | 2020-02-13 16:29:57 | 2020-02-13 17:36:47 |
5149871616 | Outbound | 2020-02-13 16:55:03 | 2020-02-13 16:55:10 |
5149871616 | CallBack | 2020-02-13 17:36:00 | 2020-02-13 17:40:44 |
5149871616 | CallBack | 2020-02-13 19:14:54 | 2020-02-13 19:16:58 |
5149871616 | Outbound | 2020-02-13 19:16:19 | 2020-02-13 19:16:48 |
5149871616 | CallBack | 2020-02-13 20:02:13 | 2020-02-13 20:10:39 |
5149871616 | Outbound | 2020-02-13 20:02:16 | 2020-02-13 20:02:35 |
The output will be as below:
RemoteID | MediaType_name | ConnectedDate | TerminatedDate | Diff-TerminatedDate | Diff-ConnectedDate |
2049545137 | CallBack | 2020-02-13 15:49:11 | 2020-02-13 16:55:25 | ||
2508094515 | CallBack | 2020-02-13 17:15:09 | 2020-02-13 17:23:44 | ||
2508094515 | CallBack | 2020-02-13 18:30:08 | 2020-02-13 18:44:36 | ||
4037819143 | CallBack | 2020-02-13 18:20:51 | 2020-02-13 18:33:21 | ||
4037819143 | CallBack | 2020-02-13 20:06:07 | 2020-02-13 20:38:01 | ||
4037819143 | CallBack | 2020-02-13 20:45:12 | 2020-02-13 20:50:58 | ||
4163058294 | CallBack | 2020-02-13 16:36:59 | 2020-02-13 17:46:31 | ||
4163058294 | CallBack | 2020-02-13 17:25:49 | 2020-02-13 17:39:23 | ||
4185710361 | CallBack | 2020-02-13 18:28:51 | 2020-02-13 19:17:59 | ||
4185710361 | CallBack | 2020-02-13 20:14:57 | 2020-02-13 20:15:48 | ||
5149832646 | CallBack | 2020-02-13 16:23:34 | 2020-02-13 17:13:09 | ||
5149832646 | CallBack | 2020-02-13 16:45:31 | 2020-02-13 16:47:50 | ||
5149871616 | CallBack | 2020-02-13 16:29:57 | 2020-02-13 17:36:47 | ||
5149871616 | CallBack | 2020-02-13 17:36:00 | 2020-02-13 17:40:44 | ||
5149871616 | CallBack | 2020-02-13 19:14:54 | 2020-02-13 19:16:58 | ||
5149871616 | CallBack | 2020-02-13 20:02:13 | 2020-02-13 20:10:39 |
Thank you in advance.
Hi @Anonymous
please paste this code into the advanced editor and follow the steps:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZU5bsMwEEWvEqg2YM7GrXQOkAMYLpyki5E08f1DUXDD4QjjdMKHnt6I+CTP5wUDF2EBSstheb3ebqfrx1d7BDoGPGLA8AJSuQxRrCLL5TDwb/ff95/796fiBWaRl+8yyy8hh9I+IPb8qcLIp4qkecPv5g1/rhRUxOz2Nx4tngOlDAWY9vyo/USaN/2o/e2XnH4MNUQVUfb6/bzpZ1GRTOY3/RO+bYnOQ6QgGQvb6x8rRdUfjpo3+9+nU5GXT2r9tsg7fyu77j9N/t/0o/Y/+uPj0yza+CwJAkXY7X8eolJhwpv9F55FXr7LPH6zv8A6Eq9/e9ngBbhkwshxr7849q8diaR5s784rl+P/P5x/61ResI/4SU/w4/9jY/92/kEEfbXb7w/03okKP4f95/Hn6bnT3DzRfVvjfzz95c9vH1/oIpgMr99f2i+RZfLHw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [RemoteID = _t, MediaType_name = _t, ConnectedDate = _t, TerminatedDate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"RemoteID", Int64.Type}, {"MediaType_name", type text}, {"ConnectedDate", type datetime}, {"TerminatedDate", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"RemoteID"}, {{"CallBacks", each Table.SelectRows(_, each [MediaType_name] = "CallBack")}, {"Outbounds", each Table.SelectRows(_, each [MediaType_name] = "Outbound")}}),
#"Expanded CallBacks" = Table.ExpandTableColumn(#"Grouped Rows", "CallBacks", {"MediaType_name", "ConnectedDate", "TerminatedDate"}, {"MediaType_name", "ConnectedDate", "TerminatedDate"}),
DiffTerminatedDate = Table.AddColumn(#"Expanded CallBacks", "Diff-TerminatedDate", each [TerminatedDate] - List.Max([Outbounds][TerminatedDate])),
#"Added Custom" = Table.AddColumn(DiffTerminatedDate, "Diff-ConnectedDate", each [ConnectedDate] - List.Min([Outbounds][ConnectedDate]))
in
#"Added Custom"
The reason for asking for sample data is that seeing the desired result helps understanding the explanations for the problem/requirements. And prevents silly code, as one can detect small errors or typos in the description.
This was missing from what you've sent so I have not been able to check if the negative amounts are really correct here.
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
Hi @ImkeF ,
Thank you for your reply, please forgive my bad explanantion :).
I will check that and try to implement it to my code.I will let you know ASAP.
Thanks.
Hi everyone,
Could anyone help on this please ?
Much appreciated.
Thanks.
Hi @Anonymous
Sorry, misses your answer.
Will check it out in a sec.
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
Hi @Anonymous
could you please check the data for the desired output?
I cannot see any calculation there. So its just a selection of the first 4 items with "MediaType" = "CallBack"
Please make sure that the desired input and output match each other completely.
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
Thanks ImkeF, much appreciated.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.