The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
Solved! Go to Solution.
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
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