Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jlarques
Resolver I
Resolver I

Wrong total in a matrix

Hi Team,

Before writing this post, I have been looking for other samples with the same problem, but all solutions didn't work in my case.

I'm working with two simple measures that I want to show in a matrix. The measures are:

Ingresos=SUM(INGRESOS[IMPORTE])

Ingresos LY=

     IF(
         Ingresos>0;

         CALCULATE(

            Ingresos;

            SAMEPERIODLASTYEAR(

                CALENDARIO[FECHA]

            )

        )

    )

 

The reason that I type an IF expression is to avoid show all rows in the IngresosLY column if the Ingresos column has no values.

The result is this:

Error suma totales matriz.png

As you can see, the total of Ingresos LY is wrong, because the total amount is the monthly amount and not the total of Ingresos LY column.

Do you know where the problem is? Any suggestions?

 

Thanks, everyone for your help.

 

José Luis 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

 
I try these following measures based on replicate dataset and it seems to work (Sheet1 is just a date + amount column)
 
1. Actual = SUM(Sheet1[Amount])
2. Lastyear =
IF([Actual] > 0,
CALCULATE([Actual],SAMEPERIODLASTYEAR('Calendar'[Date]))
)
3. TotalForLastyear =
var TT = SUMMARIZE('Calendar','Calendar'[Date],"Lastyear",[Lastyear])
return
IF(HASONEVALUE(Sheet1[Date]),
[Lastyear],
SUMX(TT,[Lastyear])
)
You may want to see more explanation in


https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,

 
I try these following measures based on replicate dataset and it seems to work (Sheet1 is just a date + amount column)
 
1. Actual = SUM(Sheet1[Amount])
2. Lastyear =
IF([Actual] > 0,
CALCULATE([Actual],SAMEPERIODLASTYEAR('Calendar'[Date]))
)
3. TotalForLastyear =
var TT = SUMMARIZE('Calendar','Calendar'[Date],"Lastyear",[Lastyear])
return
IF(HASONEVALUE(Sheet1[Date]),
[Lastyear],
SUMX(TT,[Lastyear])
)
You may want to see more explanation in


https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

ebeery
Solution Sage
Solution Sage

@jlarques this is yet another example of the very common "wrong total" issue.  By definition, the total cell for the "LY" measure does not compute the total of the cells above it - instead it computes the measure in its current context.

 

In this case, its context is the "sameperiodlastyear" of whatever date context you have applied to the visual. I'm guessing you have a filter/slicer applied to the visual which may be filtering the date context to "January 2021" or something?  If this is the case, one option would be to adjust the upper bound of your date range to include only the date range in 2021 which you want to consider in 2020.

Hi @ebeery ,

 

thanks for your answer. 

 Indeed, I have a year filter to visualize the results in the matrix. The problem will be when the matrix grows and includes other years like 2024, 2025, etc. I don't want to adjust the upper bound every time.

 

I would like to have a simple matrix with the right total for the Ingresos LY measure. With all the power of DAX formulas, I'm sure there has to be a way to be able to display the right total.

Thanks,

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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