Forum Discussion

H3nning's avatar
H3nning
Icon for Helper V rankHelper V
6 years ago

Sum up Datediff based on filter

Hi,

 

hope someone can give me a hint for a problem I'm thinking about for a while now.

 

I have Sales with the Date of Sales and who sold it:

 

Table Sales:

Date | Person | Amount

 

I also have the date when the Person entered a new stage of experience:

 

Table Person:

Person | EndOfStage1 | EndOfStage2 | EndofStage3 | EntryDate | Manager

 

Now I need to calculate the Amount per day in a certain stage for a selectable time period. The result should be in total or by Manager.

So for Stage1 I need to sum up the amount of sales made by any Person in Stage 1 during the time of the sale

divided by the sum of days all people spend in Stage1 during the selected Period. 

 

I especially have problems with the sum of days, because it is not just difference between EntryDate and EndOfStage1. For example when the upper bound of the date filter is set in the middle of these two dates, then the diff between EntryDate and the upper bound should only be counted. 

Also the calculation has to be made for each person and after that summed up to the respective context (eg Manager).

 

Any clues on this?

 

Best Regards and many thanks

 

 

 

 

7 Replies

    • H3nning's avatar
      H3nning
      Icon for Helper V rankHelper V

      Hi,

       

      sorry for the confusuion. Person is a dimension of course (1:n).

  • v-yuta-msft's avatar
    v-yuta-msft
    Icon for Community Support rankCommunity Support

    H3nning ,

     

    I'm confused on your description. Could you please share some sample data and clarify more details about your expected result?

     

    Regards,

    Jimmy Tao

    • H3nning's avatar
      H3nning
      Icon for Helper V rankHelper V

      Only found a possibility to upload photos:

       

      The result is dependent on filter here. Lets say we select just a few days, 2020-02-29 until 2020-03-02.



      The result for Stage 1 and Manager Carl should be 0.5

      There were 2 sales for Carl's team in that period and in that stage (twice Simone and she was Stage 1).
      Carl's team members spend 4 days in that stage during that period (1 day Ute + 3 days Simone).
      So the result should be 2 divided by 4 for equals 0.5

      Hope that clears it up a bit. Thanks in advance 🙂

       

      Edit: result for Stage 2 should be 0, because no one made a sale during that period and in that Stage, but Ute spent there 2 days (0 devided by 2).

       

      Result for Manager Lilly and Stage 1 : 0 -> no sales and 6 days -> 0 / 6

      Result for Manager Lilly and Stage 2 : blank -> no sales an no days 0 / 0

      • v-yuta-msft's avatar
        v-yuta-msft
        Icon for Community Support rankCommunity Support

        H3nning ,

         


        There were 2 sales for Carl's team in that period and in that stage (twice Simone and she was Stage 1).
        Carl's team members spend 4 days in that stage during that period (1 day Ute + 3 days Simone).
        So the result should be 2 divided by 4 for equals 0.5

        What does "Stage1" mean? Could you show the logic using some expression?

         

        Regards,

        Jimmy Tao