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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
V-pazhen-msft
Community Support
Community Support

@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

 

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.