Forum Discussion
need help on dax code rolling MTD value
Hi,
Need help on getting rolling MTD value.
I have the source data attached here, need to filter only the DayName(Date) = Monday, the data is avliable on weekly.
Need output for WeekValue, RollingWeekValue, Month-to-date for the selected week, and Rolling Month-to-Date.
Here am unable to acheive to get Rolling Month-to-Date.
Need help on code for get rolling MTD value based on MTD column.
Rolling Week Value =
CALCULATE (
[Value],
FILTER (
ALLSELECTED ( 'Date' ),
'Date'[Date] <= MAX ( 'Date'[Date] )
)
)
MTD Value = CALCULATE(SUM(Value),'Date'[FiscalYear] = SELECTEDVALUE('Date'[FiscalYear]),'Date'[FiscalMonthNumber]=SELECTEDVALUE('Date'[FiscalMonthNumber]),'Date'[Date]<=SELECTEDVALUE('Date'[FiscalWeekEnd]))
Need output to get Rolling MTD value highlighted below.
| Date | Day | Value |
| 28-04-2025 00:00 | Mon | 804.28 |
| 05-05-2025 00:00 | Mon | 2937.27 |
| 12-05-2025 00:00 | Mon | 1057.96 |
| 19-05-2025 00:00 | Mon | 1714.2 |
| 26-05-2025 00:00 | Mon | 5802.43 |
| 27-05-2025 00:00 | Tue | 43.53 |
| 28-05-2025 00:00 | Wed | 2334.93 |
| 29-05-2025 00:00 | Thu | 172.35 |
| 30-05-2025 00:00 | Fri | 42.99 |
| 31-05-2025 00:00 | Sat | 3118 |
| 02-06-2025 00:00 | Mon | 2834.43 |
| 09-06-2025 00:00 | Mon | 1295.66 |
| 16-06-2025 00:00 | Mon | 4455.44 |
| 23-06-2025 00:00 | Mon | 1981.1 |
| 24-06-2025 00:00 | Tue | 4453.32 |
| 25-06-2025 00:00 | Wed | 985.11 |
| 26-06-2025 00:00 | Thu | 732.95 |
| 27-06-2025 00:00 | Fri | 509.76 |
| 28-06-2025 00:00 | Sat | -275.61 |
| 29-06-2025 00:00 | Sun | -5500 |
| 30-06-2025 00:00 | Mon | 186.43 |
| 07-07-2025 00:00 | Mon | 2602.33 |
| 14-07-2025 00:00 | Mon | 1482.63 |
Hi again,
now this result
It matches yours apart from Fiscal week 4, but I think the above value is the correct one, am I right? Your value is 11,313
Code
Rolling MTD =VAR MaxDate = MAX ( 'Date'[Date] )VAR MaxMonth = MAX ( 'Date'[FiscalMonthFullName] )VAR DatesToConsider =ADDCOLUMNS(CALCULATETABLE (VALUES ( 'Date'[Date] ),'Date'[Date] <= MaxDate,'Date'[FiscalMonthFullName] = MaxMonth,REMOVEFILTERS( 'Date' )),"@ROLL", IF ( NOT ISEMPTY( CALCULATETABLE('Fact') ), [Rolling WeekValue] ))RETURNIF (NOT ISEMPTY ( Fact ) && ISINSCOPE( 'Date'[Date] ),SUMX (DatesToConsider,[@ROLL]))File attached
If this helped, please consider giving kudos and mark as a solution
me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
HI SP_1
modified the code accordingly. File attached
Best
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Hi FBergamaschi ,
Thanks for you help and its working.
7 Replies
- FBergamaschiSuper User
Hi SP_1
I could not replicate what you ask because I would need the association of your fiscal months to the dates which you did not provideI obtained this
with this code (I created a 'Date' table )
Rolling MTD =VAR MaxDate =MAX ( 'Date'[Date] )VAR MaxYear = YEAR ( MaxDate )VAR MaxMonth = MONTH ( MaxDate )RETURNIF (NOT ISEMPTY ( Facts ) && ISINSCOPE( 'Date'[Date] ),SUMX (CALCULATETABLE (VALUES ( 'Date'[Date] ),'Date'[Date] <= MaxDate,YEAR ( 'Date'[Date] ) = MaxYear,MONTH( 'Date'[Date] ) = MaxMonth),[Rolling Week Value]))I think it should work when you slice data with your calendar where you have the link between dates and fiscal monthsLet me know if this works or I shall fix it if you send me your calendar tooFile attachedIf this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your threadWant to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
- SP_1Frequent Visitor
Hi FBergamaschi ,
Thank you for your help. However, the output does not match my expectations. Please refer to the attached sample file (link below). Thanks in advance.
https://www.dropbox.com/scl/fi/4tnlqv4re2rm9y9kpcpnx/Rolling-MTD.pbix?rlkey=nw1kd122d5fw6bbeo28zdbn3y&st=wr48l1tm&dl=0
I expect the output to match the highlighted (Yellow) result.- FBergamaschiSuper User
Hi again,
now this result
It matches yours apart from Fiscal week 4, but I think the above value is the correct one, am I right? Your value is 11,313
Code
Rolling MTD =VAR MaxDate = MAX ( 'Date'[Date] )VAR MaxMonth = MAX ( 'Date'[FiscalMonthFullName] )VAR DatesToConsider =ADDCOLUMNS(CALCULATETABLE (VALUES ( 'Date'[Date] ),'Date'[Date] <= MaxDate,'Date'[FiscalMonthFullName] = MaxMonth,REMOVEFILTERS( 'Date' )),"@ROLL", IF ( NOT ISEMPTY( CALCULATETABLE('Fact') ), [Rolling WeekValue] ))RETURNIF (NOT ISEMPTY ( Fact ) && ISINSCOPE( 'Date'[Date] ),SUMX (DatesToConsider,[@ROLL]))File attached
If this helped, please consider giving kudos and mark as a solution
me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI