Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hello, I need help with a DAX measurement.
I have my measure called "Gross Margin" which calculates the gross margin I make on a number of products sold in various supermarkets. This measure comes created as the sum of other measures (turnover per product minus transport cost, minus distribution cost, etc).
The supermarkets are Carrefour, Mercadona and Dia and come from the column Master[Supermarkets].
The products I analyze are Milk, Eggs and Meat and come from the column Master[Products].
The cities I analyze are Madrid, Barcelona and Valencia and come from the column Master[City].
I need to create a new measure, called "Gross Margin Carrefour" that always gives me the Carrefour margin for that product, that city and to be able to compare it with other supermarkets.
So I need this:
| Carrefour | Carrefour | Mercadona | Mercadona | Día | Día | ||
| Gross Margin Carrefour | Gross Margin | Gross Margin Carrefour | Gross Margin | Gross Margin Carrefour | Gross Margin | ||
| Madrid | Eggs | 100 | 100 | 100 | 98 | 100 | 55 |
| Milk | 120 | 120 | 120 | 37 | 120 | 24 | |
| Meat | 130 | 130 | 130 | 43 | 130 | 89 | |
| Barcelona | Eggs | 102 | 102 | 102 | 99 | 102 | 32 |
| Milk | 122 | 122 | 122 | 22 | 122 | 56 | |
| Meat | 132 | 132 | 132 | 50 | 132 | 78 | |
| Valencia | Eggs | 97 | 97 | 97 | 96 | 97 | 35 |
| Milk | 117 | 117 | 117 | 32 | 117 | 59 | |
| Meat | 127 | 127 | 127 | 51 | 127 | 83 |
As you can see, the Gross Margin Carrefour measure is constant for all supermarkets and products in the same city.
However, I am getting this result:
| Carrefour | Carrefour | Mercadona | Mercadona | Día | Día | ||
| Gross Margin Carrefour | Gross Margin | Gross Margin Carrefour | Gross Margin | Gross Margin Carrefour | Gross Margin | ||
| Madrid | Eggs | 100 | 100 | 101,2 | 98 | 100 | 55 |
| Milk | 120 | 120 | 120 | 37 | 122 | 24 | |
| Meat | 130 | 130 | 134,3 | 43 | 131 | 89 | |
| Barcelona | Eggs | 102 | 102 | 102,3 | 99 | 102,2 | 32 |
| Milk | 122 | 122 | 121 | 22 | 122 | 56 | |
| Meat | 132 | 132 | 132 | 50 | 133 | 78 | |
| Valencia | Eggs | 97 | 97 | 99 | 96 | 97 | 35 |
| Milk | 117 | 117 | 103 | 32 | 116,5 | 59 | |
| Meat | 127 | 127 | 127,1 | 51 | 128 | 83 |
The measure I am using right now is:
Gross Margin Carrefour = CALCULATE (
@armvime Hi! Try with:
Gross Margin Carrefour =
CALCULATE(
[Gross Margin],
Master[Supermarkets] = "Carrefour",
ALLEXCEPT(Master, Master[Products], Master[City])
)
The ALLEXCEPT function removes the filters from the other supermarkets while keeping the filters for products and cities intact.
BBF
Thanks for your answer, it gets better, but it is not the ultimate solution. Now I have the same Carrefour Gross Margin for all supermarkets and same city and product. However, it does not match the original Gross Margin for Carrefour supermarket. That is, my table is now like this:
| Carrefour | Carrefour | Mercadona | Mercadona | Día | Día | |||
| Gross Margin Carrefour | Gross Margin | Gross Margin Carrefour | Gross Margin | Gross Margin Carrefour | Gross Margin | |||
| Madrid | Eggs | 98 | 100 | 98 | 98 | 98 | 55 | |
| Milk | 117 | 120 | 117 | 37 | 117 | 24 | ||
| Meat | 133 | 130 | 133 | 43 | 133 | 89 | ||
| Barcelona | Eggs | 101 | 102 | 101 | 99 | 101 | 32 | |
| Milk | 121 | 122 | 121 | 22 | 121 | 56 | ||
| Meat | 134 | 132 | 134 | 50 | 134 | 78 | ||
| Valencia | Eggs | 96,2 | 97 | 96,2 | 96 | 96,2 | 35 | |
| Milk | 119 | 117 | 119 | 32 | 119 | 59 | ||
| Meat | 130 | 127 | 130 | 51 | 130 | 83 |
@armvime Try with:
Gross Margin Carrefour =
CALCULATE(
[Gross Margin],
KEEPFILTERS(Master[Supermarkets] = "Carrefour"),
ALLEXCEPT(Master, Master[Products], Master[City])
)
If it still doesn't work, can you share the PBIX file and tell me the desired output? So that I can test it directly on the dataset.
BBF
@armvime , Try using below measure
Gross Margin Carrefour =
CALCULATE(
[Gross Margin],
Master[Supermarkets] = "Carrefour",
REMOVEFILTERS(Master[Supermarkets])
)
Proud to be a Super User! |
|
Thanks for your answer, it stays as it is, the table is unchanged.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 21 | |
| 10 | |
| 8 | |
| 8 |