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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Jonathan_Richar
Frequent Visitor

Line graph (Last 12 months) with field parameter.

111122

Jonathan_Richar_0-1713893439674.png

 


Hey guys!
I hope they are well.

I would like to request your help with a DAX measurement. I tried looking online for something similar to what I need to do and I couldn't find it.

I have a field parameter that returns the name of the month or quarter depending on the selection in the filter (image 1), I need a DAX measure that returns the last 12 months, I tried several times, but I couldn't.

In image 2 it is the closest I could do, but ideally the x-axis should change to month or quarter according to the selection made in the 1st image.


Thank you for all responses.

2 REPLIES 2
amitchandak
Super User
Super User

@Jonathan_Richar , In case you select a date/month or qtr and still need 12 month on slicer, then you need one disconnected table

 

//Date1 is independent Date table, Date is joined with Table. Date 1 is used in slicer
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = eomonth(_max, -12) +1
return
calculate( sum(sales[Gross Sales]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

 

//DateInd is joined with inactive join, Date is joined with Table with Active join. and Date table is used in slicer , and Dateind is used on axis


new measure =
Var _max = Max('Date'[Date])
var _min = EOMONTH(_max, -12)+1
return
CALCULATE([Net Sales Measure],filter(ALL('Date'), 'Date'[Date]>=_min && 'Date'[Date]<=_max) ,USERELATIONSHIP('DateInd'[Date], Sales[Sales Date]))

 

or


new measure =
Var _max = Max('Date'[Date])
var _min = EOMONTH(_max, -12)+1
return
CALCULATE(sumx(Values(Date[Date]), [Net Sales Measure]) ,filter(ALL('Date'), 'Date'[Date]>=_min && 'Date'[Date]<=_max) ,USERELATIONSHIP('DateInd'[Date], Sales[Sales Date]))

 

Need of an Independent/disconnected Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

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

@amitchandak

Firstly, thank you very much for the clarification.

One question, how would it be possible for the x axis of the graph to be variable according to the type of period (Quarter or Month) chosen?

For example: If you select "month" the graph would show months (Jan, Feb...) if you select "Quarter" the graph would show (Q1, Q2....)

If possible, could you provide me with the file (.pbix) you used for the answer.

Thank you in advance for your time and knowledge.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors