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
datapy
Regular Visitor

Filter table visual bewteen date range based on slicer

Hi, I am having difficulties to do the following in Power BI Desktop :

I would like to make a table visual which is being filtered on a date range based on a date slicer visual.

 

Here is an example :

Date selected in date slicer : 03/01/2024

Date range for filtering table visual is 3 days prior the selected date: from 01/01/2024 until the 01/03/2024 included

 

I tried to following DAX code :

MeasureAmount =

var currentDate = SELECTEDVALUE(FactTable[date])

var startDate   = currentDate - 2

var sumAmount   =

CALCULATE

(

    SUM(FactTable[amount]),

    DATESBETWEEN

    (

        FactTable[date],

        startDate,

        currentDate

    )

)

return sumAmount

 

This measure works fine when I display it on a table visual. In the screenshot below, the measure returns 2774 which is the expect output. However, when I add other columns such as date and idSale, the data shown is not what I am expecting. In my example, only data for the 03/01/2024 is displayed.

Picture 1

image1.png

 

 

The expected result is the following :

Picture 2

image2.png

 

Any ideas how to solve this ?

 

Many thanks

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

Hi @datapy ,

The Table data is shown below:

vzhouwenmsft_0-1712282480748.png

Please follow these steps:

1. Use the following DAX expression to create a table 

Table 2 = CALENDAR(DATE(2024,1,1),DATE(2024,1,6))

2. Use the following DAX expression to create a measure

MeasureAmount = 
var currentDate = SELECTEDVALUE('Table 2'[Date])
var startDate   = currentDate - 2
var sumAmount   = CALCULATE(SUM('Table'[Amount]),DATESBETWEEN('Table'[Date],startDate,currentDate))
RETURN sumAmount

3.Final output

vzhouwenmsft_1-1712282660260.png

vzhouwenmsft_2-1712282682357.png

vzhouwenmsft_3-1712282727595.png

vzhouwenmsft_4-1712282738808.png

vzhouwenmsft_5-1712282761448.png

 

Best Regards,
Wenbin Zhou
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

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-zhouwen-msft
Community Support
Community Support

Hi @datapy ,

The Table data is shown below:

vzhouwenmsft_0-1712282480748.png

Please follow these steps:

1. Use the following DAX expression to create a table 

Table 2 = CALENDAR(DATE(2024,1,1),DATE(2024,1,6))

2. Use the following DAX expression to create a measure

MeasureAmount = 
var currentDate = SELECTEDVALUE('Table 2'[Date])
var startDate   = currentDate - 2
var sumAmount   = CALCULATE(SUM('Table'[Amount]),DATESBETWEEN('Table'[Date],startDate,currentDate))
RETURN sumAmount

3.Final output

vzhouwenmsft_1-1712282660260.png

vzhouwenmsft_2-1712282682357.png

vzhouwenmsft_3-1712282727595.png

vzhouwenmsft_4-1712282738808.png

vzhouwenmsft_5-1712282761448.png

 

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

 

Hi, many thanks for your help. It works now!

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.