Forum Discussion

Shaik_2002's avatar
Shaik_2002
Frequent Visitor
2 years ago
Solved

Values not getting added in TOTALS

Hi All,

 

Here I Have some measures,

 

On-Date Target =

VAR Key = AVERAGE('Table'[Value])

RETURN

IF(HASONEVALUE('Table'[Cities]),Key,SUMX(VALUES('Table'[Cities]),Key))

 

Day Target =

VAR SelectedDate  = SELECTEDVALUE('DateTable'[Date])

VAR SelectedMonth = MONTH(SelectedDate)

VAR SelectedYear  = YEAR(SelectedDate)

RETURN

CALCULATE(

    ([On-Date Target]),

    'DateTable'[Date] <= SelectedDate,

    'DateTable'[Date] >= DATE(SelectedYear, SelectedMonth, 1)  -- MTD

)

 

And I'm getting like this.

while using Day Target Measure, I'm getting blank for Kannur. So I used another Measure Day_Target variable, 

 

Day_Target  =

VAR SelectedDate = SELECTEDVALUE('DateTable'[Date])

VAR SelectedMonth = MONTH(SelectedDate)

VAR SelectedYear = YEAR(SelectedDate)

RETURN

IF(ISBLANK([On-Date Target]),

    CALCULATE(

        [On-Date Target],

        'DateTable'[Date] <= SelectedDate,

        'DateTable'[Date] >= DATE(SelectedYear, 1, 1)  -- YTD

    ),

    CALCULATE(

        [On-Date Target],

        'DateTable'[Date] <= SelectedDate,

        'DateTable'[Date] >= DATE(SelectedYear, SelectedMonth, 1)  -- MTD

    )

)

now I'm getting value for Kannur, but it is not adding in TOTALS.

 

 

Please suggest any solution to this.
Thanks in advance!!

  • Hi All,

     

    Issue is resolved by using this below measure

     

    Total_MTD_YTD =
    IF(
        ISINSCOPE('Table'[Countries]),
        [Day_Target],
        CALCULATE(
            SUMX(
                ALL('Table'[Countries]),
                [Day_Target]
            )
        )
    )
     
    Thank you all.
  • Hi Anonymous ,

     

    In the Sample file which you published, the data is getting like this.

    But I need like this

    By using first two measures, I didn't get the expected result.

    Day.Target = 
    VAR SelectedDate  = SELECTEDVALUE(DateTable[Date])
    VAR SelectEdMonth = MONTH(SelectedDate)
    VAR SelectedYear  = YEAR(SelectedDate)
    RETURN
    CALCULATE(
        ([On-Date Target]),
        'DateTable'[Date] <= SelectedDate,
        'DateTable'[Date] >= DATE(SelectedYear, SelectedMonth, 1)  -- MTD
    )

     

    Day Target = 
    VAR SelectedDate = MAX('DateTable'[Date])
    VAR SelectedMonth = MONTH(SelectedDate)
    VAR SelectedYear = YEAR(SelectedDate)
    VAR MTD_Value =
        CALCULATE(
            [On-Date Target],
            DATESBETWEEN(
                'DateTable'[Date],
                DATE(SelectedYear, SelectedMonth, 1),
                SelectedDate
            )
        )
    VAR YTD_Value =
        CALCULATE(
            [On-Date Target],
            DATESBETWEEN(
                'DateTable'[Date],
                DATE(SelectedYear, 1, 1),
                SelectedDate
            )
        )


    But using third measure, I got the expected result.

    Day_Target = 
    IF(
        ISINSCOPE('Table'[Countries]),
        [Day Target],
        CALCULATE(
            SUMX(
                ALL('Table'[Countries]),
                [Day Target]
            )
        )
    ) 

     

    I'm sharing my sample file,

    https://www.dropbox.com/scl/fi/gdte9oe6lcd5sgs2lc5iv/Sample-Power-Bi-Data.pbix?rlkey=9ltgzdxbdy9074kw5ar8z8c1i&st=tqjes2fd&dl=0

     

    Thank you all.

     

