Forum Discussion

IM_TRYING_HERE's avatar
IM_TRYING_HERE
Frequent Visitor
1 year ago

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. Thanks

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

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion
  • 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~

    • IM_TRYING_HERE's avatar
      IM_TRYING_HERE
      Frequent Visitor

      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.