Forum Discussion
Date Table source changes
- 8 years ago
Hi Jamal,
I found a way to replace the code directly. You can check it out in this file.
1. Create a function. (I found the M code here).
let CreateDateTable = (StartDate as date, EndDate as date, optional Culture as nullable text) as table => let DayCount = Duration.Days(Duration.From(EndDate - StartDate)), Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)), TableFromList = Table.FromList(Source, Splitter.SplitByNothing()), ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}), RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}), InsertMonth = Table.AddColumn(RenamedColumns, "Month", each Date.Month([Date])), InsertMonthName = Table.AddColumn(InsertMonth, "Month Name", each Date.ToText([Date], "MMMM", Culture), type text), InsertYear = Table.AddColumn(InsertMonthName, "Year", each Date.Year([Date])), InsertQuarter = Table.AddColumn(InsertYear, "Month Year", each Date.QuarterOfYear([Date])) in InsertQuarter in CreateDateTable2. Replace the M code of the query dDate with the following one.
let maxDate = List.Max(#"Consolidated Data"[Column1]), //Max date of another query, which makes this query dynamic. Source = Query(#date(2018, 2, 1), maxDate, null) in Source3. Apply the changes.
Note: If the data you shared is a sample, you need to adjust the code to satisfy your data. The structure and the column names should be the same.
Now you can get rid of the workbook file.
Best Regards,
Dale
Hi Jamal,
What's the issue? You know the DAX function Calendar and you can create a date table.
Best Regards,
Dale
Hi Dale,
Thanks for your response.
Actually I want to replace the Date field of dDate table with the one which you suggested. Then I will connect the date from my sales table.
As mentioned earlier, the date field is linked with Excel file and all the reports are based on this Date field. Every month I have to add month in excel table.
I want to use the Calendar function inspite of linkage with Excel.
Please download the pbix file from the link given below.
https://drive.google.com/open?id=1WR_ghdl-wEWS-iQZzY9zTUeOuo32gXq7
I shall be thankful to you that I you could use the Calendar function in Date field.
Regards,
Jamal Qamar
- v-jiascu-msft8 years agoMicrosoft Employee
Hi Jamal,
I'm afraid you have to replace the whole dDate table with a new date table. I hope I didn't miss anything. What could be the problem?
Best Regards,
Dale
- jamalq1238 years agoAdvocate III
Hi Dale,
Is there any way to just replace Date field so that it could not hit the report. I tried to chnage in the advanced editor, but could not do so.
If you could just replace the date filed with the new date field, it will be highly helpful for me.
Regards,
Jamal Qamar
- PaulDBrown8 years agoCommunity ChampionSurely if the new created date table has exactly the same structure, name and relationships the model will be “unaware” of the change?
The problem I see is how to have two tables with the same name. Which basically means you will have to create the new Table using power query and M code, and the substitue the M code in the current date table with the new code created in the new table. I think.
