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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
FredLEGUEN
Helper III
Helper III

DAX What's wrong with my measure to return the value of the previous month

Hi Group,

 

I have created a dashboard to follow the Covid19 in France.

I never had issues with my measure but today, I have noticed a problem with the result of my measure to return the value of the previous month.

Here is my measure to return the number of deaths 1 month ago
DeathM-1 = CALCULATE([DCLast],DATEADD(TimeTable[Date],-1,MONTH))
2020-11-03_21-17-18.png
But the result is impossible. You can't have more deaths 7 days ago (24156) compare to 1 month ago (25113)
 
But if I replace my original measure by this one, the result is better
DeathD-30 = CALCULATE([DCLast],DATEADD(TimeTable[Date],-30,DAY))
2020-11-03_21-34-35.png
 

I never had problem with my original measure. 

Do you have an idea why suddenly, the result is wrong?

 

6 REPLIES 6
Anonymous
Not applicable

Hello @FredLEGUEN

In additon to think DATEADD(TimeTable[Date],-1,MONTH) will return at the end of last month.

So 25113 is the sum of death from the start date to 2020/10/31.

I build a sample table for you to test.

1.png

The result of your measurement will return to 31, which is the sum from the start date to the end of October.

2.png

You can test my measurement:

DeathM-1 = 
CALCULATE([DCLast],FILTER(TimeTable,TimeTable[Date]<= EOMONTH(TODAY(),-2)+DAY(TODAY())))

The result will be back to 6 which is added from 2020/10/01 to 2020/11/06(Today) - 31(Oct has 31 Days).

3.png

You can download the pbix file from this link: DAX What's wrong with my measure to return the previous month's value

Best regards

Rico Zhou

If this post helps,then consider Accepting it as the solution to help other members find it faster.

HotChilli
Super User
Super User

Why do you say 'Of course not'?  You posted the issue yesterday(Nov 3rd).  It looks entirely plausible that 25113 is the value at the end of October.

What I'm saying is - the measure appears to have given you the value for the end of October when you wanted a value from around Oct 3rd.  Perhaps you could check the data by getting the value for the end of Oct with a different measure.  We can then investigate what's going wrong with the original measure. 

Hi @HotChilli 

I have send you a private message

 

HotChilli
Super User
Super User

Is it possible that 25113 is the value of the measure DCLast at the end of October (the previous month)? 

 

Hi @HotChilli 

Of course not, and this is why I have immediately noticed a problem

 

@amitchandak 

Thanks for your ideas of measures but even I follow your explanation, I still don't have the correct value.

 

First, I have suppected a problem with my time table but if it was the case, the measure with -30 days won't return the result. 

So here, I really don't understand what's wrong with the measure.

amitchandak
Super User
Super User

@FredLEGUEN , Try a measure like

 

DeathM-1 = CALCULATE([DCLast],datesmtd(DATEADD(TimeTable[Date],-1,MONTH)))

 

also prefer to use date table in all such case, refer examples

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
this month =MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH('Date'[Date])))
last MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
previous month value = CALCULATE(sum(''Table''[total hours value]),previousmonth('Date'[Date]))

diff = [MTD Sales]-[last MTD Sales]
diff % = divide([MTD Sales]-[last MTD Sales],[last MTD Sales])

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors