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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
2366
Helper I
Helper I

How to apply a measure calculation before roll up

Hello,

 

I needed some help to understand how to apply a DAX expression before roll up -

 

Here's a sample dataset -

DIM

2366_0-1639562783146.png

 

 

FACT

2366_1-1639562808107.png

 

 

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

 

2366_2-1639562920113.png

 

Here's my DAX

Margin = (Sum('Fact'[Selling])-sum('Fact'[Cost]))/sum('Fact'[Cost])
Less 20% Margin = IF([Margin]<.2,sum('Fact'[Selling]),0)
 
Appreciate any help with this.
 
Thanks
2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

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
    )
)

View solution in original post

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
    )
)

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

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?

 

Less 20% Margin 2 =
SUMX(
VALUES ( 'dim'[Sales Rep] ),
IF (
[Margin] < .2,
CALCULATE ( [Margin]) ,
0
)
)
 
2366_0-1639590384412.png

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
    )
)
ValtteriN
Super User
Super User

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.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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