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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Eleonora
Regular Visitor

Create a graph with last 12 months and last 24 months

Hi everyone,

 

i would like to create a graph that has as X axis the months and as values 2 lines that represent:

1- monthly number of sales of the last 12 months (from august 2021 to august 2022)

2- monthly number of sales of the last 24 months (from august 2020 to august 2021)

 

The X axis should start from august to august ideally.

 

Could you help me solve this issue?

 

Many thanks!

 

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @Eleonora ,

 

Please try following DAX:

year = FORMAT('Sheet10'[Date],"yyyy")

month = 
var _mon = FORMAT('Sheet10'[Date],"mmm")
var _aug = IF('Sheet10'[year] = "2022" && _mon = "Aug","Aug_22",_mon)
return _aug

Measure = 
var _month = SELECTEDVALUE('Sheet10'[month])
var _sort = SWITCH(_month,
           "Aug",1,
           "Sep",2,
           "Oct",3,
           "Nov",4,
           "Dec",5,
           "Jan",6,
           "Feb",7,
           "Mar",8,
           "Apr",9,
           "May",10,
           "Jun",11,
           "Jul",12,
           "Aug_22",13)
return _sort

 

Please add Measure to Tppltips:

vyadongfmsft_0-1662025603998.png

Sort axis by Measure, the X axis will start from august to august:vyadongfmsft_1-1662025740107.png

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yadongf-msft
Community Support
Community Support

Hi @Eleonora ,

 

Please try following DAX:

year = FORMAT('Sheet10'[Date],"yyyy")

month = 
var _mon = FORMAT('Sheet10'[Date],"mmm")
var _aug = IF('Sheet10'[year] = "2022" && _mon = "Aug","Aug_22",_mon)
return _aug

Measure = 
var _month = SELECTEDVALUE('Sheet10'[month])
var _sort = SWITCH(_month,
           "Aug",1,
           "Sep",2,
           "Oct",3,
           "Nov",4,
           "Dec",5,
           "Jan",6,
           "Feb",7,
           "Mar",8,
           "Apr",9,
           "May",10,
           "Jun",11,
           "Jul",12,
           "Aug_22",13)
return _sort

 

Please add Measure to Tppltips:

vyadongfmsft_0-1662025603998.png

Sort axis by Measure, the X axis will start from august to august:vyadongfmsft_1-1662025740107.png

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Eleonora
Regular Visitor

Hi @ToddChitt , thank you for your help!

I did the calculated column and I put it as legend, but the plot starts from January, and not from august.

As you suggested I put the date in the X-axis just with the month.

 

Any idea how i can make it right?

 

Thanks!

ToddChitt
Super User
Super User

You need 'seasonal' data. To get that, plot JUST the month name, properly sorted, and do a Legend by 'Plot Year'.

Your 'Plot Year' will need to start in August and end the following July.

'Plot Year' can be as simple as a calculated Column: IF (MONTH([Date]) > 6 ,  , ) 




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors