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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.