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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

covid19 - dax formula for previous weekly and yearly cumulatives/running totals

hi,

ref sample file.

 

i have managed to get the dax working for the previous daily, monthly & quarterly cummulative/running totals. however, i'm having problems to get the same for previously week and yearly cummulative/running totals.

 

1st i get the sum of newcases with

SUM( 'cv19-data'[New_cases] )

 

then, for previous day, month, quarter, year calculation, i use the DATEADD function such as

CALCULATE ( [NewCases], DATEADD ( 'Calendar'[Date], -1, DAY ) )
or
CALCULATE ( [NewCases], DATEADD ( 'Calendar'[Date], -1, MONTH ) )
or
CALCULATE ( [NewCases], DATEADD ( 'Calendar'[Date], -1, QUARTER ) )
or
CALCULATE ( [NewCases], DATEADD ( 'Calendar'[Date], -1, YEAR ) )

 

for previous week, i use

VAR CurrentWeek = SELECTEDVALUE( 'Calendar'[WeekNo] )

VAR
CurrentYear = SELECTEDVALUE( 'Calendar'[Year] )

VAR
MaxWeekNo = CALCULATE( MAX ( 'Calendar'[WeekNo] ), ALL ( 'Calendar' ) )

RETURN

SUMX
( FILTER( ALL ( 'Calendar' ),
IF ( CurrentWeek = 1, 'Calendar'[WeekNo] = MaxWeekNo
&& 'Calendar'[Year] = CurrentYear -
1,
'Calendar'[WeekNo] = CurrentWeek -
1
&& 'Calendar'[Year] = CurrentYear
)
),
[NewCases]
)

 

for the cummulative/running totals calculations, i have no issues with the previous day, previous month, & previous quarter. i need help to find the cummulative/running totals for previous week and previous year.


thanks in advance for any help.

krgds, -nik

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Ideally this formula should work as cumulative for day week and month etc

 

Cumm Sales = CALCULATE([new case], filter(allselected(Calendar),Calendar[date] <=max(Calendar[Date])))

 

 

Use week rank as a new column and use that for week related stuff

 

new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

measures
This Week = CALCULATE([new cases], FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE([new cases], FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Cumm Week = CALCULATE([new cases], FILTER(ALL('Date'),'Date'[Week Rank] <=max('Date'[Week Rank])))

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Ideally this formula should work as cumulative for day week and month etc

 

Cumm Sales = CALCULATE([new case], filter(allselected(Calendar),Calendar[date] <=max(Calendar[Date])))

 

 

Use week rank as a new column and use that for week related stuff

 

new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

measures
This Week = CALCULATE([new cases], FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE([new cases], FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Cumm Week = CALCULATE([new cases], FILTER(ALL('Date'),'Date'[Week Rank] <=max('Date'[Week Rank])))

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

tks again, @amitchandak.

i hv also managed to find week-over-week calc.

krgds, -nik

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.