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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Dax Same Period (user defined) Period Last Months

Hi everyone,

 

I need help to get the average of sales of past 3 months relative to the user defined day of the month (selectedvalue).

 

I am able to find similar solution but this always points to date TODAY(). 

 

For example, today is April 16, 2021:

- I would like to select April 20, 2021 (future date);

- Average of the following dates would be shown:

     March 1 - 20

     Feb 1 - 20

     Jan 1 -20

 

 

This is the similar solution i found and tried to edit by replacing TODAY() with SELECTEDVALUE:

=====

2-MonthSamePeriod Sum =
CALCULATE (
SUM ( 'Sheet 1'[Order Lines/Subtotal w/o Tax] ),
FILTER (
'DATE',
AND (
[Date]
>= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
[Date]
<= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) - 1 )
)
)
)
 
Thanks in advance guys.
Jap

 

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

Hi @Anonymous ,

 

Please use the following measure to get the average of sales of past 3 months:

 

Measure =
AVERAGEX (
    FILTER (
        'Date',
        DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH )
    ),
    SUM ( 'Sheet 1'[Order Lines/Subtotal w/o Tax] )
)

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please use the following measure to get the average of sales of past 3 months:

 

Measure =
AVERAGEX (
    FILTER (
        'Date',
        DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH )
    ),
    SUM ( 'Sheet 1'[Order Lines/Subtotal w/o Tax] )
)

 

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

 

Best Regards,

Dedmon Dai

HarishKM
Impactful Individual
Impactful Individual

@Anonymous Hey

Try this 

Test 2 = CALCULATE(SUM(Sheet1[Sales]),DATEADD(ALLSELECTED(Sheet1[Date]),-3,MONTH))
amitchandak
Super User
Super User

@Anonymous , Try a measure with help from date Table

 

Rolling 3 =
var _max = day(MAXX(ALLSELECTED('date'),'date'[Date])) //or // day(Today()) //or// Day(today()+4)
return
CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH), filter('Date', Day('Date'[Date]) <=_max))

 

//or are replacement values that you can use for _max

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.