Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi experts
I have been trying and failing for a while so thought I would post here.
I am trying to compare current month to date with the 2 previous periods.
I have:
Solved! Go to Solution.
Are you comparing month by month, or are you looking at the whole year?
If you are looking at the whole year, you would have to insert additional days in you time dimension. But in doing so, I am not sure the time intelligence functions, like TOTALMTD, will work. But it is possible to recreate that with other functions.
If you comparing month by month, you can add a table with just 1 to 31 on the rows. And add a day of month-column in your date dimension as sell. And use this column on the axis, and create the measures like this
Total MTD =
VAR maxday =
MAX ( dimDate[dayofmonth] )
RETURN
IF (
SELECTEDVALUE ( Daysofmonths[dayofmonth] ) <= maxday,
CALCULATE (
SUM ( [Sales] ),
FILTER (
ALL ( Daysofmonths[dayofmonth] ),
Daysofmonths[dayofmonth] <= MIN ( Daysofmonths[dayofmonth] )
)
),
BLANK ()
)Total MTD - 1 =
VAR maxday =
CALCULATE (
MAX ( dimDate[dayofmonth] ),
FILTER ( ALL ( dimDate ), dimDate[month] = MIN ( dimDate[month] ) - 1 )
)
RETURN
IF (
MIN ( Daysofmonths[dayofmonth] ) <= maxday,
CALCULATE (
SUM ( [Sales] ),
FILTER ( ALL ( dimDate ), dimDate[month] = MIN ( dimDate[month] ) - 1 ),
FILTER (
ALL ( Daysofmonths ),
Daysofmonths[dayofmonth] <= MIN ( Daysofmonths[dayofmonth] )
)
),
BLANK ()
)
I believe I have figured it out now. Thanks, your solution got me on the way to what I needed.
I managed to do it without the need for variables (as I always want the chart to go to 31 even if both months finish before then.
Code below for anyone interested and needing the same solution
MTD = CALCULATE (TOTALMTD([Sales],DimDate[Date]),
FILTER (
ALL (Daysofmonths[dayofmonth] ),
Daysofmonths[dayofmonth] <= MIN ( Daysofmonths[dayofmonth] )
))MTD -1 = CALCULATE(TOTALMTD([Sales],DATEADD(DimDate[Date],-1,MONTH)),FILTER (
ALL ( Daysofmonths ),
Daysofmonths[dayofmonth] <= max ( Daysofmonths[dayofmonth] )))
Are you comparing month by month, or are you looking at the whole year?
If you are looking at the whole year, you would have to insert additional days in you time dimension. But in doing so, I am not sure the time intelligence functions, like TOTALMTD, will work. But it is possible to recreate that with other functions.
If you comparing month by month, you can add a table with just 1 to 31 on the rows. And add a day of month-column in your date dimension as sell. And use this column on the axis, and create the measures like this
Total MTD =
VAR maxday =
MAX ( dimDate[dayofmonth] )
RETURN
IF (
SELECTEDVALUE ( Daysofmonths[dayofmonth] ) <= maxday,
CALCULATE (
SUM ( [Sales] ),
FILTER (
ALL ( Daysofmonths[dayofmonth] ),
Daysofmonths[dayofmonth] <= MIN ( Daysofmonths[dayofmonth] )
)
),
BLANK ()
)Total MTD - 1 =
VAR maxday =
CALCULATE (
MAX ( dimDate[dayofmonth] ),
FILTER ( ALL ( dimDate ), dimDate[month] = MIN ( dimDate[month] ) - 1 )
)
RETURN
IF (
MIN ( Daysofmonths[dayofmonth] ) <= maxday,
CALCULATE (
SUM ( [Sales] ),
FILTER ( ALL ( dimDate ), dimDate[month] = MIN ( dimDate[month] ) - 1 ),
FILTER (
ALL ( Daysofmonths ),
Daysofmonths[dayofmonth] <= MIN ( Daysofmonths[dayofmonth] )
)
),
BLANK ()
)
Hi @sturlaws
Thanks for the reply but I still am having the same issue with this. I.e. if I filter by Feb, the Jan line will also stop at 28 instead of 31.
I have attached a link of what I am trying to achieve, would be great if you could have a look
Thanks in advance
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 31 | |
| 28 |
| User | Count |
|---|---|
| 129 | |
| 88 | |
| 79 | |
| 68 | |
| 63 |