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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.