Home – Le CFO masqué › Forums › Power Query › Table de Dates
- This topic has 3 replies, 3 voices, and was last updated 3 years, 3 months ago by
magali.careddu.
-
AuthorPosts
-
12 January 2022 at 8 h 15 min #100566
magali.careddu
ParticipantBonjour,
Je voudrai savoir s’il serait possible de disposer du code M correspondant à la création d’une Table de dates, ce qui me permettrait de l’utiliser dans la plupart de mes requêtes.
Etant entendu qu’il existe plusieurs possibilités, je suis preneuse de l’écriture du code le plus simple, à savoir celui correspondant au calendrier grégorien (avec les champs Année/Trimestre/Mois/Numéro Semaine/Jour semaine), pas celui d’un calendrier fiscal.En vous remerciant par avance de la réponse apportée.
Magali
12 January 2022 at 9 h 16 min #100567JBruneau
ParticipantBonjour Magali
Ceci n’est pas de mon crû mais fonctionne. A copier dans une requête vide.
———–
let
CreateDateTable = () as table =>
let
StartDate =#date(2021,1,1),
EndDate = #date(2022,12,31),
Culture = “dd/mm/yyyy”,
DayCount = Duration.Days(Duration.From(EndDate-StartDate))+1,
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”, “JOUR”}}),
InsertYear = Table.AddColumn(RenamedColumns, “ANNEE”, each Date.Year([JOUR]), Int64.Type),
InsertQuarter = Table.AddColumn(InsertYear, “TRIMESTRE”, each Date.QuarterOfYear([JOUR]), Int64.Type),
InsertMonth = Table.AddColumn(InsertQuarter, “MOIS”, each Date.Month([JOUR]), Int64.Type),
InsertDay = Table.AddColumn(InsertMonth, “JOUR_MOIS”, each Date.Day([JOUR]), Int64.Type),
InsertDayInt = Table.AddColumn(InsertDay, “JOUR_INT”, each [ANNEE] * 10000 + [MOIS] * 100 + [JOUR_MOIS], Int64.Type),
InsertMonthName = Table.AddColumn(InsertDayInt, “MOIS_LIBELLE”, each Date.ToText([JOUR], “MMMM”, Culture), type text),
InsertCalendarMonth = Table.AddColumn(InsertMonthName, “MOIS_CALENDRIER”, each (try(Date.ToText([JOUR], “MMM”, Culture)) otherwise [MOIS_LIBELLE]) & ” ” & Text.End(Number.ToText([ANNEE]),2), type text),
InsertCalendarQtr = Table.AddColumn(InsertCalendarMonth, “TRIMESTRE_CALENDRIER”, each “T” & Number.ToText([TRIMESTRE]) & ” ” & Number.ToText([ANNEE]), type text),
InsertDayWeek = Table.AddColumn(InsertCalendarQtr, “JOUR_SEMAINE”, each Date.DayOfWeek([JOUR], Day.Monday)+1, Int64.Type),
InsertDayName = Table.AddColumn(InsertDayWeek, “JOUR_LIBELLE”, each Date.ToText([JOUR], “dddd”, Culture), type text),
InsertWeekEnding = Table.AddColumn(InsertDayName, “JOUR_FIN_SEMAINE”, each Date.EndOfWeek([JOUR]), type date),
InsertMonthOrder = Table.AddColumn(InsertWeekEnding , “ORDRE_MOIS”, each [ANNEE]*100+[MOIS], Int64.Type)
in
InsertMonthOrder
in
CreateDateTable
——————————12 January 2022 at 10 h 13 min #100569Sophie Marchand
ParticipantBonjour,
Sinon, nous avons le fichier suivant à notre boutique https://www.lecfomasque.com/produit/fonctions-calendrier-dans-power-query/. Il permet de récupérer différents codes selon divers scénarios de calendrier et il vient avec un tutoriel écrit et une vidéo.
Au plaisir,
Sophie
13 January 2022 at 2 h 42 min #100580magali.careddu
ParticipantMerci à vous deux pour vos réponses et l’aide apportée.
Je vais m’inspirer du code M, et à terme je pense me procurer le fichier de la boutique.Merci beaucoup !
Magali
-
AuthorPosts
- You must be logged in to reply to this topic.