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
kai1109
Frequent Visitor

I want to get the average and maximum value of the average before the selected month in slicer

As the title says.
Please advise how to implement it

 

name date(month)value
AApr-23200
BApr-23300
CApr-23400
DApr-23500
AMay-23150
BMay-23250
CMay-23350
DMay-23450
AJun-2350
BJun-2360
CJun-2370
DJun-2380
AJul-2390
BJul-23100
CJul-23110
DJul-23120
AAug-23555
BAug-23555
CAug-23555
DAug-23555
ASep-23222
BSep-23222
CSep-23222
DSep-23222

 


If you have data like this, let's say you select June in the slicer.
I would like to display the results in the table below.

namedate(month)value
AJun-23133
BJun-23203
CJun-23273
DJun-23343


The logic is that if you select June in the slicer, the average value for each name will be calculated as April, May and June, and May and June.
I want to display the maximum value among them.

For example, if June is selected with the slicer, the average of June and May is 100, and the average of June, May, and April is 133. Therefore, I would like to display 133.

 

And there are some conditions.
・You can go back up to 6 months.
・I want to calculate it by fiscal year, so it starts in April and ends in March.
・So, in the case of April, the average is not calculated, and in the case of March, the above calculation is performed using data up to October.

 

please give me a good idea

 

1 ACCEPTED SOLUTION
v-heq-msft
Community Support
Community Support

Hi @kai1109 ,

Thanks to @Musadev  for the solution.
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1710145019652.png

Create a date table

Date = VALUES('Fact'[date(month)])

Create a measure

Maximum of two averages = 
VAR sum_3 = 
CALCULATE(
    SUM('Fact'[value]),
    FILTER(
        'Fact',
        'Fact'[date(month)] <= SELECTEDVALUE('Date'[date(month)]) && 'Fact'[date(month)] >= EDATE(SELECTEDVALUE('Date'[date(month)]),-2)
        )
    )
VAR sum_2 = 
CALCULATE(
    SUM('Fact'[value]),
    FILTER(
        'Fact',
        'Fact'[date(month)] <= SELECTEDVALUE('Date'[date(month)]) && 'Fact'[date(month)] >= EDATE(SELECTEDVALUE('Date'[date(month)]),-1)
    )
)
VAR average_2 = DIVIDE(sum_2,2)
VAR average_3 = DIVIDE(sum_3,3)
RETURN
IF(
    average_2 > average_3,
    average_2,
    average_3
)

Use date table as the value of slicer
Fianl output

vheqmsft_1-1710145121327.png

 

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
v-heq-msft
Community Support
Community Support

Hi @kai1109 ,

Thanks to @Musadev  for the solution.
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1710145019652.png

Create a date table

Date = VALUES('Fact'[date(month)])

Create a measure

Maximum of two averages = 
VAR sum_3 = 
CALCULATE(
    SUM('Fact'[value]),
    FILTER(
        'Fact',
        'Fact'[date(month)] <= SELECTEDVALUE('Date'[date(month)]) && 'Fact'[date(month)] >= EDATE(SELECTEDVALUE('Date'[date(month)]),-2)
        )
    )
VAR sum_2 = 
CALCULATE(
    SUM('Fact'[value]),
    FILTER(
        'Fact',
        'Fact'[date(month)] <= SELECTEDVALUE('Date'[date(month)]) && 'Fact'[date(month)] >= EDATE(SELECTEDVALUE('Date'[date(month)]),-1)
    )
)
VAR average_2 = DIVIDE(sum_2,2)
VAR average_3 = DIVIDE(sum_3,3)
RETURN
IF(
    average_2 > average_3,
    average_2,
    average_3
)

Use date table as the value of slicer
Fianl output

vheqmsft_1-1710145121327.png

 

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you for the very helpful calculation formula.
I tried to reflect this in actual data, but it didn't work.
I think that the calculation results are probably incorrect because it needs to be calculated starting in April.
For example, when I select April in the sample data I received, the results are also incorrect.
I use TOTALYTD in other calculation formulas, is it possible to incorporate it into this calculation formula as well?

Hi @kai1109 ,
Thank you for your reply, according to your description you want to end the fiscal year with a custom time, you can certainly customize the fiscal year cycle with the parameters of TOTALYTD.

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

sorry. It still didn't go well.
Please give me some more advice.

For production data, the date table and fact table need to connect relationships in order to take advantage of other formulas and graphs.

 

kai1109_0-1710304876871.pngkai1109_1-1710304889574.png

 

If relations are connected, when you select a slicer in the date table, the data will be filtered by that month, and the average maximum time will not reach the required value.

Is there any good solution?

I would like to ask you to provide additional information.
In actual data,
Select the year and month separately using the slicer.
How should I modify the calculation formula in that case?
I added 

 

'Fact'[date(year)] <= SELECTEDVALUE('Date'[year])

 

to the FILTER part, but it didn't give me the desired result.

name date(month)yearvalue
A42024200
B42024300
C42024400
D42024500
A52024150
B52024250
C52024350
D52024450
A6202450
B6202460
C6202470
D6202480
A7202490
B72024100
C72024110
D72024120
A82024555
B82024555
C82024555
D82024555
A92024222
B92024222
C92024222
D92024222
Musadev
Resolver III
Resolver III

Hi @kai1109 
You need to create 2 measures to get the desired results. 

 

AvgValue = AVERAGEX(TBL1,TBL1[Value])

 

 

This will calculate the  average value and in the second measure you will get the 3 months average for any current month, 

 

Last 3 Months Avg = CALCULATE(
    [AvgValue],
    DATESINPERIOD(TBL1[Date],
    MAX(TBL1[Date]),
    -3,
    MONTH
    )
)

 


Check the results here .

Musadev_0-1709888513229.png

 

If any post helps, please consider Accepting it as the solution to help other members find it more quickly.

If I misunderstand your needs or if you still have problems, please feel free to let us know. Thanks a lot!



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.