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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
nattargekar
Regular Visitor

Compare selected mont_ year with previous month_year

Hi, I have a requirement here:

I have data like below:

Table1.JPG

 

I need the output in Power BI as:

There will be a slicer to select year. When I select Year as 18 in the slicer, it should list data only for Year 2018 where the Profit for year 2018 is compared with Profit of 2017 and added into a column. It should be seen like below:

 

Table2.JPG

 

Any Ideas?

1 ACCEPTED SOLUTION

@nattargekar

 

May be this Column

 

Column =
VAR Previous_Year =
    CALCULATE (
        SUM ( Table1[Profit] ),
        ALLEXCEPT ( Table1, Table1[Product] ),
        SAMEPERIODLASTYEAR ( Table1[Date] )
    )
RETURN
    IF ( NOT ( ISBLANK ( Previous_Year ) ), Table1[Profit] - Previous_Year )

Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

@nattargekar

 

Try this measurE

 

Measure  =
VAR Previous_Year =
    CALCULATE (
        SUM ( Table1[Profit] ),
        ALLEXCEPT ( Table1, Table1[Product] ),
        SAMEPERIODLASTYEAR ( Table1[Date] )
    )
RETURN
    SUM ( Table1[Profit] ) - Previous_Year

Regards
Zubair

Please try my custom visuals

Hi Zubair,

Your code works great for a Measure. Thanks for it. I actually need to create a new Column with these values, so that I can use the column for further calculations. Can you think of DAX to create new column for same requirement ???

@nattargekar

 

May be this Column

 

Column =
VAR Previous_Year =
    CALCULATE (
        SUM ( Table1[Profit] ),
        ALLEXCEPT ( Table1, Table1[Product] ),
        SAMEPERIODLASTYEAR ( Table1[Date] )
    )
RETURN
    IF ( NOT ( ISBLANK ( Previous_Year ) ), Table1[Profit] - Previous_Year )

Regards
Zubair

Please try my custom visuals

It's working, Thank you so much @Zubair_Muhammad !!!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors