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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Arnaud31450
Frequent Visitor

Sum of sales within a range

Hi team !

 

I am trying to get a sum of gross profit within a particular selling price range and then divide them by the sales within that range to get the gross margin.

 

I have tried to following below but it does not work. error message: "A function placeholder has been used in a True/False expression that is used as a table filter expression".

Sales_List Price to Lvl.1 = 
DIVIDE(
CALCULATE(
    SUM('Fact Sales Actual'[gp_sm_fxb]),
    'Measure AB_1'[ASP_LC_Fxb]<AVERAGE('Price List Item'[Apttus_Config2__ListPrice__c]),'Measure AB_1'[ASP_LC_Fxb]>AVERAGE('Price List Item'[TargetPrice__c])
),
CALCULATE(
    SUM('Fact Sales Actual'[sales_sm_fxb]),
    'Measure AB_1'[ASP_LC_Fxb]<AVERAGE('Price List Item'[Apttus_Config2__ListPrice__c]),'Measure AB_1'[ASP_LC_Fxb]>AVERAGE('Price List Item'[TargetPrice__c])
    )
)
thanks in advance for the help !
1 ACCEPTED SOLUTION

The first argument of FILTER has to be the table you are filtering.

 

Maybe this will get you a bit closer:

Sales_List Price to Lvl.1 =
VAR AvgListPrice   = AVERAGE ( 'Price List Item'[Apttus_Config2__ListPrice__c] )
VAR AvgTargetPrice = AVERAGE ( 'Price List Item'[TargetPrice__c] )
VAR PriceRange =
    FILTER (
        'Price List Item',
        AND (
            AvgListPrice > [ASP_LC_Fxb],
            [ASP_LC_Fxb] > AvgTargetPrice
        )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Fact Sales Actual'[gp_sm_fxb] ),    PriceRange ),
        CALCULATE ( SUM ( 'Fact Sales Actual'[sales_sm_fxb] ), PriceRange )
    )

View solution in original post

7 REPLIES 7
Arnaud31450
Frequent Visitor

So apparently it does not filter correctly as I did:

GP Lvl.2 to Lvl.3 = 
VAR AvgLevel2   = AVERAGE ( ProductPricing[Range2__c] )
VAR AvgLevel3 = AVERAGE ( ProductPricing[Range3__c] )
VAR PriceRange =
    FILTER (
        'ProductPricing',
        AND (
            AvgLevel2 > [ASP_LC_Fxb],
            [ASP_LC_Fxb] > AvgLevel3
        )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Fact Sales Actual'[gp_sm_fxb] ),    PriceRange ),
        CALCULATE ( SUM ( 'Fact Sales Actual'[sales_sm_fxb] ), PriceRange )
    )

And still got the same number ...

I don't know your model but it's possible that the measure [ASP_LC_Fxb] isn't behaving as you think inside the FILTER row context. How is this measure defined?

ASP_LC_Fxb =
DIVIDE(
    SUM('Fact Sales Actual'[sales_sm_fxb]),
    SUM('Fact Sales Actual'[units sold])
)
Arnaud31450
Frequent Visitor

It worked thanks a lot ! 
Need to investigate VAR and renaming variables !

Yep. It can help make the code more readable sometimes and sometimes even help performance by allowing you to calculate a value that is used repeatedly only once.

Arnaud31450
Frequent Visitor

Also tried this which gives syntax error:

 

 

Sales_List Price to Lvl.1 = 
DIVIDE(
CALCULATE(
    SUM('Fact Sales Actual'[gp_sm_fxb]),
    FILTER(AVERAGE('Price List Item'[Apttus_Config2__ListPrice__c])>'Measure AB_1'[ASP_LC_Fxb]>AVERAGE('Price List Item'[TargetPrice__c])
)),
CALCULATE(
    SUM('Fact Sales Actual'[sales_sm_fxb]),
    FILTER(AVERAGE('Price List Item'[Apttus_Config2__ListPrice__c])>'Measure AB_1'[ASP_LC_Fxb]>AVERAGE('Price List Item'[TargetPrice__c])
    ))
))

 

And this:


Sales_List Price to Lvl.1 = 
DIVIDE(
CALCULATE(
SUM('Fact Sales Actual'[gp_sm_fxb]),
FILTER(AND(AVERAGE('Price List Item'[Apttus_Config2__ListPrice__c])>'Measure AB_1'[ASP_LC_Fxb],'Measure AB_1'[ASP_LC_Fxb]>AVERAGE('Price List Item'[TargetPrice__c]))
)),
CALCULATE(
SUM('Fact Sales Actual'[sales_sm_fxb]),
FILTER(AND(AVERAGE('Price List Item'[Apttus_Config2__ListPrice__c])>'Measure AB_1'[ASP_LC_Fxb],'Measure AB_1'[ASP_LC_Fxb]>AVERAGE('Price List Item'[TargetPrice__c]))
))
))

 

The first argument of FILTER has to be the table you are filtering.

 

Maybe this will get you a bit closer:

Sales_List Price to Lvl.1 =
VAR AvgListPrice   = AVERAGE ( 'Price List Item'[Apttus_Config2__ListPrice__c] )
VAR AvgTargetPrice = AVERAGE ( 'Price List Item'[TargetPrice__c] )
VAR PriceRange =
    FILTER (
        'Price List Item',
        AND (
            AvgListPrice > [ASP_LC_Fxb],
            [ASP_LC_Fxb] > AvgTargetPrice
        )
    )
RETURN
    DIVIDE (
        CALCULATE ( SUM ( 'Fact Sales Actual'[gp_sm_fxb] ),    PriceRange ),
        CALCULATE ( SUM ( 'Fact Sales Actual'[sales_sm_fxb] ), PriceRange )
    )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.