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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Charu
Post Patron
Post Patron

DAX to get data from selected month previous year till selected current month

Dear Communtiy,

 

Please help me with the requirement below using dax

I need to show the data based on selected month.

For Example :If I select FY2020 I want the data from FY2019P08 to FY2020P08 (based ono fiscal qtr)

Below are the Sample data and the expected output

 

SalesAmount |  TimeDimDate | Fiscal Fiscal Period  | Fiscal Year

100                |  18-Jan-2019 | FY2019 P01 | FY2019

100                |  22-Feb-2019  | FY2019 P01 | FY2019

100                |  05-Mar-2019  | FY2019 P01 | FY2019

100                |  17-Apr-2019  | FY2019 P02 | FY2019

100                |  24-May-2019  | FY2019 P02 | FY2019

500                |  18-Jun-2019  | FY2019 P02 | FY2019

200                |  13-Jan-2020  | FY2019 P01 | FY2020

600                |  18-Feb-2019  | FY2019 P01 | FY2020

500                |  18-Mar-2019  | FY2019 P01 | FY2020

200                |  18-Apr-2020  | FY2019 P02 | FY2020

300                |  18-May-2020  | FY2019 P02 | FY2020

 

Expected Output : When I filter for May-2020 then the output will look like below

SalesAmount |  TimeDimDate | Fiscal Fiscal Period  | Fiscal Year

100                |  24-May-2019  | FY2019 P02 | 2019

500                |  18-Jun-2019  | FY2019 P02 | 2019

200                |  13-Jan-2020  | FY2019 P01 | 2020

600                |  18-Feb-2019  | FY2019 P01 | 2020

500                |  18-Mar-2019  | FY2019 P01 | 2020

200                |  18-Apr-2020  | FY2019 P02 | 2020

300                |  18-May-2020  | FY2019 P02 | 2020

 

Filter field would be Fiscal year

Is this possible?If so someone please help me get this.

I would be great if someone can help me as soon as possible.

 

Thanks inadvance

7 REPLIES 7
Anonymous
Not applicable

@Charu 

I met a similar question yesterday, check the sample pbix I provided from this post: 

https://community.powerbi.com/t5/Desktop/Last-12-Periods-when-Period-is-Data-type-quot-Text-quot-and...

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Charu , Try like

 

Measure =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = date(year(_max),month(_max)-12,1)
return
calculate([measure],filter(All(DATE), Date[Date] >=_min && Date[Date] <=_max))

 

You may have to use 13 in place of 12

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 
I tried your dax,unfortunately it din't give me the expected output

Hi @amitchandak 

 

Sorry slight change in the requirement
We do have Fiscal_period and  fiscal year in separate column which is FY2019 P01,FY2019 P12 and FY2020 P01 to FY2020 P12
Whether the logic you shared here will work for the filtering fiscal year 2020 then the data should populate from FY2019 P08 to FY2020 P08 (based on the fiscal qtr)

@Charu , Can use before slicer along with measure and check

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@Charu , refer if this can help

https://www.youtube.com/watch?v=duMSovyosXE

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@Charu , Or  try this approach

https://www.youtube.com/watch?v=duMSovyosXE

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.