Measure with Sum using Calculate and IF not showing totals correctly

I am working on a Power BI Report (which is in direct query mode with SSAS tabular model as source). I need to create two measures opening base and closing base with below condition.

opening base should be show value only for the minimum date range chosen by the user in the date slicer.

closing base should be show value only for the maximum date range chosen by the user in the date slicer.

For e.g : if user chooses between may 1, 2020 and may 17,2020 opening base will show value only for may 1, 2020 & closing base show value only for may 17th,2020. For other dates value should be 0 . I have tried below

Created a measure to get the minimum date of the date slicer.

**> StartDate = CALCULATE(min(‘DATE’[DATE]),ALLSELECTED(‘DATE’[DATE])) **
**> **
> OP = if(SELECTEDVALUE(‘DATE’[DATE]) = [StartDate], CALCULATE(sum(MEASUREMENTS[OPENING_BASE_VAL]),DATESBETWEEN(‘DATE’[DATE],[StartDate],[StartDate])),0)

Now i can get the desired output, but the grand-total is become 0 as shown in below picture. any help much appreciated.

Captures

@baijumohan,

Please take a look at the following thread:

This provides a solution to the same incorrect totals problem, and explains in pretty good detail the logic behind the solution.

If you still have questions after going through this, just give a shout.

I hope this is helpful.

  • Brian

https://forum.enterprisedna.co/t/why-your-total-is-incorrect-in-power-bi-the-key-dax-concept-to-understand/5108

https://forum.enterprisedna.co/t/fixing-errors-with-your-totals-efficiently/4948

Hi @baijumohan, a response on this post has been tagged as “Solution”. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the check box. Thanks!