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
AshDil
Helper V
Helper V

Subtract one Category value from Other Category

Hi,

 

I have data as follows

CATEGORYMonthSALESTARGET
AEMarch$180,000$200,000
AEApril$80,000$80,000
AEMay$100,000$120,000
BEMarch$210,000$220,000
BEApril$280,000$165,000
BEMay$180,000$200,000
NAMarch$25,000$25,000
NAApril$10,000$10,000
NAMay$20,000$20,000
UNMarch$30,000$30,000
UNApril$30,000$30,000
UNMay$30,000$30,000

 

I want output as follows:

AshDil_0-1646885803995.png

For MAR

AE,

Sales = 1,80,000 and Target = 2,00,000

NA,

Sales = 25000 and target = 25000

Now I want to subtract 'NA' sale value from 'AE' sale value same with Target.

i.e, 1,80,000 - 25,000 = 1,55,000

Please help me to do it.

Thanks,

AshDil

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

Hi @AshDil ,

According to your description, here's my solution.

Here's my sample data.

vkalyjmsft_0-1647335024632.png

1. In Power Query, select Unpivot Columns, get this table:

vkalyjmsft_1-1647335091201.png

2. Create a measure.

Measure =
IF (
    MAX ( 'Table'[CATEGORY] ) = "AE",
    MAX ( 'Table'[Value] )
        - MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[CATEGORY] = "NA"
                    && 'Table'[Month] = MAX ( 'Table'[Month] )
                    && 'Table'[Attribute] = MAX ( 'Table'[Attribute] )
            ),
            'Table'[Value]
        ),
    MAX ( 'Table'[Value] )
)

Put the measure in the matrix, get the result.

vkalyjmsft_2-1647335248387.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

View solution in original post

3 REPLIES 3
v-yanjiang-msft
Community Support
Community Support

Hi @AshDil ,

According to your description, here's my solution.

Here's my sample data.

vkalyjmsft_0-1647335024632.png

1. In Power Query, select Unpivot Columns, get this table:

vkalyjmsft_1-1647335091201.png

2. Create a measure.

Measure =
IF (
    MAX ( 'Table'[CATEGORY] ) = "AE",
    MAX ( 'Table'[Value] )
        - MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[CATEGORY] = "NA"
                    && 'Table'[Month] = MAX ( 'Table'[Month] )
                    && 'Table'[Attribute] = MAX ( 'Table'[Attribute] )
            ),
            'Table'[Value]
        ),
    MAX ( 'Table'[Value] )
)

Put the measure in the matrix, get the result.

vkalyjmsft_2-1647335248387.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

amitchandak
Super User
Super User

@AshDil , You need to create measure like

 

calculate(sum(Table[Sales]), filter(all(Table[Category]), Table[Category] ="Na"))

 

or

 

calculate(sum(Table[Target]), filter(all(Table[Category]), Table[Category] ="AE"))

Hi @amitchandak ,

 

With the above measures I can not show my expected output

AshDil_0-1646965640555.png

Please help me to do it.

Thanks,

AshDil.

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.