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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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