This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreGet Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.
Hi all,
Need your assistance to find a formula to write the DAX for previous 6 months.
Between Aug 2020 to Dec 2020, there is no value.
Below screenshot of desired ouput
Regards
Hidayat
Solved! Go to Solution.
Hi @Anonymous ,
Create a Yearmonth column from the date column.
year_month = YEAR('table'[date])*100+MONTH('table'[date])Create index columns based on month and year.
month_index =
VAR MonthRow = 'table'[year_month]
RETURN
CALCULATE (
DISTINCTCOUNT ( 'table'[year_month] ),
FILTER ('table','table'[year_month] <= MonthRow )
)Create an unrelated calendar table as slicer.
Table 2 = SELECTCOLUMNS('table',"DateKey",'table'[date],"YearMonth",'table'[year_month])Create a measure and apply it to a visual level filter.
Last6Months =
//Get the year_month from the slicer
var max_date = SELECTEDVALUE('Table 2'[YearMonth])
//Get the index of year_month
var _mindex = CALCULATE(MAX('table'[month_index]),FILTER(ALL('table'),'table'[year_month]=max_date))
//Get the min year_month of the last six months
var min_date = CALCULATE(MIN('table'[year_month]),FILTER(ALL('table'),'table'[month_index]=_mindex-5))
return IF(MAX('table'[year_month])>=min_date&&MAX('table'[year_month])<=max_date,1,0)
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
Create a Yearmonth column from the date column.
year_month = YEAR('table'[date])*100+MONTH('table'[date])Create index columns based on month and year.
month_index =
VAR MonthRow = 'table'[year_month]
RETURN
CALCULATE (
DISTINCTCOUNT ( 'table'[year_month] ),
FILTER ('table','table'[year_month] <= MonthRow )
)Create an unrelated calendar table as slicer.
Table 2 = SELECTCOLUMNS('table',"DateKey",'table'[date],"YearMonth",'table'[year_month])Create a measure and apply it to a visual level filter.
Last6Months =
//Get the year_month from the slicer
var max_date = SELECTEDVALUE('Table 2'[YearMonth])
//Get the index of year_month
var _mindex = CALCULATE(MAX('table'[month_index]),FILTER(ALL('table'),'table'[year_month]=max_date))
//Get the min year_month of the last six months
var min_date = CALCULATE(MIN('table'[year_month]),FILTER(ALL('table'),'table'[month_index]=_mindex-5))
return IF(MAX('table'[year_month])>=min_date&&MAX('table'[year_month])<=max_date,1,0)
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @amitchandak ,
Not looking for average in the statement.
I would need the statement to lookup the last 6 month record.
Regards
Hidayat
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 25 | |
| 24 | |
| 22 | |
| 21 | |
| 19 |
| User | Count |
|---|---|
| 51 | |
| 48 | |
| 44 | |
| 21 | |
| 21 |