Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Versioning KPI month-by-month & dynamic sum calculation

Hello all, 

I'm looking for your help because I don't know the way forward in the creation of a stock KPI report. 

 

What I'm trying to achieve : the evolution of my stock quality KPI month by month based on the sales history for each product over the past 12 months (there are more calculation but my problem lies here) 

 

My issue: Creating the relationship between by table stock and my table sales and effectively calculate my sales history over the last 12 months from the extraction date, as I have one new version a month I'm not sure how to link them together now. 

 

Here are my two tables: 

1* My stock table, for which I retrieve a 'snapshot' each first Monday of the month : 

ProductLocationStockExtraction date
AAB307-01-19
BAC407-01-19
CAB207-01-19
DAD507-01-19
AAB504-02-19
BAC704-02-19
CAB104-02-19
DAD204-02-19
AAB104-03-19
BAC204-03-19
CAB104-03-19

 

2* My sales history table

ProductLocationDateQuantity
AAB10-12-181
BAC10-03-182
CAD05-09-181
AAB08-01-183
BAC29-09-185
DAD06-02-193
CAD04-03-182
AAB14-05-181
DAC04-07-182
BAC14-05-181

 

So for each product/location/extraction date I would like to get the sum of the sales history over the past 12 month (start date = extraction date - one year / end-date = extraction date). I would like to make it dynamic, next month I can refresh my report and get the info for this month. 

Accoding to you, what would be the most effective way to do it ? 

Thanks a lot for your help!
Reno

 

 

  • Hi Anonymous ,

     

    We can create a measure as below.

     

    Measure = 
    VAR startdate =
        MAX ( stock[Extraction date] ) - 365
    VAR prod =
        MAX ( stock[Product] )
    VAR location =
        MAX ( stock[Location] )
    RETURN
        CALCULATE (
            SUM ( sales[Quantity] ),
            FILTER (
                sales,
                sales[Product] = prod
                    && sales[Location] = location
                    && 'sales'[Date] >= startdate
                    && 'sales'[Date] <= MAX ( 'stock'[Extraction date] )
            )
        )
    

     

5 Replies

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

    Hi Anonymous ,

     

    We can create a measure as below.

     

    Measure = 
    VAR startdate =
        MAX ( stock[Extraction date] ) - 365
    VAR prod =
        MAX ( stock[Product] )
    VAR location =
        MAX ( stock[Location] )
    RETURN
        CALCULATE (
            SUM ( sales[Quantity] ),
            FILTER (
                sales,
                sales[Product] = prod
                    && sales[Location] = location
                    && 'sales'[Date] >= startdate
                    && 'sales'[Date] <= MAX ( 'stock'[Extraction date] )
            )
        )
    

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-frfei-msft Thanks a lot for your answer, the output looks exactly what I'm looking for. 

      I'm really surprise to see that there is no relationship between the two tables, how is that possible ? I'm a bit confused :) 

      Ashish_Mathur Thanks for your answer, interesting model with those extra tables. However the output is not exactly what I wanted. Date column should be the extraction one, and I should be able to compare sales history of the last 12 month with the current stock (in order to make an average sales history per day, to measure how many days can be covered by the current stock). 

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-frfei-msft Nevermind, by addind the measure to my model I realized how the relationship was made within the measure via the filters. This is amazing ! What is the purpose of the MAX function here ? I don't really knows what it makes with text column. Anyway thanks again !

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

        Hi Anonymous ,

         

        The MAX  function is used to get the value of current row in the column here.