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
Mahadevaraobc
Helper II
Helper II

Average of last 3 values and next 3 values

Hello Experts,

 

I have a table as following

 

ProductSalesno of stores% Conversion
A3255092590.95%
A3103522811.09%
A3219342751.03%
A3197622911.09%
A3275092801.03%
A3204362911.09%
A3063023341.31%
A2963512380.96%
A24948160.77%
A28846120.50%
A27870271.16%
A30454180.71%
A30065100.40%
B2976780.32%
B35922210.70%
B39480110.33%
B40592140.41%
B41127160.47%
B38268220.69%
B25217150.71%
B18070161.06%
B16965100.71%
B16683191.37%
B15762141.07%
B1505770.56%
B13587110.97%
C567971.48%
C876150.68%
C716730.50%
C487351.23%
C655761.10%
C646971.30%
C645250.93%
C1250980.77%
C642191.68%
C641710.19%
C641440.75%
C641030.56%
C640950.94%
C640861.12%

 

I would like to know how to get an average of 7 values based on a highest sales condition.

ex: Calculate highest value of sales in Product A which is 327509 and based on this value check what is the % conversion (1.03%), now calculate average of % conversion for last 3 values and next 3 values including the current value (Average of total 7 values). In this case it will be 1.08%

1.09%
1.03%
1.09%
1.03%
1.09%
1.31%
0.96%

 

Thanks in advance for your help.

19 REPLIES 19
tamerj1
Super User
Super User

@Mahadevaraobc 
Here is the updated sample file https://we.tl/t-oXVgQzVfA8

1.png

% Converion = 
VAR CurrentIndex = MAX ( Data[Index] )
VAR CurrentNumOfStores = MAX ( Data[no of stores] )
VAR CurrentSales = MAX ( Data[Sales] )
VAR CurrentProductTable =
    CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Product] ) )
VAR MaxSales = MAXX ( CurrentProductTable, Data[Sales] )
VAR IndexOfMaxSales = 
    MAXX ( FILTER ( CurrentProductTable, Data[Sales] = MaxSales ), Data[Index] )
VAR Result = DIVIDE ( CurrentNumOfStores * 12, CurrentSales )
RETURN
    IF ( CurrentIndex >= IndexOfMaxSales - 3 && CurrentIndex <= IndexOfMaxSales + 3, Result )

@Mahadevaraobc

If your data is not already aggregated then you need to create an index measure based  in the original index then we need to modify our formula. It would more complex but can be achieved. If this is the case then please provide me with sample raw dat. 

Hi @tamerj1 ,

 

Attaching an excel file which has info and reqd field,i have marked highest value in red and avg of 7 months in yellow for reference.

How to attach xlsx file not able to find an option to attach

@Mahadevaraobc 
I see nothing attched. However, I updated the solution as requested. https://we.tl/t-n5VCL2koo1

The filter measure is as per the first version of the solution then a new Average % Converion measure as follows:

1.png

%Conversion = AVERAGEX ( ALLSELECTED ( Data[Index] ), CALCULATE ( SUM (Data[% Conversion] ) ) )

Hi @tamerj1 ,

 

I think we are close but my expectations is as below screenshot. 

Mahadevaraobc_0-1656338594998.png

 

@Mahadevaraobc 

1.png

Avergare % Conversion = 
VAR CurrentIndex = MAX ( Data[Index] )
VAR CurrentProductTable =
    CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Product] ) )
VAR MaxSales = MAXX ( CurrentProductTable, Data[Sales] )
VAR IndexOfMaxSales = 
    MAXX ( FILTER ( CurrentProductTable, Data[Sales] = MaxSales ), Data[Index] )
VAR FilteredTable = FILTER ( CurrentProductTable, Data[Index] >= IndexOfMaxSales - 3 && Data[Index] <= IndexOfMaxSales + 3 )
RETURN
    AVERAGEX ( FilteredTable, Data[% Conversion] )

Hi @tamerj1 ,

 

Thank you but the expected value shown above is different from the value i get in excel.

ex: Avg of Product A is 1.08%, Avg of Product B is 0.63% but the value you are getting is 1.09% and 0.62%. 

@Mahadevaraobc 

Apparently it is a rounding issue 

Hi @tamerj1 ,

 

Mahadevaraobc_0-1656341184740.png

The Filter Measure is showing 1 correctly but not %conversion, in above case product A average should be 1.08% (average of values % Conversion column) for all values, but sample shows 0.93% for all ( taking an average of all values in Product A, it should only take avg of Filter Measure value is 1)

Hi @tamerj1 ,

 

Thanks for helping, our table already has a %conversion column our needs are mentioned below.

1) check max sales in the table 

2) get value of %conversion

3) get values of +3 months values and -3 months

4) make an average based on these 7 values and show in different column

 

ex: 

Product A max sales = 327509 which %conversion is 1.03%

DateProductSalesno of stores% Conversionexpected result
201611A3255092590.95%1.08%
201612A3103522811.09%1.08%
201701A3219342751.03%1.08%
201702A3197622911.09%1.08%
201703A3275092801.03%1.08%
201704A3204362911.09%1.08%
201705A3063023341.31%1.08%
201706A2963512380.96%1.08%
201707A24948160.77%1.08%
201708A28846120.50%1.08%
201709A27870271.16%1.08%
201710A30454180.71%1.08%
tamerj1
Super User
Super User

Hi @Mahadevaraobc 
Plesae refer to sample file with the solution https://we.tl/t-Lph83wQrrO

1.png

Hi @tamerj1 ,

 

Its working and showing me 1 as expected , but how can i display average of %conversion in place of 1.

ex: 1s should be replaced by averaging all 7 values of %conversion. 

@Mahadevaraobc 
Please define average of %conversion

@tamerj1 

%of conversion will be no of stores*12/sales.

Mahadevaraobc
Helper II
Helper II

Hi @tamerj1 ,

 

Here it is

DateProductSalesno of stores% Conversion
201611A3255092590.95%
201612A3103522811.09%
201701A3219342751.03%
201702A3197622911.09%
201703A3275092801.03%
201704A3204362911.09%
201705A3063023341.31%
201706A2963512380.96%
201707A24948160.77%
201708A28846120.50%
201709A27870271.16%
201710A30454180.71%
201711A30065100.40%
201611B2976780.32%
201612B35922210.70%
201701B39480110.33%
201702B40592140.41%
201703B41127160.47%
201704B38268220.69%
201705B25217150.71%
201706B18070161.06%
201707B16965100.71%
201708B16683191.37%
201709B15762141.07%
201710B1505770.56%
201711B13587110.97%
201611C567971.48%
201612C876150.68%
201701C716730.50%
201702C487351.23%
201703C655761.10%
201704C646971.30%
201705C645250.93%
201706C1250980.77%
201707C642191.68%
201708C641710.19%
201709C641440.75%
201710C641030.56%
201711C640950.94%
201712C640861.12%

 

Date is in YYYYMM format

Mahadevaraobc
Helper II
Helper II

Hi @tamerj1 ,

 

Yes there is a date field 

Mahadevaraobc
Helper II
Helper II

Hi @tamerj1,

Thanks for helping,

Product C has maximum value in between which is 12509.

 

@Mahadevaraobc 

Thank you. Do you gave a date or index column?

tamerj1
Super User
Super User

Hi @Mahadevaraobc 

do you have a date or index column? This shall be per each product? For prouct C there is only one value before the maximum one. In this case only 5 records will be displayed or they must be 7 records anyway?

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.