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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Kadrimedquali
Helper I
Helper I

Calculate difference between two values in same column

hello,

 

i have a table and i wante te calculate the difference between tow date 

 

C20-21 = 2020 

C21-22 = 2021

 

Capture d’écran (349).png

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Kadrimedquali 

 

I have simply simulated some data that I hope fits your situation, and you can try the following methods.

vzhangti_0-1655175516473.png

Measure =
IF (
    HASONEVALUE ( 'Table'[Year] ),
    SUM ( 'Table'[Value] ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            [Year] = 2021
                && [Category] = SELECTEDVALUE ( 'Table'[Category] )
        )
    )
        - CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALL ( 'Table' ),
                [Year] = 2020
                    && [Category] = SELECTEDVALUE ( 'Table'[Category] )
            )
        )
)

Change the name of the column Total to Difference. The results are shown in the figure.

vzhangti_2-1655175864482.png     vzhangti_1-1655175698659.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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-zhangti
Community Support
Community Support

Hi, @Kadrimedquali 

 

I have simply simulated some data that I hope fits your situation, and you can try the following methods.

vzhangti_0-1655175516473.png

Measure =
IF (
    HASONEVALUE ( 'Table'[Year] ),
    SUM ( 'Table'[Value] ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            [Year] = 2021
                && [Category] = SELECTEDVALUE ( 'Table'[Category] )
        )
    )
        - CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALL ( 'Table' ),
                [Year] = 2020
                    && [Category] = SELECTEDVALUE ( 'Table'[Category] )
            )
        )
)

Change the name of the column Total to Difference. The results are shown in the figure.

vzhangti_2-1655175864482.png     vzhangti_1-1655175698659.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

d_rohlfs
Resolver I
Resolver I

In this you can just use a measure. The DAX would look like this. 

Difference = SUM('Table'[C20-21]) - SUM('Table'[C21-22])

Then you would just put this measure into your values for your matrix. (Or columns for a table).

Kadrimedquali
Helper I
Helper I

i need your help 

thanks

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.