The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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