Forum Discussion
vmcode
8 years agoFrequent Visitor
loop Statement to DAX
Hello dear, I am starting with dax and I must implement a report where you can see the amount and date of payment of sales to the credit, I have tried with the function dateadd but I need to iterate ...
- Anonymous8 years ago
vmcode,
You can use Power Query to get the above result. Add two new blank queries in your PBIX file, then paste the following codes to the Advanced Editor of the blank queries.let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY31DcyMLRQitUBcYwQHBNkGVM4JxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}) in #"Changed Type"let BufferedHolidays = Table.Buffer(Holidays), Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Xc1RCsAgDAPQq4jsU6rtTKlnEe9/De2EjfmXQB7pPTJiipwlS2Fb8VKQtbDS7U2YmoZnUvdkpIXsQGAS+Ey9GaFug89IOUxVMn2PGKTyR2MC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [store = _t, #"date of sale" = _t, amount = _t, #"number of payment" = _t, #"payment amount" = _t, #"payment date" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"store", Int64.Type}, {"date of sale", type date}, {"amount", Currency.Type}, {"number of payment", Int64.Type}, {"payment amount", Currency.Type}, {"payment date", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.AddMonths([payment date], [number of payment]-1)), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom1", each List.Dates([payment date],Duration.Days(Duration.From([Custom]-[payment date]))+1,#duration(1,0,0,0))), #"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom1", "Custom1"), #"Added Custom2" = Table.AddColumn(#"Expanded Custom1", "Month", each Date.Month([Custom1])), #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Ifholiday", each if List.Contains ( Table.Column(BufferedHolidays, "Date") , [Custom1]) then 0 else 1), #"Filtered Rows" = Table.SelectRows(#"Added Custom3", each ([Ifholiday] = 1)), #"Grouped Rows" = Table.Group(#"Filtered Rows", {"store", "date of sale", "amount", "number of payment", "payment amount", "payment date", "Month"}, {{"First date", each List.Min([Custom1]), type date}}), #"Renamed Columns" = Table.RenameColumns(#"Grouped Rows",{{"Month", "payment"}, {"First date", "new payment date"}}) in #"Renamed Columns"
Regards,
Lydia
Anonymous
8 years agoNot applicable
vmcode,
You can use Power Query to get the above result. Add two new blank queries in your PBIX file, then paste the following codes to the Advanced Editor of the blank queries.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY31DcyMLRQitUBcYwQHBNkGVM4JxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}})
in
#"Changed Type"
let
BufferedHolidays = Table.Buffer(Holidays),
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Xc1RCsAgDAPQq4jsU6rtTKlnEe9/De2EjfmXQB7pPTJiipwlS2Fb8VKQtbDS7U2YmoZnUvdkpIXsQGAS+Ey9GaFug89IOUxVMn2PGKTyR2MC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [store = _t, #"date of sale" = _t, amount = _t, #"number of payment" = _t, #"payment amount" = _t, #"payment date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"store", Int64.Type}, {"date of sale", type date}, {"amount", Currency.Type}, {"number of payment", Int64.Type}, {"payment amount", Currency.Type}, {"payment date", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.AddMonths([payment date], [number of payment]-1)),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom1", each List.Dates([payment date],Duration.Days(Duration.From([Custom]-[payment date]))+1,#duration(1,0,0,0))),
#"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom1", "Custom1"),
#"Added Custom2" = Table.AddColumn(#"Expanded Custom1", "Month", each Date.Month([Custom1])),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "Ifholiday", each if List.Contains ( Table.Column(BufferedHolidays, "Date") , [Custom1]) then 0 else 1),
#"Filtered Rows" = Table.SelectRows(#"Added Custom3", each ([Ifholiday] = 1)),
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"store", "date of sale", "amount", "number of payment", "payment amount", "payment date", "Month"}, {{"First date", each List.Min([Custom1]), type date}}),
#"Renamed Columns" = Table.RenameColumns(#"Grouped Rows",{{"Month", "payment"}, {"First date", "new payment date"}})
in
#"Renamed Columns"
Regards,
Lydia
- vmcode8 years agoFrequent Visitor
Thank you very much Lydia, I will do the tests during the night and I will tell you how it was
regards