Table de Dates

Home – Le CFO masqué Forums Power Query Table de Dates

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #100566
    magali.careddu
    Participant

    Bonjour,

    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

    #100567
    JBruneau
    Participant

    Bonjour 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
    ——————————

    #100569
    Sophie Marchand
    Participant

    Bonjour,

    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

    #100580
    magali.careddu
    Participant

    Merci à 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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.