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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Solution Sage
Solution Sage

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.