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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Simple way to find data from previous month without creating a DATA table

Hey Guys. 

Right now I am attempting to compare the current month with the previous 

 

I have variable called MonthlyCount and a month variable called "Month".

Through DAX i could easily extract the data belonning to the current month:

 

CALCULATE(SUM('CountTable'[TotalCountPerMonth]),('CountTable'[Month])=MONTH(TODAY()))
 
Now I want to ask how can I do the same with the previous month? I have seen many suggestion and attempts where people create local DATA tables which I really dont want to for practical reasons. Is there a way of extracing the previous month's data with (-1) of currentmonth fx? 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I found a fix!

 

CALCULATE(SUM('CountTable'[Counts]),('CountTable'[Month])=MONTH(TODAY())-1)
This DAX measure will take the total values filtering the previous MONTH!
And thus I also can avoid using the DATE Table

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous ,Prefer to use time intelligence with date table.

 

Example

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]))
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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

Appreciate your Kudos.

Anonymous
Not applicable

@amitchandak 

 

I added a Calender/Data table and tried all your measures, but I still dont seem to be getting the correct data from previous month. I get a far higher value when using; 

previous month value = CALCULATE(sum(''Table''[total hours value]),previousmonth('Date'[Date]))

 

Anonymous
Not applicable

I found a fix!

 

CALCULATE(SUM('CountTable'[Counts]),('CountTable'[Month])=MONTH(TODAY())-1)
This DAX measure will take the total values filtering the previous MONTH!
And thus I also can avoid using the DATE Table

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors