Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

 

 

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community 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] )
        )
    )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-frfei-msft
Community Support
Community 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] )
        )
    )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
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 !

Hi @Anonymous ,

 

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

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
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). 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.