Forum Discussion

sirgseymour's avatar
sirgseymour
Helper I
7 years ago
Solved

Calculating Difference between data in a table with two seperate ID keys

I am trying to compare portfolio data that exists in a single table. For Example, I have the data for two Portfolios containing losses in the same table. I have created two Tables in the Power BI UI and want to create a third that shows the difference between the two. What I want to do is do the calculation:

 

Difference= (Sum Aggregate values where PortfolioID=1) - (Sum Aggregate values where PortfolioID=2)

 

I need to be able to select the Portfolio ID's from slicers to see each of the portfolios in the two tables... Any ideas Thanks

7 Replies

  • I am trying to compare portfolio data that exists in a single table. For Example, I have the data for two Portfolios containing losses in the same table. I have created two Tables in the Power BI UI and want to create a third that shows the difference between the two. What I want to do is do the calculation:

     

    Difference= (Sum Aggregate values where PortfolioID=1) - (Sum Aggregate values where PortfolioID=2)

     

    I need to be able to select the Portfolio ID's from slicers to see each of the portfolios in the two tables... Any ideas Thanks

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Tough to be specific without sample data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

     

    That being said, you could create a measure that starts with two VAR's that do a MIN and MAX of your slicer. You could then use that to calculate your difference by filtering based upon your variables.

     

    Again, tough to be specific here.

    • sirgseymour's avatar
      sirgseymour
      Helper I

      Thank you for getting back to me. Here is an example that i have put together to give you an idea of what I am looking to do. In the example below I have included a Data ttable (SQL Table) and the three tables I want to show inthe UI. What I want to be able to do is select the individual Portfolios in the slicers and then subtract the aggregated data from the individual tables.

       

      Data Table  
         
      PortfolioCountryAggregate Loss
      Portfolio 1Argentina         50,000,000
      Portfolio 1US         50,000,000
      Portfolio 1UK         50,000,000
      Portfolio 1Germany         50,000,000
      Portfolio 1Argentina         60,000,000
      Portfolio 1US         60,000,000
      Portfolio 1UK         60,000,000
      Portfolio 1Germany         60,000,000
      Portfolio 2Argentina         80,000,000
      Portfolio 2US         80,000,000
      Portfolio 2UK         80,000,000
      Portfolio 2Germany         80,000,000
      Portfolio 2Argentina       110,000,000
      Portfolio 2US       110,000,000
      Portfolio 2UK       110,000,000
      Portfolio 2Germany       110,000,000
         
         
      Power BI Visual 
         
       Portfolio 1 (Slicer)
        
         
      CountryAggregate Loss 
      Argentina       110,000,000 
      US       110,000,000 
      UK       110,000,000 
      Germany       110,000,000 
         
       Portfolio 2 (Slicer)
        
         
      CountryAggregate Loss 
      Argentina       190,000,000 
      US       190,000,000 
      UK       190,000,000 
      Germany       190,000,000 
         
      Difference  
         
      CountryAggregate Loss 
      Argentina       (80,000,000) 
      US       (80,000,000) 
      UK       (80,000,000) 
      Germany       (80,000,000) 
      • v-lili6-msft's avatar
        v-lili6-msft
        Community Support

        hi,@sirgseymour

             After my research, whether there are only two types in column Portfolio, you can use this formula:

        Measure = CALCULATE(SUM(Table4[Aggregate Loss]),Table4[Portfolio]="Portfolio 1")-CALCULATE(SUM(Table4[Aggregate Loss]),Table4[Portfolio]="Portfolio 2")

        if there are more than two types in column Portfolio,

        when you select Portfolio 1 in slicer,

        first table visual will show data of Portfolio 1 and second table visual will show data of Portfolio 1 too.

         And when you select Portfolio 2 in slicer,

        second table visual will show data of Portfolio 2 and first table visual will show data of Portfolio 2 too.

         

        Best Regards,

        Lin

         

         

         

         

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi, sirgseymour

           Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

     

    Best Regards,

    Lin