Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I have a table which contains sales by store and by product type (A or B):
STORE_ID | PROD_TYPE |
STORE_01 | A |
STORE_01 | B |
STORE_02 | B |
STORE_03 | A |
STORE_03 | B |
STORE_04 | A |
STORE_05 | B |
I need to create a measure which will tell me if each store sells Only Prod A, Only Prod B or Both (it would look like this):
STORE_ID | MEASURE |
STORE_01 | BOTH |
STORE_01 | BOTH |
STORE_02 | ONLY B |
STORE_03 | BOTH |
STORE_03 | BOTH |
STORE_04 | ONLY A |
STORE_05 | ONLY B |
Any help would be greatly appreciated!
Solved! Go to Solution.
Hi @yharfush
Try this code to create your measure:
Measure =
VAR _A =
CALCULATE (
DISTINCTCOUNT ( 'Table'[PROD_TYPE] ),
ALLEXCEPT ( 'Table', 'Table'[STORE_ID] )
)
RETURN
IF ( _A = 2, "Both", "Only " & MAX ( 'Table'[PROD_TYPE] ) )
output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
Hi @yharfush
Try this code to create your measure:
Measure =
VAR _A =
CALCULATE (
DISTINCTCOUNT ( 'Table'[PROD_TYPE] ),
ALLEXCEPT ( 'Table', 'Table'[STORE_ID] )
)
RETURN
IF ( _A = 2, "Both", "Only " & MAX ( 'Table'[PROD_TYPE] ) )
output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
Thank you so much! This works perfectly.
If I can ask another thing, how can I add a filter to the table? Because I have two different time periods for my data and I need to show the results of only one period. I tried this but it doesn't seem to be working:
Measure =
VAR _A =
CALCULATE (
DISTINCTCOUNT ( 'Table'[PROD_TYPE] ),
ALLEXCEPT ( 'Table', 'Table'[STORE_ID] ),
FILTER( 'Table', 'Table'[PERIOD] = "PERIOD1" )
)
RETURN
IF ( _A = 2, "BOTH", "ONLY " & MAX ( 'Table'[PROD_TYPE] ))
Thanks again! 🙂
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
63 | |
62 | |
52 | |
39 | |
24 |
User | Count |
---|---|
84 | |
57 | |
45 | |
42 | |
37 |