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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Notbad
Regular Visitor

How to filter related table by measure?

Hello! I`m very-very new to Power Bi and, unfortunately, I got stuck with this issue. I have three tables (two tables with facts (costs and traffic) and one table with kyes (for filtering). I`m trying to write a measure, which will show a sum of spent money (a

facts_ads_costs[adCost] field) but only if there is at least one session in table facts_GA_traffic. 

And this variant I wrote dies not work.

amount_spent =
VAR sessions = SUM(facts_GA_traffic[sessions])
RETURN
CALCULATE(SUM(facts_ads_costs[adCost]), sessions > 1)

Could you please help? Thanks!

tables.png

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

 

Hi @Notbad ,

Accourding your picture ,the relationship in your tables:

key_utm_from_BQ   to facts_GA_traffic :one to many(1:*)

key_utm_from_BQ   to facts_ads_costs:one to many(1:*)

facts_GA_traffic  and  facts_ads_costs , not with direct relatinship.

So you need to show the relationship throuth dax.

And according your picture ,I create a sample:

key_utm_from_BQ :

vluwangmsft_0-1639465641159.png

facts_GA_traffic:

vluwangmsft_1-1639465657160.png

 

facts_ads_costs:

vluwangmsft_2-1639465683564.png

Relationship:

vluwangmsft_3-1639465699206.png

 

your measure:

amount_spent =
VAR sessions =
    SUM ( facts_GA_traffic[sessions] )
RETURN
    CALCULATE ( SUM ( facts_ads_costs[adCost] ), sessions > 1 )

Return :

vluwangmsft_4-1639465788758.png

 

And based on the three table ,try following steps:

Step1, create a measure on facts_GA_traffic:

session1 = SUM(facts_GA_traffic[sessions])

Step 2, create measure on  facts_ads_costs:

amount_spent = 
CALCULATE(SUM(facts_ads_costs[adCost]),FILTER(facts_GA_traffic,facts_GA_traffic[medium]=MAX(facts_ads_costs[medium])&&facts_GA_traffic[session1]>1))

Get result(the figure below, only medium=3 satisfies the condition):

vluwangmsft_5-1639465917785.png

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

 

View solution in original post

2 REPLIES 2
v-luwang-msft
Community Support
Community Support

 

Hi @Notbad ,

Accourding your picture ,the relationship in your tables:

key_utm_from_BQ   to facts_GA_traffic :one to many(1:*)

key_utm_from_BQ   to facts_ads_costs:one to many(1:*)

facts_GA_traffic  and  facts_ads_costs , not with direct relatinship.

So you need to show the relationship throuth dax.

And according your picture ,I create a sample:

key_utm_from_BQ :

vluwangmsft_0-1639465641159.png

facts_GA_traffic:

vluwangmsft_1-1639465657160.png

 

facts_ads_costs:

vluwangmsft_2-1639465683564.png

Relationship:

vluwangmsft_3-1639465699206.png

 

your measure:

amount_spent =
VAR sessions =
    SUM ( facts_GA_traffic[sessions] )
RETURN
    CALCULATE ( SUM ( facts_ads_costs[adCost] ), sessions > 1 )

Return :

vluwangmsft_4-1639465788758.png

 

And based on the three table ,try following steps:

Step1, create a measure on facts_GA_traffic:

session1 = SUM(facts_GA_traffic[sessions])

Step 2, create measure on  facts_ads_costs:

amount_spent = 
CALCULATE(SUM(facts_ads_costs[adCost]),FILTER(facts_GA_traffic,facts_GA_traffic[medium]=MAX(facts_ads_costs[medium])&&facts_GA_traffic[session1]>1))

Get result(the figure below, only medium=3 satisfies the condition):

vluwangmsft_5-1639465917785.png

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

 

bcdobbs
Community Champion
Community Champion

I think this does what you're trying to achieve:

 

amount_spent =
VAR sessions = SUM(facts_GA_traffic[sessions])

RETURN

IF( sessions > 1,
	SUM(facts_ads_costs[adCost]),
	BLANK()
)

 

 

What you were doing wouldn't work a row in facts_ads_costs has no sessions column to filter on.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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