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
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
Waoooooo Dale,
Excellent task you did for me. Thanks a lot. Now my issue resolved. This is a relax time for me.
Best Regards,
Jamal Qamar
That's great! You are welcome, Jamal. Could you please mark my answer as solution?
Best Regards,
Dale
Yes Dale, I did it. Again thanks for your cooperation.
Regards,
Jamal Qamar
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
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
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
Hi Jamal,
Another concern is if you still want the dates to be dynamic. As we can see from the formula in your first post.
Best Regards,
Dale
Yes Sure,
The only purpose is to make it dynamic which should connect with my sales date table.
Proud to be a Super User!
Paul on Linkedin.
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 |
---|---|
114 | |
99 | |
83 | |
70 | |
60 |
User | Count |
---|---|
150 | |
115 | |
104 | |
89 | |
65 |