March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
I needed some help to understand how to apply a DAX expression before roll up -
Here's a sample dataset -
DIM
FACT
I am trying to calculate the total sales amount from every city where the sales rep margin <20%. DAX works fine when I keep Sales Rep in the context but when I remove Sales rep field, the calculation doesnt work anymore
Here's my DAX
Solved! Go to Solution.
Add an iterator at whatever the appropriate level of granularity is.
Assuming Sales Rep the granularity you want, try this:
Less 20% Margin =
SUMX (
VALUES ( 'dim'[Sales Rep] ),
IF (
[Margin] < .2,
CALCULATE ( SUM ( 'Fact'[Selling] ) ),
0
)
)
This measure is designed to add up the values for each Sales Rep separately so it shouldn't be used when you don't want to do that.
I'm not sure, but I'm guessing you want something more like this:
Less 20% Margin 2 =
CALCULATE (
[Margin],
FILTER (
VALUES ( 'dim'[Sales Rep] ),
[Margin] < .2
)
)
Add an iterator at whatever the appropriate level of granularity is.
Assuming Sales Rep the granularity you want, try this:
Less 20% Margin =
SUMX (
VALUES ( 'dim'[Sales Rep] ),
IF (
[Margin] < .2,
CALCULATE ( SUM ( 'Fact'[Selling] ) ),
0
)
)
Thank you that works!!
I further changed the DAX to calculate margins of the sales reps <.2 and it works however the sub total row aggregates the percentages. Is there anyway to handle this please?
Thanks
This measure is designed to add up the values for each Sales Rep separately so it shouldn't be used when you don't want to do that.
I'm not sure, but I'm guessing you want something more like this:
Less 20% Margin 2 =
CALCULATE (
[Margin],
FILTER (
VALUES ( 'dim'[Sales Rep] ),
[Margin] < .2
)
)
Hi,
Without the sales rep context your calculation is done to all of the data in the data set and it seems for new york this aggregate is greater than 20%. To solve this you can calculate the margin in a calcuated column and then appy the if condition to the calculated column to get the margin on a transaction level.
I hope this helps to solve your issue and if it does consider accepting this as a solution.
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
14 | |
11 | |
8 | |
5 |
User | Count |
---|---|
26 | |
21 | |
20 | |
14 | |
10 |