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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ImreP
Helper I
Helper I

Values of all related clients based on product filter

Hi,

 

I have a requirement where I need to get the values of all products of all clients that has a product a user filters.

 

Here is the example:

 

ProductClientVolumeExpected volume
C1121x
M11000x
D1200x
C2112x
D2300x
M32000 
D4400x
C4154x
  42872287

 

Let's say the user slices by Product 'C'. In this case the required Measure result is the sum of all products where any clients has product 'C'. Then 'Expected volume' marks which volumes should be included in the result in case of product 'C' filter.

 

In SQL I'd do the following:

 

select
sum(Volume)
from table

where client in

(select
client
from table
where product='C')

 

But I need this to be dynamic therefore I think it should be written in a measure. 

 

Could you please help me with this?

 

Thanks.

6 REPLIES 6
Greg_Deckler
Super User
Super User

@ImreP Try:

Measure =
  VAR __Clients = DISTINCT('Table'[Client])
  VAR __Table = FILTER(ALL('Table'),[Client] IN __Clients)
RETURN
  SUMX(__Table,[Volume])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

It's not fast. Actually it does not give a result after minutes. I was out of memory after about 7 minutes. 

 

I guess it is expected to be slow. 

 

Are there any options that are less resource intensive? It could be tables, measures. The data model is much more complex than my example and there are multiple filters in the user's hand. All other filters should work as "normal". But testing on my sample table, your formula does just that, so I would think your formula would result in the desired output. 

 

@Greg_Deckler 

@ImreP You can try something like this:

Measure =
SUMX(
	KEEPFILTERS(DISTINCT('Table'[Client])),
	CALCULATE(SUM('Table'[Volume]))
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler The performance is okay but the result is wrong. Only the chosen product is taken into account on client level. 

@ImreP Yeah, the joys of CALCULATE, maybe this:

Measure =
SUMX(
	KEEPFILTERS(DISTINCT('Table'[Client])),
	CALCULATE(SUM('Table'[Volume]),ALL('Table'))
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks! Looks good on the example. I'm going to try it on the actual data model. 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors