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
Anonymous
Not applicable

calculate previous month based on selected month in DAX

Hi All,

How can i get previous month data based on selected month in DAX query?

aqil1995_0-1639565134650.png

tower value = feb 2020 data.
tower previous = previous month data (jan 2020).

For example i selected feb 2020 and i want jan 2020 data also but cant figure out how to calculate in DAX.
Here my table for reference.

aqil1995_1-1639565329693.png

 



1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1639986885737.png

Here are the steps you can follow:

1. Create calculated column.

Month_m = MONTH('Table'[Month])
MonthYear =
FORMAT('Table'[Month],"mmm")&" "&RIGHT('Table'[Month],2)

2. Create measure.

Tower Previous =
VAR _MONTH=SELECTEDVALUE('Table'[MonthYear])
VAR _Attribute=SELECTEDVALUE('Table'[Attrubute])
var _last=MAXX(FILTER(ALL('Table'),'Table'[MonthYear]=_MONTH),'Table'[Month_m]) -1
return
CALCULATE(SUM('Table'[Tower Value]),FILTER(ALL('Table'),
'Table'[Month_m]=_last&&'Table'[Attrubute]=_Attribute&&'Table'[Category]=MAX('Table'[Category])))

3. Result:

vyangliumsft_1-1639986885740.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1639986885737.png

Here are the steps you can follow:

1. Create calculated column.

Month_m = MONTH('Table'[Month])
MonthYear =
FORMAT('Table'[Month],"mmm")&" "&RIGHT('Table'[Month],2)

2. Create measure.

Tower Previous =
VAR _MONTH=SELECTEDVALUE('Table'[MonthYear])
VAR _Attribute=SELECTEDVALUE('Table'[Attrubute])
var _last=MAXX(FILTER(ALL('Table'),'Table'[MonthYear]=_MONTH),'Table'[Month_m]) -1
return
CALCULATE(SUM('Table'[Tower Value]),FILTER(ALL('Table'),
'Table'[Month_m]=_last&&'Table'[Attrubute]=_Attribute&&'Table'[Category]=MAX('Table'[Category])))

3. Result:

vyangliumsft_1-1639986885740.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Anonymous
Not applicable

Hi @Anonymous ,
thanks it work but when i put 2021 data it doesn't appear.
can u advice me what i need to do?

aqil1995_0-1641874603594.png

 

DimaMD
Solution Sage
Solution Sage

HI, @Anonymous 
Try this measure

 

Measure = 
CALCULATE(
    SUM('Table'[Value]),PREVIOUSMONTH('Dates'[Date] ))

 

Screenshot_16.jpg

You also need a Calendar Table




__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
Anonymous
Not applicable

Hi @DimaMD ,

i try that measure but the data dont show up

aqil1995_0-1639624864886.png

 

thanks.

@Anonymous Hi
Do you have a relationship between the date table and the data table?


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
Anonymous
Not applicable

yes both table have relationship

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.