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
rhoelzle
Frequent Visitor

How to sum with filter on related columns from multiple tables

Appologies if this has already been covered in another post. I've searched with so many keyword combos, but haven't yet found a post that covers what I'm trying to do. Please link if you think this has already been covered.

 

In short, I'm trying to create a set of measures which sum a column from one table (TableA) based on a filter applied to a different different table (TableB) which is related to the first through an intermediate metadata table (TableMD). I'll ultimately be doing this same thing on several different sets of interlinked tables, but all with the same basic filtering structure.

 

I'll lay out one as an example. Here, TableA is timestamped net profits associated with a number of different units, TableB is the timestamped regional market price that those units operate in, and TableMD links units to regions.

 

TableA

DATETIMEUNITNET_PROFIT
28/03/2023 12:00:00 AMA390.45
28/03/2023 12:00:00 AMB547.87
28/03/2023 12:00:00 AMC962.47
28/03/2023 12:00:00 AMD303.17
27/03/2023 11:00:00 PMA-102.91
27/03/2023 11:00:00 PMB707.78
27/03/2023 11:00:00 PMC596.35
27/03/2023 11:00:00 PMD876.05
27/03/2023 10:00:00 PMA313.89
27/03/2023 10:00:00 PMB437.14
27/03/2023 10:00:00 PMC639.51
27/03/2023 10:00:00 PMD516.13
---------
---------
---------
---------
01/01/2015 01:00:00 AMA203.12
01/01/2015 01:00:00 AMB797.69
01/01/2015 01:00:00 AMC228.12
01/01/2015 01:00:00 AMD852.00

 

Table B

DATETIMEREGIONMARKET_PRICE
28/03/2023 12:00:00 AMR1-41.08
28/03/2023 12:00:00 AMR2148.84
27/03/2023 11:00:00 PMR1-40.08
27/03/2023 11:00:00 PMR29.4
27/03/2023 10:00:00 PMR121.88
27/03/2023 10:00:00 PMR240.22
---------
---------
01/01/2015 01:00:00 AMR189.05
01/01/2015 01:00:00 AMR281.05

 

TableMD

UNITREGION
AR1
BR2
CR1
DR1

 

In my model, TableA[UNIT] links to TableMD[UNIT], TableB[REGION] links to TableMD[REGION], and TableA[DATETIME] and TableB[DATETIME] both link to an independent Calendar table with DATETIME, DATE, YEAR, etc.

 

I want to create a measure in TableA that sums NET_PROFIT for all rows (DATETIMEs) where the associated regional MARKET_PRICE in TableB is less than 45 (ie, how well do we perform when the market price is low?).

 

I'm quite new to power bi and can't work out the syntax, but I'm guessing it's some sort of multilayered filtering like:

 

 

Measure =
   CALCULATE(
      SUM(TableA[NET_PROFIT]),
      FILTER(
         TableA,
         FILTER(
            TableMD,
            FILTER(
               TableB, TableB[MARKET_PRICE] < 45
            )
         )
      )
   )

 

 

 

The end goal is to feed these set of measures into a couple of different matrix visualizations. Thanks for any and everythign that helps me work this out!

0 REPLIES 0

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.