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
Happy2023_05
Helper I
Helper I

Calculating values based on Date selection from slicer

hi,

I want to calculate values based on date slicer selection.

for eg date slicer 01/02/2022 to 01/05/2022. I need to write DAX. can someone help on this?

for eg calculate(sum(x), date in slicer selection). what DAX function can be used to get this? 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Happy2023_05 

Thanks for reaching out to us.

If you create a relationship between the calendar table and the fact table, then when you filter the date in the slicer, the data in the fact table in visual will also be filtered. If you don't want the number of data rows in visual to be affected, please try the following method:

Sample (see sample file attached below)

vxiaotang_2-1668414784513.png

(1) create a calendar table

calendar = calendar(DATE(2021,1,1),DATE(2022,12,31))

vxiaotang_0-1668414702577.png

(2) create the measure below

Measure1 = 
var _start=MINX(ALLSELECTED('calendar'),[Date])
var _end=MAXX(ALLSELECTED('calendar'),[Date])
var _sum= SUMX(FILTER('Table','Table'[Date]>=_start && 'Table'[Date]<=_end),[value])
return "date range:"&_start&"-"&_end&": "&_sum

vxiaotang_1-1668414764514.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Happy2023_05 

Thanks for reaching out to us.

If you create a relationship between the calendar table and the fact table, then when you filter the date in the slicer, the data in the fact table in visual will also be filtered. If you don't want the number of data rows in visual to be affected, please try the following method:

Sample (see sample file attached below)

vxiaotang_2-1668414784513.png

(1) create a calendar table

calendar = calendar(DATE(2021,1,1),DATE(2022,12,31))

vxiaotang_0-1668414702577.png

(2) create the measure below

Measure1 = 
var _start=MINX(ALLSELECTED('calendar'),[Date])
var _end=MAXX(ALLSELECTED('calendar'),[Date])
var _sum= SUMX(FILTER('Table','Table'[Date]>=_start && 'Table'[Date]<=_end),[value])
return "date range:"&_start&"-"&_end&": "&_sum

vxiaotang_1-1668414764514.png

 

Best Regards,

Community Support Team _Tang

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

serpiva64
Super User
Super User

Hi,

i think you don't need to write any dax.

You only need to create a relationship between your calendar table and your fact table.

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.

Top Solution Authors