Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
Hi All,
How can i get previous month data based on selected month in DAX query?
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.
Solved! Go to Solution.
Hi @Anonymous ,
I created some data:
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:
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
Hi @Anonymous ,
I created some data:
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:
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
Hi @Anonymous ,
thanks it work but when i put 2021 data it doesn't appear.
can u advice me what i need to do?
HI, @Anonymous
Try this measure
Measure =
CALCULATE(
SUM('Table'[Value]),PREVIOUSMONTH('Dates'[Date] ))
You also need a Calendar Table
@Anonymous Hi
Do you have a relationship between the date table and the data table?
yes both table have relationship
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 10 | |
| 5 | |
| 5 |