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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

Compare last year vs current year (months) on same visual

Hey everyone! I could use some guidance on how to create a visual that is able to show each month (last year vs current year) side by side on a stacked or clusterted bar chart. 

 

Desired Result:

currentchart.PNG

 

2019 March

2020 March 

 

2019 April

2020 April 

 

2019 May

2020 May

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Use if statement to make conditional judgment and calculate data of each month.

Measure =
IF (
    (
        YEAR ( MAX ( 'Table'[Date] ) ) = YEAR ( TODAY () )
            || YEAR ( MAX ( 'Table'[Date] ) )
                = YEAR ( TODAY () ) - 1
    )
        && MONTH ( MAX ( 'Table'[Date] ) ) <= MONTH ( TODAY () )
        && MONTH ( MAX ( 'Table'[Date] ) ) >= 3,
    SUM ( 'Table'[Sales] )
)

test_Compare last year vs current year (months) on same visual.PNG

Sample .pbix

 

Best Regards,
Liang
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

4 REPLIES 4
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Use if statement to make conditional judgment and calculate data of each month.

Measure =
IF (
    (
        YEAR ( MAX ( 'Table'[Date] ) ) = YEAR ( TODAY () )
            || YEAR ( MAX ( 'Table'[Date] ) )
                = YEAR ( TODAY () ) - 1
    )
        && MONTH ( MAX ( 'Table'[Date] ) ) <= MONTH ( TODAY () )
        && MONTH ( MAX ( 'Table'[Date] ) ) >= 3,
    SUM ( 'Table'[Sales] )
)

test_Compare last year vs current year (months) on same visual.PNG

Sample .pbix

 

Best Regards,
Liang
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

@Anonymous , You use last year trailing measure or datesmtd 1 year behind. All that with a date table. Move your mon-year in that table

 

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
last year MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak thanks for the quick response!

 

I used the both formulas you provided but I am only seeing 2020, not both 2019/2020 side by side. 

 

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
last year MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))

 

chart.PNGchart2.PNG

 

 

 

nandukrishnavs
Super User
Super User

@Anonymous 

 

Refer to this https://databear.com/power-bi-dax-sameperiodlastyear-paralellperiod-and-dateadd/

 



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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