Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
When I started working in power bi, I simply made a link from excel to make the date table. Please find below the M Language which I took from advanced Editor
let
Source = Excel.Workbook(File.Contents("D:\Jamal Qamar DATA\Data\Geo\FPC Rating and Program wise revenue\rating cy17.xlsx"), null, true),
dDate_Sheet = Source{[Item="dDate",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(dDate_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Month", Int64.Type}, {"Month name", type text}, {"Year ", Int64.Type}, {"Month Year", type text}})
in
#"Changed Type"
Now I want to use Calendar option i.e. "dDate1 = CALENDAR(DATE(2015,1,1),MAX('Consolidated Data'[Day]))" inspite of the old method.
Please guide me to resolve the issue, In the old method I have to update the excel file time to time, whereas in the c aledar option this is very easy to use and not to update the table.
Regards,
Jamal Qamar
Solved! Go to Solution.
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 CreateDateTable
2. 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 Source
3. 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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |