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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

SUM values during the last 7 days and between 2 dates ( similar to GROUP BY on SQL)

Hello,

I have a table that looks something like the one below. It summarizes the daily number of products sold by a retailer in a shopping center in the month of January.

johnray_2-1623368254418.png

 

How do I write a measure using DAX such that I can

-  calculate the total number of products sold in the 7 days of January
-  calculate the total number of products sold in the between 2 dates

 

So that the output PBI table that I need to display looks like this:

 

johnray_0-1623368522029.png

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Assume one is range selected and one we have the force

 

calculate(sum(Table[product sold]), filter(Date, Date[Date] >=date(2021,1,1)  && Date[Date] <=date(2021,1,7) ))

 

if date is connected

measure =
var _min = minx(allselected('Date'), 'Date'[Date])
var _max = maxx(allselected('Date'), 'Date'[Date])
return
calculate(sum(Table[product sold]))

 

You can use an independent table

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

How to use two Date/Period slicers :https://www.youtube.com/watch?v=WSeZr_-MiTg

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , Assume one is range selected and one we have the force

 

calculate(sum(Table[product sold]), filter(Date, Date[Date] >=date(2021,1,1)  && Date[Date] <=date(2021,1,7) ))

 

if date is connected

measure =
var _min = minx(allselected('Date'), 'Date'[Date])
var _max = maxx(allselected('Date'), 'Date'[Date])
return
calculate(sum(Table[product sold]))

 

You can use an independent table

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

How to use two Date/Period slicers :https://www.youtube.com/watch?v=WSeZr_-MiTg

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.