Forum Discussion
QZ
Helper I
4 years agoHow to create new records base on row data(date format)?
In Power BI desktop, get original excel data as bellow:
| Employee ID | Start Date of Biztrip | End Date of Biztrip |
| A01 | Jul 6, 2022 12:00:00 AM | Jul 8, 2022 12:00:00 AM |
| A02 | Jul 4, 2022 12:00:00 AM | Jul 6, 2022 12:00:00 AM |
Maybe after processed(DAX or M?), can I get bellow format data base on original excel file? If yes, how to do it?
| Employee ID | Date of Biztrip | Day of leave |
| A01 | 2022/7/6 | 1 |
| A01 | 2022/7/7 | 1 |
| A01 | 2022/7/8 | 1 |
| A02 | 2022/7/4 | 1 |
| A02 | 2022/7/5 | 1 |
| A02 | 2022/7/6 | 1 |
If you've had any luck with this issue and can shed some light, it would by much appreciated.
Hi,
This M code works
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQwVNJRMjDTNTDXNTIwMgJxLOCcWB2QCrCgCbIKhPLYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Start Date of Biztrip" = _t, #"End Date of Biztrip" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", type text}, {"Start Date of Biztrip", type date}, {"End Date of Biztrip", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each {Number.From([Start Date of Biztrip])..Number.From([End Date of Biztrip])}), #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Start Date of Biztrip", "End Date of Biztrip"}) in #"Removed Columns"Hope this helps.
9 Replies
- Ashish_Mathur
Super User
Hi,
This M code works
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQwVNJRMjDTNTDXNTIwMgJxLOCcWB2QCrCgCbIKhPLYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Start Date of Biztrip" = _t, #"End Date of Biztrip" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", type text}, {"Start Date of Biztrip", type date}, {"End Date of Biztrip", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each {Number.From([Start Date of Biztrip])..Number.From([End Date of Biztrip])}), #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Start Date of Biztrip", "End Date of Biztrip"}) in #"Removed Columns"Hope this helps.
- QZ
Helper I
Thank you for your rapid response!
I'm new in M language, suppose the orininal table name is A, after processed base on table A, I want to create a new table B, may I know how to do it in M language?
- Ashish_Mathur
Super User
You are welcome. Share the download link of your PBI file and i will share the M code in that file.
- QZ
Helper I
Put the pbix file to OneDrive, I'm not sure you can access or not, anyway, pls try it. Thanks.
Click here