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

Get the column difference after filter selection

Hello Everyone

 

I need the DAX measure expression for the below scenario.

 

For my table Sales, I have 4 columns-Quateryear, SalesAmount-A, SalesAmount-B,Place.

 

Both the  column values of SalesAmount-A and  SalesAmount-B are same and they have  filters A and filter B applied on SalesAmount-A and  SalesAmount-B respectively. filter A and filter B has Quateryear values.

 

so as per my requirement if I select any quateryear value in filterA, it should filter and sum the Sales AmountA  and if it select any quateryear value in filter B, it should filter and sum the SalesAmountB. Based on these filtered values selection, I should get the difference between SalesAmount -A and Sales Amount-B columns in the DifferenceSales

 

P.S: Here the column values for SalesAmount-A, SalesAmount-B are the same/you can say duplicate column. The filters too refers to the same column quateryear.

 

I wrote a measure to handle this but it is not working.

 

Could someone suggest some changes.

 

SalesAmount difference from Q12017, Q22017, Q32017, or Q42017 =
VAR __SALES_AMOUNTA =
    CALCULATE(
        SUM('Sales'[SalesAmount-A]),
        'Sales'[QuaterYear]
            IN { "Q12017", "Q22017", "Q32017", "Q42017" }
    )
VAR __SALES_AMOUNTB =
    CALCULATE(
        SUM('Sales'[SalesAmount-B]),
        'Sales'[QuaterYear]
            IN { "Q12017", "Q22017", "Q32017", "Q42017" }
    )
RETURN
    IF(NOT ISBLANK(__SALES_AMOUNTA), __SALES_AMOUNTB - __SALES_AMOUNTA)
 
SOURCE INPUT:excel
QuaterYearSalesAmount-ASalesAmount-BPlaceDifferenceSales
Q1201710001000London 
Q1201711001100London 
Q1201711201120London 
Q12017900900Tokyo 
Q2201722002200Tokyo 
Q2201721002100Tokyo 
Q2201710001000Tokyo 
Q22017500500Tokyo 
Q2201719001900Tokyo 
Q2201719001900Tokyo 
Q2201720002000Tokyo 
Q2201740004000Tokyo 
Q2201721002100Tokyo 
Q3201711001100Kaula Lampur 
Q32017890890Kaula Lampur 
Q4201722002200Berlin 
Q4201723002300Berlin 
Q4201729002900Berlin 

 

 

Expected Output in PowerBI should look like this:[Just for look and feel I made a similar in excel as below]

 

1.JPG

My Sales Matrix table visualization :school.JPG

1 REPLY 1
lbendlin
Super User
Super User

Where is the Tokyo value for Q12017?

 

You probably need to duplicate your data table, and use one copy for the A filter and the other copy for the B filter. Then use a measure to calculate the difference between the selected items. You will need to lower your expectations on the output format, it is not possible to implement it exactly as in your example.

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.