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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Dax measure to get previous week and previous month record count

Hi,

 

Any help will be much appricatieated with following problem.

image001.jpg

 

Thanks

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

 

My dax Measures are fixed.

 

Last Week Count =
var MaxSelectedDate= CALCULATE( MAX ( 'Date'[Date]), ALLSELECTED ( 'Date'[Date] ))
Var SelectedWeek = CALCULATE(max('Date'[Week Number]),'Date'[Date]=MaxSelectedDate)
Var SelectedYear = CALCULATE(max('Date'[Year]),'Date'[Date]=MaxSelectedDate)
Var MaxWeek = CALCULATE(max('Date'[Week Number]),ALL('Date'))


return
calculate([Total Record Count],
FILTER(ALL('Date'),IF(SelectedWeek=1,
'Date'[Week Number]=MaxWeek && 'Date'[Year]=SelectedYear-1,
'Date'[Week Number]=SelectedWeek-1 && 'Date'[Year]=SelectedYear))
)
 
 
Last Month Count =
var MaxSelectedDate= CALCULATE( MAX ('Date'[Date]), ALLSELECTED ('Date'[Date] ))
Var SelectedMonth = CALCULATE(max('Date'[Monthnumber]),'Date'[Date]=MaxSelectedDate)
Var SelectedYear = CALCULATE(max('Date'[Year]),'Date'[Date]=MaxSelectedDate)
Var MaxMonth= CALCULATE(max('Date'[Monthnumber]),ALL('Date'))


return
CALCULATE([Total Record Count],
FILTER(ALL('Date'),IF(SelectedMonth=1,
'Date'[Monthnumber]=MaxMonth && 'Date'[Year]=SelectedYear-1,
'Date'[Monthnumber]=SelectedMonth-1 && 'Date'[Year]=SelectedYear))
)
 
It's working fine.
 
Thanks
 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,

 

My dax Measures are fixed.

 

Last Week Count =
var MaxSelectedDate= CALCULATE( MAX ( 'Date'[Date]), ALLSELECTED ( 'Date'[Date] ))
Var SelectedWeek = CALCULATE(max('Date'[Week Number]),'Date'[Date]=MaxSelectedDate)
Var SelectedYear = CALCULATE(max('Date'[Year]),'Date'[Date]=MaxSelectedDate)
Var MaxWeek = CALCULATE(max('Date'[Week Number]),ALL('Date'))


return
calculate([Total Record Count],
FILTER(ALL('Date'),IF(SelectedWeek=1,
'Date'[Week Number]=MaxWeek && 'Date'[Year]=SelectedYear-1,
'Date'[Week Number]=SelectedWeek-1 && 'Date'[Year]=SelectedYear))
)
 
 
Last Month Count =
var MaxSelectedDate= CALCULATE( MAX ('Date'[Date]), ALLSELECTED ('Date'[Date] ))
Var SelectedMonth = CALCULATE(max('Date'[Monthnumber]),'Date'[Date]=MaxSelectedDate)
Var SelectedYear = CALCULATE(max('Date'[Year]),'Date'[Date]=MaxSelectedDate)
Var MaxMonth= CALCULATE(max('Date'[Monthnumber]),ALL('Date'))


return
CALCULATE([Total Record Count],
FILTER(ALL('Date'),IF(SelectedMonth=1,
'Date'[Monthnumber]=MaxMonth && 'Date'[Year]=SelectedYear-1,
'Date'[Monthnumber]=SelectedMonth-1 && 'Date'[Year]=SelectedYear))
)
 
It's working fine.
 
Thanks
 
Anonymous
Not applicable

Hi Amit,

 

Thank you for you reply.

I visited your blog. It's very informative but my requirement is little bit diffrent.

I got following 3 Measures. Only "Total Record Count" is working fine other 2 producting wrong result.

 

Total Record Count = COUNT(Supplier[Supplier])
 
Last Week Count =
var MaxSelectedDate= CALCULATE( MAX ( 'Date'[Date]), ALLSELECTED ( 'Date'[Date] ))
Var SelectedWeek = CALCULATE(max('Date'[Week Number]),'Date'[Date]=MaxSelectedDate)
Var SelectedYear = CALCULATE(max('Date'[Year]),'Date'[Date]=MaxSelectedDate)
Var MaxWeek = CALCULATE(max('Date'[Week Number]),ALL('Date'))


return
COUNTX(
FILTER(ALL('Date'),IF(SelectedWeek=1,
'Date'[Week Number]=MaxWeek && 'Date'[Year]=SelectedYear-1,
'Date'[Week Number]=SelectedWeek-1 && 'Date'[Year]=SelectedYear)),
[Total Record Count])
 
Last Month Count =
var MaxSelectedDate= CALCULATE( MAX ('Date'[Date]), ALLSELECTED ('Date'[Date] ))
Var SelectedMonth = CALCULATE(max('Date'[Monthnumber]),'Date'[Date]=MaxSelectedDate)
Var SelectedYear = CALCULATE(max('Date'[Year]),'Date'[Date]=MaxSelectedDate)
Var MaxMonth= CALCULATE(max('Date'[Monthnumber]),ALL('Date'))


return
COUNTX(
FILTER(ALL('Date'),IF(SelectedMonth=1,
'Date'[Monthnumber]=MaxMonth && 'Date'[Year]=SelectedYear-1,
'Date'[Week Number]=SelectedMonth-1 && 'Date'[Year]=SelectedYear)),
[Total Record Count])
Count Last week.JPG

 

 

 

Thanks

 

amitchandak
Super User
Super User

@Anonymous , Refer a my blog on Week vs Week

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.