Forum Discussion
milomilo2020
4 years agoFrequent Visitor
Convert DAX to M code
Hi, I have this DAX VAR _action_id =
CALCULATE ( SELECTEDVALUE ( 'base fact_ds_action'[action_id] ) )
VAR _insertion_date =
CALCULATE ( SELECTEDVALUE ( 'base fact_ds_action'[insert...
- Anonymous4 years ago
Hi milomilo2020 ,
Accoding to my understanding, you want to set Today for the row with the max date of each ID, the remains set the max date.
Please create a new blank query and paste the following M to the Advanced Editor dialog:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIyMDLSN9Q3VIrVAYoZIYsZQ8RMTDHVoeg1waLXAoteiDpLIECIGWERM8MiZmgAFrQAAlTBWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Count", each _, type table [ID=nullable number, Date=nullable date]}, {"Max", each List.Max([Date]), type nullable date}}), #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Date"}, {"Date"}), #"Added Custom" = Table.AddColumn(#"Expanded Count", "Custom", each if [Date]=[Max] then Date.From( DateTime.LocalNow()) else [Max]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Max"}) in #"Removed Columns"Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
4 years agoNot applicable
Hi milomilo2020 ,
Accoding to my understanding, you want to set Today for the row with the max date of each ID, the remains set the max date.
Please create a new blank query and paste the following M to the Advanced Editor dialog:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIyMDLSN9Q3VIrVAYoZIYsZQ8RMTDHVoeg1waLXAoteiDpLIECIGWERM8MiZmgAFrQAAlTBWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Count", each _, type table [ID=nullable number, Date=nullable date]}, {"Max", each List.Max([Date]), type nullable date}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Date"}, {"Date"}),
#"Added Custom" = Table.AddColumn(#"Expanded Count", "Custom", each if [Date]=[Max] then Date.From( DateTime.LocalNow()) else [Max]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Max"})
in
#"Removed Columns"
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.