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
OsamaAhmed
Regular Visitor

How to Calculate Profit in current year vs previous year

Hello Everyone, 

I am currently working on developing a dashboard, and I have been trying to calculate the Gross Profit for 2022( Jan-now) vs. the Gross Profit of 2021(Jan-Dec). I have used the following equations to get the right answers: GP 2021 = Calculate([GP Total], Value('Date'[Date]) = 2021), and so for 2022. But I want this to be dynamic. Meaning that when next year comes, the dashboard will show 2022 vs. 2023. I also tried using the Year function: YEAR(TODAY()), but I still hit a roadblock. Your help and guidance are much appreciated and thanks in advance. 

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

Hi @OsamaAhmed ,

Please have a try.

Create a measure.

measure =
VAR _2021 =
    CALCULATE (
        SUM ( 'Date'[sales] ),
        FILTER ( ALL ( 'date' ), YEAR ( 'date'[date] ) = 2021 )
    )
VAR _2022 =
    CALCULATE (
        SUM ( 'Date'[sales] ),
        FILTER (
            ALL ( 'date' ),
            YEAR ( 'date'[date] ) = 2022
                && 'Date'[date] <= TODAY ()
        )
    )
RETURN
    IF (
        YEAR ( MAX ( 'Date'[date] ) ) = 2021,
        _2021,
        IF ( YEAR ( MAX ( 'Date'[date] ) ) = 2022, _2022, BLANK () )
    )

If I have misunderstood your meaning, please provide more details with your desired output and your pbix file without privacy information.

 

Best Regards

Community Support Team _ Polly

 

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-rongtiep-msft
Community Support
Community Support

Hi @OsamaAhmed ,

Please have a try.

Create a measure.

measure =
VAR _2021 =
    CALCULATE (
        SUM ( 'Date'[sales] ),
        FILTER ( ALL ( 'date' ), YEAR ( 'date'[date] ) = 2021 )
    )
VAR _2022 =
    CALCULATE (
        SUM ( 'Date'[sales] ),
        FILTER (
            ALL ( 'date' ),
            YEAR ( 'date'[date] ) = 2022
                && 'Date'[date] <= TODAY ()
        )
    )
RETURN
    IF (
        YEAR ( MAX ( 'Date'[date] ) ) = 2021,
        _2021,
        IF ( YEAR ( MAX ( 'Date'[date] ) ) = 2022, _2022, BLANK () )
    )

If I have misunderstood your meaning, please provide more details with your desired output and your pbix file without privacy information.

 

Best Regards

Community Support Team _ Polly

 

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

Thank you @v-rongtiep-msft, your answer has helped me achieving my desired output

MahyarTF
Memorable Member
Memorable Member

Hi,

if you have a column that included the Year in your data, just create the sum([GP Total]) measure and then use it in your visual with the Year column :

MahyarTF_0-1661580757984.png

Appreciate your Kudos

Mahyartf
Jihwan_Kim
Super User
Super User

Hi,

If you want to compare the current year's number (even if it is not a full complete year) VS. last full year's number, please try to use the below DAX function. One of ways to achieve this is to use PARALLELPERIOD function.

 

https://docs.microsoft.com/en-us/dax/parallelperiod-function-dax

 

I hope this helps to provide some ideas on how to create a solution for your dataset.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.