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
baijumohan1990
Helper II
Helper II

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 

Created below measures 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.PNG

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@baijumohan1990 , Either change if to a filter. Or have a formula like one given below

I have used your existing measure in this


OP new=
sumx(summarize( Date, Date[Date],"_1",[OP]),[_1])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
v-yingjl
Community Support
Community Support

Hi @baijumohan1990 ,

In general, the measure is like @ amitchandak mentioned, since I'm not certain your dataset, I have created this measure:

OP =
VAR tab =
    SUMMARIZE (
        MEASUREMENTS,
        MEASUREMENTS[Date],
        MEASUREMENTS[OPENING_BASE_VAL],
        "Re",
        VAR _date = MEASUREMENTS[Date]
        RETURN
            IF (
                _date IN FILTERS ( 'Date'[Date] ),
                SUM ( MEASUREMENTS[OPENING_BASE_VAL] ),
                0
            )
    )
RETURN
    SUMX ( tab, [Re] )

result.png

My sample file is attached, please check and refer under your actual situation: Measure with Sum using Calculate and IF not showing totals correctly.pbix 

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@baijumohan1990 , Either change if to a filter. Or have a formula like one given below

I have used your existing measure in this


OP new=
sumx(summarize( Date, Date[Date],"_1",[OP]),[_1])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

hi amit,

 

thanks for your reply. i will try this out. could you plese give an example to replace if with filter? Also in the op_new measure you have created -1 is some placeholder?

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.