7 Replies

  • Shaik_2002 , You need a measure like

     

    Day_Target  =

    Sumx( Values(Geography[Cities]) ,

    VAR SelectedDate = SELECTEDVALUE('DateTable'[Date])

    VAR SelectedMonth = MONTH(SelectedDate)

    VAR SelectedYear = YEAR(SelectedDate)

    RETURN

    IF(ISBLANK([On-Date Target]),

        CALCULATE(

            [On-Date Target],

            'DateTable'[Date] <= SelectedDate,

            'DateTable'[Date] >= DATE(SelectedYear, 1, 1)  -- YTD

        ),

        CALCULATE(

            [On-Date Target],

            'DateTable'[Date] <= SelectedDate,

            'DateTable'[Date] >= DATE(SelectedYear, SelectedMonth, 1)  -- MTD

        )

    ) )

     

    You can summarize if there more than one group by in visual

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Shaik_2002 ,

     

    As far as I know, your issue should be caused by IF() function.

    Here I have two workarounds: 
    1. You can sum [Day_Target] to get correct total directly.

     

    New_Day_Target =
    SUMX ( VALUES ( 'Table'[Citys] ), [Day_Target] )

    2. You can create a virtual table in your calculation.

    New_Day_Target =
    VAR _Virtual =
        SUMMARIZE (
            'Table',
            'Table'[Cities],
            "Day_Target",
                VAR SelectedDate =
                    SELECTEDVALUE ( 'DateTable'[Date] )
                VAR SelectedMonth =
                    MONTH ( SelectedDate )
                VAR SelectedYear =
                    YEAR ( SelectedDate )
                RETURN
                    IF (
                        ISBLANK ( [On-Date Target] ),
                        CALCULATE (
                            [On-Date Target],
                            'DateTable'[Date] <= SelectedDate,
                            'DateTable'[Date] >= DATE ( SelectedYear, 1, 1 )
                        ),
                        CALCULATE (
                            [On-Date Target],
                            'DateTable'[Date] <= SelectedDate,
                            'DateTable'[Date] >= DATE ( SelectedYear, SelectedMonth, 1 )
                        )
                    )
        )
    RETURN
        SUMX ( _Virtual, [Day_Target] )

    If this reply still couldn't help you solve your issue please share a sample file with us. This will make it easier for us to find the solution.

     

    Best Regards,
    Rico Zhou

     

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

     

    • Shaik_2002's avatar
      Shaik_2002
      Frequent Visitor

      Hi All,

       

      Issue is resolved by using this below measure

       

      Total_MTD_YTD =
      IF(
          ISINSCOPE('Table'[Countries]),
          [Day_Target],
          CALCULATE(
              SUMX(
                  ALL('Table'[Countries]),
                  [Day_Target]
              )
          )
      )
       
      Thank you all.
      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Shaik_2002 ,

         

        I am glad that you could find the solution by yourself.

        Here I update the measure, you can achieve your goal by only two measures.

        Day Target = 
        VAR SelectedDate =
            SELECTEDVALUE ( 'DateTable'[Date] )
        VAR SelectedMonth =
            MONTH ( SelectedDate )
        VAR SelectedYear =
            YEAR ( SelectedDate )
        VAR _AVG =
            AVERAGE ( 'Table'[Value] )
        VAR _MonthLevel =
            CALCULATE (
                AVERAGE ( 'Table'[Value] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Countries] ),
                    'Table'[Billing Date] <= SelectedDate
                        && 'Table'[Billing Date] >= DATE ( SelectedYear, SelectedMonth, 1 )
                ) -- MTD
            )
        VAR _YearLevel =
            CALCULATE (
                AVERAGE ( 'Table'[Value] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Countries] ),
                    'Table'[Billing Date] <= SelectedDate
                        && 'Table'[Billing Date] >= DATE ( SelectedYear, 1, 1 )
                ) -- YTD
            )
        RETURN
            IF (
                ISBLANK ( _AVG ),
                IF ( ISBLANK ( _MonthLevel ), _YearLevel, _MonthLevel ),
                _AVG
            )
        Measure = 
        IF(HASONEVALUE('Table'[Countries]),[Day Target],SUMX(ALLSELECTED('Table'[Countries]),[Day Target]))

        Result is as below.

         

        Best Regards,
        Rico Zhou

         

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

         

    • Shaik_2002's avatar
      Shaik_2002
      Frequent Visitor

      Hi Anonymous,

       

      Sorry for the delay, I have tried the formula which you have given and still it is not working. 

      I'm attaching the sample pbix file along with the sample excel data.

      https://www.dropbox.com/scl/fi/gdte9oe6lcd5sgs2lc5iv/Sample-Power-Bi-Data.pbix?rlkey=9ltgzdxbdy9074kw5ar8z8c1i&st=nyu8x4yk&dl=0

       

      https://www.dropbox.com/scl/fi/b66kr2jby2di4rty67pyh/Sample-Data.xlsx?rlkey=ixaokfwbxyl9u7yaeckjpn5nw&st=hxv3lxvd&dl=0

       

      Thanks in Advance!!