Décumul de montant à partir du total et périodes début/fin

Accueil – Le CFO masqué Forums Power Query Décumul de montant à partir du total et périodes début/fin

Mots-clés : , ,

  • Ce sujet contient 1 réponse, 1 participant et a été mis à jour pour la dernière fois par chikletch, le il y a 4 années et 5 mois.
2 sujets de 1 à 2 (sur un total de 2)
  • Auteur
    Articles
  • #58774
    chikletch
    Participant

    Bonjour, désolé, je post en anglais car je viens de poster sur le forum de MS … mais les réponses peuvent être en français sans aucun problème. Merci pour le coup de main, et félicitation aux membres de cette communauté.

    Hi,
    I am a debutant in PowerQuery, and I search to have “decumulation” or periodical amounts from a cumulative amount.

    My use case is the following: I have one table with Item Description, Start Date, End Date and an amount for this duration. I need to obtain a table with the amount for each period (each day between Start Date and End Date, for example).

    Table ITEMS:
    Item StartDate EndDate TotAmnt
    Fsdfsfssf 01/01/2019 01/01/2022 43454,09
    Vfvsfsfgsfgs 13/02/2020 19/06/2022 984334,43
    …….

    With SQL statement, it’s easy.
    I create a table with all the periods I need and I obtain what I want with this statement.

    Table CALENDAR:
    Period
    01/01/2018
    01/02/2018
    01/03/2018
    ……..

    SELECT ITEMS.Item, Period AS CALENDAR.Period, PeriodAmount AS ITEMS.TotAmnt/(DateDiff(ITEMS.StartDate, ITEMS.EndDate))
    FROM ITEMS, CALENDAR
    WHERE (CALENDAR.Period >= ITEMS.StartDate AND CALENDAR.Period < ITEMS.EndDate)

    How can I do that with PowerQuery and Langage M, using data/table from my current Excel Sheet?

    I have seen how to connect me to twos tables in Excel which are basically my ITEMS and CALENDAR tables.
    Then, I tried to use the method Table.SelectRows and similar criterias of my SQL Statement: Calendar.Period >= ITEMS.Start, etc… but it doesn’t work… the method expects a logical result and not a function one.
    I try to use also methods from List… without success.

    I am thinking writing some Loops, but I don’t have already understood correctly how the “each” operator works.

    Somebody can give me some orientations and tips ?
    I imagine that this need to cumulate or “decumulate” (or uncumulate ?) amounts are a recurrent use case for PowerQuery developpers.

    Thanks for any help.
    Chikus

    #58783
    chikletch
    Participant

    Une réponse a été postée sur TechNet, je la partage à toute fin utile.

    https://social.technet.microsoft.com/Forums/en-US/1e564972-6e6c-4d94-b859-24c1cf0f77e7/decumulation-uncumulation-of-amounts-with-excel-and-power-query?forum=powerquery#1e564972-6e6c-4d94-b859-24c1cf0f77e7

    En fait, la méthode proposée (et qui marche très bien) est :
    * créer une liste de toutes les dates comprises entre la date de début et la date de fin ;
    * compter le nombre de valeur de cette liste (dénominateur) ;
    * diviser le montant total par ce dénominateur ;
    * Déployer (Déplier) la liste et j’obtiens la table attendue.

    Sympa PowerQuery et le Langage M … plus besoin de SQL, etc… et tout dans Excel

2 sujets de 1 à 2 (sur un total de 2)
  • Vous devez être connecté pour répondre à ce sujet.