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
akhaliq7
Post Prodigy
Post Prodigy

keepfilters - when aggregating the measure with another column, it brings back the incorrect value

I have written a dax measure that does boolean filters on calculate but brings backs the incorrect value, it uses keepfilters when I add another column the each row shows the correct value, but the total figure is incorrect

 

CALCULATE(
    SUM(Profit),
    KEEPFILTERS(Sales[Order Date] >= start_date),
    KEEPFILTERS(Sales[Order Date] <= end_date
)

 

please note, start_date and end_date above are variables but irrelevant for my question.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @akhaliq7 ,

Please try:
1. Explicitly Handle Totals:

Measure = 
// This is the total you want to get. Please modify the TotalProfit code as needed.
VAR TotalProfit = CALCULATE(SUM(Profit), ALLSELECTED(Sales))
RETURN
IF(
    HASONEVALUE(Sales[Order Date]),
    CALCULATE(
        SUM(Profit),
        KEEPFILTERS(Sales[Order Date] >= start_date),
        KEEPFILTERS(Sales[Order Date] <= end_date)
    ),
    TotalProfit
)

2. Or try completes context in the code:

MEASURE =
SUMX (
    VALUES ( 'Table'[GroupField] ),
    CALCULATE (
        SUM ( Sales[Profit] ),
        KEEPFILTERS ( Sales[Order Date] >= start_date ),
        KEEPFILTERS ( Sales[Order Date] <= end_date )
    )
)


Why Power BI totals might seem inaccurate - SQLBI
Obtaining accurate totals in DAX - SQLBI

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @akhaliq7 ,

Please try:
1. Explicitly Handle Totals:

Measure = 
// This is the total you want to get. Please modify the TotalProfit code as needed.
VAR TotalProfit = CALCULATE(SUM(Profit), ALLSELECTED(Sales))
RETURN
IF(
    HASONEVALUE(Sales[Order Date]),
    CALCULATE(
        SUM(Profit),
        KEEPFILTERS(Sales[Order Date] >= start_date),
        KEEPFILTERS(Sales[Order Date] <= end_date)
    ),
    TotalProfit
)

2. Or try completes context in the code:

MEASURE =
SUMX (
    VALUES ( 'Table'[GroupField] ),
    CALCULATE (
        SUM ( Sales[Profit] ),
        KEEPFILTERS ( Sales[Order Date] >= start_date ),
        KEEPFILTERS ( Sales[Order Date] <= end_date )
    )
)


Why Power BI totals might seem inaccurate - SQLBI
Obtaining accurate totals in DAX - SQLBI

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors