Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
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:
Product | Client | Volume | Expected volume |
C | 1 | 121 | x |
M | 1 | 1000 | x |
D | 1 | 200 | x |
C | 2 | 112 | x |
D | 2 | 300 | x |
M | 3 | 2000 | |
D | 4 | 400 | x |
C | 4 | 154 | x |
4287 | 2287 |
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.
@ImreP Try:
Measure =
VAR __Clients = DISTINCT('Table'[Client])
VAR __Table = FILTER(ALL('Table'),[Client] IN __Clients)
RETURN
SUMX(__Table,[Volume])
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.
@ImreP You can try something like this:
Measure =
SUMX(
KEEPFILTERS(DISTINCT('Table'[Client])),
CALCULATE(SUM('Table'[Volume]))
)
@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'))
)
Thanks! Looks good on the example. I'm going to try it on the actual data model.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
82 | |
81 | |
52 | |
39 | |
35 |
User | Count |
---|---|
95 | |
79 | |
52 | |
49 | |
47 |