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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
L_K_
Helper I
Helper I

Dax measure to subtract one value from another without changing other values

Hello!

I need some help with displaying my data in the matrix.

I want to create a dax measure to subtract one value from another without changing other values as shown in the added picture.

CHANGE ONE VALUE IN MATRIX.png

I have an idea how the dax should be constructed but I can’t figure it out, so every help would be very appreciated.

1 ACCEPTED SOLUTION

@L_K_ 
Ok please try

TEST3 =
SUMX (
    CROSSJOIN (
        VALUES ( 'Date'[Year] ),
        SUMMARIZE ( Table1, Table1[Group], Table1[Name] )
    ),
    CALCULATE (
        VAR CurrentValue =
            CALCULATE (
                SUM ( Table2[Value] ),
                'Date'[Month] = SELECTEDVALUE ( 'Date'[Month] )
            )
        VAR Value40R =
            CALCULATE (
                SUM ( Table2[Value] ),
                Table1[Name] = "00040 R",
                ALL ( Table1 ),
                'Date'[Month] = SELECTEDVALUE ( 'Date'[Month] )
            )
        RETURN
            IF (
                SELECTEDVALUE ( Table1[Name] ) = "00001 P",
                CurrentValue - Value40R,
                CurrentValue
            )
    )
)

View solution in original post

14 REPLIES 14
tamerj1
Super User
Super User

Hi @L_K_ 
You can use something like

Wanted Result =
SUMX (
    SUMMARIZE ( TableName, TableName[Grooup], TableName[ColumnName] ),
    CALCULATE (
        VAR CurrentValue =
            SUM ( TableName[Value] )
        VAR Value40R =
            CALCULATE ( SUM ( TableName[Value] ), TableName[ColumnName] = "00040 R" )
        RETURN
            IF (
                SELECTEDVALUE ( TableName[ColumnName] ) = "00001 P",
                CurrentValue - Value40R,
                CurrentValue
            )
    )
)

Thank you for your help, but I'm not getting the right numbers.

@L_K_ 
What is value? Is it a measure or a summarized column? I also see year at the left top corner. Are you slicing also by year? From which table? Please provide more context with some screeshots for better undertanding. Also please provide a screenshot of you are getting now and what are you expecting to see.

Hello @tamerj1 ,

I'm sorry but I don't know how to mask so much data to show you everything. The groups and names are in a different table than the values, they are connected by an ID and the values in the matrix are a measure. The measure has a bunch of filters and everything is also filtered by year and month from a date table.

I thought about making a measure that gives every group name value the number value of 00040 R, and then make an if statement that when the name is 00001 P it subtracts the 00040 R value if true, and if false it gives the original numbers. But I don’t know how to give every name the same value. If it makes sense.

I’m sorry I can’t provide you with all the information and I am really thankful for your response.

@L_K_ 

Are groups and Names in the same table? What are the relationships between the tables?

@tamerj1 

 

The tables kind of look like this

example tables.png

 

Table 1 - one to many * Table 2

Date table - one to many * Table 2

Hi @L_K_ 

please try

Wanted Result =
SUMX (
    CROSSJOIN (
        VALUES ( DateTable[Year] ),
        SUMMARIZE ( Table1, Table1[Group], Table1[Name] )
    ),
    CALCULATE (
        VAR CurrentValue =
            SUM ( Table2[Value] )
        VAR Value40R =
            CALCULATE (
                SUM ( Table2[Value] ),
                Table1[Name] = "00040 R",
                ALL ( Table1[Group] )
            )
        RETURN
            IF (
                SELECTEDVALUE ( TableName[ColumnName] ) = "00001 P",
                CurrentValue - Value40R,
                CurrentValue
            )
    )
)

Hello, @tamerj1 

 

Sorry for my late reply. The sum value is now correct, it subtracts the value correctly and displays the right amount, but the displayed value for 0001 P is not changed.

Hi @L_K_ 
Would you please share a screanshot of the results you are getting as well as the code you have used?

TEST3 =

SUMX (

    CROSSJOIN (

        VALUES ( 'Date'[Year] ),

        SUMMARIZE (Table1,Table1[Group],Table1[Name] )

    ),

    CALCULATE (

        VAR CurrentValue =

            CALCULATE(SUM(Table2[Value]),'Date'[Month]=SELECTEDVALUE('Date'[Month]))

        VAR Value40R =

            CALCULATE (

                SUM ( Table2[Value] ),

                Table1[Name] = "00040 R",

                ALL ( Table1[Group] ) ,'Date'[Month]=SELECTEDVALUE('Date'[Month])

            )

        RETURN

            IF (

                SELECTEDVALUE ( Table1[Name] ) = "00001 P",

                CurrentValue - Value40R,

                CurrentValue

            )

    )

)

TEST1.png

@L_K_ 
please try measure

SELECTEDVALUE ( Table1[Name] )

please let me know what you get

The names (text) inside the group, like: 00002 O, 00003 D, 00040 R, 0001 P...

@L_K_ 
Ok please try

TEST3 =
SUMX (
    CROSSJOIN (
        VALUES ( 'Date'[Year] ),
        SUMMARIZE ( Table1, Table1[Group], Table1[Name] )
    ),
    CALCULATE (
        VAR CurrentValue =
            CALCULATE (
                SUM ( Table2[Value] ),
                'Date'[Month] = SELECTEDVALUE ( 'Date'[Month] )
            )
        VAR Value40R =
            CALCULATE (
                SUM ( Table2[Value] ),
                Table1[Name] = "00040 R",
                ALL ( Table1 ),
                'Date'[Month] = SELECTEDVALUE ( 'Date'[Month] )
            )
        RETURN
            IF (
                SELECTEDVALUE ( Table1[Name] ) = "00001 P",
                CurrentValue - Value40R,
                CurrentValue
            )
    )
)

This works perfectly!

Thank you so so so much @tamerj1  for your time and help!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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