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

Custom date range in Line chart from slicer selection

Hi All,

 

I would like some help on this one as I cannot figure it out.

 

I have a regular date range slicer for Date. 

 

I want to show the last 3 month from the max selected date in the slicer (not current date). I want to show the results in a line chart

 

Ex. Selected Slicer Value: 2020-07-01, the range in line chart shows 2020-05-02 to 2020-07-01

 

I have the following calculation but the line chart is still showing for the full date range:

 

 

Sales Last 60 d = 
var Ldate = MAX('Date'[Date]) //Last date
var Fdate = (Ldate-60) // last 60 days
return
calculate([Sales Total], 
    FILTER (
        Sales,
        RELATED('Date'[Date]) >= Fdate )))
 

 

Thanks!

 

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

Hi @Anonymous ,

 

We can create a date table and a measure to meet your requirement.

The date table has no relationship with sales table.

 

1. Create a date table to be a slicer.

 

Date = CALENDAR("2020/1/1","2020/8/1")

 

cus1.jpg

 

cus2.jpg

 

2. Then we can create a measure.

 

Sales Last 60 d = 
var _SelectDate = SELECTEDVALUE('Date'[Date])
var _Fdate = _SelectDate-60
var _result = 
calculate(
    SUM('Sales table'[Sales]), 
    FILTER (
        'Sales table',
        'Sales table'[Date]<=_SelectDate && 'Sales table'[Date] >=_Fdate))
return
IF(
    ISBLANK(_SelectDate),SUM('Sales table'[Sales]),_result)

 

cus3.jpg

 

cus4.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

4 REPLIES 4
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution.

 

Best regards,

 

Community Support Team _ zhenbw

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

v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a date table and a measure to meet your requirement.

The date table has no relationship with sales table.

 

1. Create a date table to be a slicer.

 

Date = CALENDAR("2020/1/1","2020/8/1")

 

cus1.jpg

 

cus2.jpg

 

2. Then we can create a measure.

 

Sales Last 60 d = 
var _SelectDate = SELECTEDVALUE('Date'[Date])
var _Fdate = _SelectDate-60
var _result = 
calculate(
    SUM('Sales table'[Sales]), 
    FILTER (
        'Sales table',
        'Sales table'[Date]<=_SelectDate && 'Sales table'[Date] >=_Fdate))
return
IF(
    ISBLANK(_SelectDate),SUM('Sales table'[Sales]),_result)

 

cus3.jpg

 

cus4.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

Greg_Deckler
Super User
Super User

@Anonymous - My Complex Selector quick measure provides an example of this scenario almost exactly.

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Complex-Selector/td-p/1116633

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Can I download the sample to try it out myself?

 

I dont understand why something like this is not available out of the box?

 

Appreciate further help in this.

 

Thanks

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.