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
IM_TRYING_HERE
Frequent Visitor

Measure using DATESBETWEEN wrong total but correct row value

I am having an issue where the rows in my table visual are showing correct values but the total row is wrong. I assume its related to context transition but I'm not sure. Here is a basic version of my measure along with a screenshot of a basic example of tables and desired result. Any advice is highly appreciated. ThanksPBI Example.png

MeasureName =

VAR stdt =

    IF (

        SELECTEDVALUE ( DateTable[YearStartDate] )

            <= SELECTEDVALUE ( PropertyInfoTable[PurchaseDate] ),

        SELECTEDVALUE ( DateTable[YearStartDate]),

        SELECTEDVALUE ( DateTable[YearStartDate])

    )

VAR endt =

    IF (

        SELECTEDVALUE ( PropertyInfoTable[SellDate]) = BLANK (),

        SELECTEDVALUE ( DateTable[Date] ),

        SELECTEDVALUE ( PropertyInfoTable[SellDate])

    )

RETURN

    SUMX (

        SUMMARIZE (

            PropertyInfoTable,

            PropertyInfoTable[Name]

        ),

        CALCULATE (

            SUM ( ActualCostsTable[Amount] ),

            DATESBETWEEN ( DateTable[Date], stdt, endt )

        )

    )

3 REPLIES 3
xifeng_L
Super User
Super User

Hi @IM_TRYING_HERE 

 

You can try below measure:

 

MeasureName =
SUMX(VALUES(PropertyInfoTable[Name]),CALCULATE(

VAR stdt =

    IF (

        SELECTEDVALUE ( DateTable[YearStartDate] )

            <= SELECTEDVALUE ( PropertyInfoTable[PurchaseDate] ),

        SELECTEDVALUE ( DateTable[YearStartDate]),

        SELECTEDVALUE ( DateTable[YearStartDate])

    )

VAR endt =

    IF (

        SELECTEDVALUE ( PropertyInfoTable[SellDate]) = BLANK (),

        SELECTEDVALUE ( DateTable[Date] ),

        SELECTEDVALUE ( PropertyInfoTable[SellDate])

    )

RETURN

    SUMX (

        SUMMARIZE (

            PropertyInfoTable,

            PropertyInfoTable[Name]

        ),

        CALCULATE (

            SUM ( ActualCostsTable[Amount] ),

            DATESBETWEEN ( DateTable[Date], stdt, endt )

        )

    )
  )
)

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

I was able to create a measure containing the initial start date and end date variables/parameter in an measure called "TotalActualCostsTableAmount" and then put it inside the following measure .
SUMX (
SUMMARIZE (
PropertyInfoTable,
PropertyInfoTable[Name]
),
CALCULATE (
[TotalActualCostsTableAmt],
DATESYTD ( 'DateTable'[Date] )
)
)

My question is, are there any other more efficient ways of writing this measure that doesn't require SUMX(Summarize. I'm still confused as to why if don't wrap in a SUMX(Summarize and I select a single property the row and total are correct but if I select two or more properties the total get the date logic wrong.

 

Greg_Deckler
Community Champion
Community Champion

@IM_TRYING_HERE First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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