Forum Discussion

Sibrulotte's avatar
Sibrulotte
Helper IV
2 years ago

Row level date range

Hi,

We have a model with email messages, send logs, contacts, and transactional data from sales.

Message:

Message Nom Message ID

webinaire envoie 11
webinaire envoie 22
webinaire envoie 33
webinaire envoie 44

 

Send Log: 

 

Message ID Sent_date Contact ID

118 janvier 202410
118 janvier 202420
118 janvier 202430
121 janvier 202440
29 février 202410
29 février 202440
210 février 202420
31 mars 202410
316 mars 202430
41 avril 202410
41 avril 202450
43 avril 202420
45 avril 202430
410 avril 202440

 

Contact:

Contact ID Epargnant id

10100
20200
30300
40400
50500

 

Transactional:

Epargnant_id date_report transaction_brut ind_adhesion

10025 janvier 20242001
10027 février 202430 
10029 mars 202450 
10015 avril 2024120 
20015 février 2024201
2004 mars 2024100 
20029 mars 202490 
20018 avril 202410 
3004 février 2024701
30029 février 2024130 
3004 mars 202420 
30019 mars 202490 
3004 avril 202440 
40025 janvier 2024201
40027 février 2024130 
40012 avril 202410 
50025 avril 20241001

 

 

We are looking to show sum of transaction brut from transactional data that has a Date_report that is within 14 days after the Sent_date only.

So our final matrix should look like:

Message

Amount

Webinaire Envoie 1

220

Webinaire Envoie 2

20

Webinaire Envoie 3

90

Webinaire Envoie 4

10

 

 

Webinaire Envoie 1 would be 220 because client 100 had a 200$ sale between January 18th 2024 and 14 days later --> February 1st and client 400 had 20$ sale between January 21st and February 4th. The sale from client 300 on February 4th should not count since his sent date was January 18th and the 14 day period would end February 1st. All the sales for client 200 also come after the 14 day period of him receiving the email.

 

 

We are fully aware that we might have over lapping reporting (webinaire 1 and 3 might be showing the same “amount” from the same client twice).

7 Replies

  • Hi my message was marked as spam and is just getting posted, so I'm bringing it back to the top for your attention. Thank you 🙂

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Sibrulotte 

    You can try the following method to solve the problem.

    Steps:
    1.Three consecutive Merges

    2. Add costom column to calcute the date differ between [Transactional.date_report] and [Send Log.Sent_date]

     

    3. Filter Date differ if the date differ between 0 and 14

    4. Remove unneeded columns

    5. Back to desktop, use the following measure.

    transaction_brut_result = 
    CALCULATE(SUM(ResultTable[Transactional.transaction_brut]))


    Advanced Editor:

    let
        Source = Table.NestedJoin(Message, {"Message ID"}, #"Send Log", {"Message ID"}, "Send Log", JoinKind.RightOuter),
        #"Expanded Send Log" = Table.ExpandTableColumn(Source, "Send Log", {"Message ID", "Sent_date", "Contact ID"}, {"Send Log.Message ID", "Send Log.Sent_date", "Send Log.Contact ID"}),
        #"Merged Queries" = Table.NestedJoin(#"Expanded Send Log", {"Send Log.Contact ID"}, Contact, {"Contact ID"}, "Contact", JoinKind.LeftOuter),
        #"Expanded Contact" = Table.ExpandTableColumn(#"Merged Queries", "Contact", {"Contact ID", "Epargnant id"}, {"Contact.Contact ID", "Contact.Epargnant id"}),
        #"Merged Queries1" = Table.NestedJoin(#"Expanded Contact", {"Contact.Epargnant id"}, Transactional, {"Epargnant_id"}, "Transactional", JoinKind.LeftOuter),
        #"Expanded Transactional" = Table.ExpandTableColumn(#"Merged Queries1", "Transactional", {"Epargnant_id", "date_report", "transaction_brut", "ind_adhesion"}, {"Transactional.Epargnant_id", "Transactional.date_report", "Transactional.transaction_brut", "Transactional.ind_adhesion"}),
        #"Added Custom" = Table.AddColumn(#"Expanded Transactional", "Custom", each [Transactional.date_report] - [Send Log.Sent_date]),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Custom] >= #duration(0, 0, 0, 0) and [Custom] <= #duration(14, 0, 0, 0)),
        #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Message ID", "Send Log.Message ID", "Send Log.Sent_date", "Send Log.Contact ID", "Contact.Contact ID", "Contact.Epargnant id", "Transactional.Epargnant_id", "Transactional.date_report", "Transactional.ind_adhesion", "Custom"})
    in
        #"Removed Columns"

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

    • Sibrulotte's avatar
      Sibrulotte
      Helper IV

      Hi Anonymous ,

      unfortunatly the first steps cannot be done properly. There are more than one sent date per transaction. 

      That will multiply my transaction table like crazy. Not doable.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi, Sibrulotte 

        You can share the pbix file without sensitive data for testing by Google Drive. 

        Best Regards,
        Yang
        Community Support Team