Hello All,
I am relatively new to M Code and wonder if anyone can help me with syntax to dynamically change loaded date values.
The situation is i am looking at the Dashboarding and Data Visualisations course - Retail Sites moule with the "Retail Sites - Data Model.xlsx specifically the Sales Table “Purchase Date” but this could apply to any dataset with a Date value.
The dataset Purchase has values from 1/7/2016 - 31/12/2019 and we are now in April 2020.
As the dashboard uses dynamic date ranges calculated from TODAY - X days my idea was on load of the Dataset to Add 3 months or even 115 days to each value of the Purchase Date to have relevant sample date in the Dynamic reporting ranges of the Dashboard.
I just have not found the valid syntax to integrate Date.AddDays or AddMonths into the M CODE so if anyone can help on this it would be appreciated.
here is an example of the incorrect syntax
Sales_Data_Table = Source{[Item="Sales_Data",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Sales_Data_Table,{{"Order ID", type text}, {"Product ID", type text}, {"Location ID", type text}, {"Sales Person ID", type text}, {"Customer ID", type text}, {"Purchase Date", type date}, {"Quantity", Int64.Type}}),
#"AddDaysToPurchaseDate" = Table.TransformColumnTypes(#"Changed Type",{"Purchase Date", Date.AddDays("Purchase Date",115 )})
in
#“AddDaysToPurchaseDate”
The Retail Sites example uses measures like
Revenue within Time Frame =
CALCULATE( [Total Revenue] ,
FILTER( Dates,
Dates[Date] <= TODAY() && Dates[Date] >= Today() - [Time Frame Selected] )
)
So the further the current date moves from the Max( [Purchase Date] ) the less data will found by the dynamic reporting ranges.
Another idea i had for working with this data set was not to change the loaded data set and Purchase dates but to trick the Current date in the Measure as follows
1. Create a Query Parameter to determine the Maximum value of the Purchase date
which is currently 31/12/2019 perhaps add some days to it .
MaxPurchaseDate = Date.AddDays(List.Max(#"Changed Type"[Purchase Date]),10)
- Replace the TODAY() function in the Measure with a reference to a Query value holding this date derived from the dataset
Thanking you in advance
Russell