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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Greg_Deckler
Super User
Super User

Dealing with Measure Totals

This one has come up quite a bit recently. The issue surrounds using Measures in Table visualizations with a Total row. The complaint is that the "Total" row is "wrong" for the measure. Technically, the total row is correct for the measure, it's just not what most people expect. What people expect is for the "Total" to display the sum of the values in the column. Measures do not do this. Measures respect the context of the Total row and is calculated within that context. Therefore, a Measure used in a column in a table visualization will likely have an unexpected value in the Total column.

 

There are a couple ways of fixing this. The easiest is to turn off the Total row.

 

Assuming that is not what you want, you can use the HASONEFILTER function to get around this issue. However, the ultimate solution will depend on how your measure is calculated.

 

For example, given the following data:

 

Year Amount

Year1500
Year21500
Year32000
Year4100
Year5800

 

We wish to find the total extra Amount spent above 1000 for each year. If the amount is not over 1000, we wish to display 0. To this end, we create a measure:

 

MyMeasure = IF(SUM(Table[Amount])<1000,0,SUM(Table[Amount])-1000) 

Adding this to a Table visualization along with Year, we get the correct answer for each of the rows, but the Total line displays 3900, not 1500 as we would expect. The figure 3900 is calculated because the Measure is performing its calculation for ALL of the rows in the table, so the calculation is (500 + 1500 + 2000 + 100 + 800) - 1000 = 3900.

 

Correct, but not what was expected.

 

To get around this problem, use HASONEFILTER to calculate the Measure one way within a row context and another way within the Total row context, such as:

 

MyMeasure2 = IF(HASONEFILTER(Table[Year]),
IF(SUM(Table[Amount])<1000,0,SUM(Table[Amount])-1000),
SUMX(FILTER(Table,[Amount]>1000),[Amount]-1000)
)

Breaking this down, we essentially wrap our original measure in an IF statement that has the HASONEFILTER function as the logical test. If HASONEFILTER equals true, we calculate our Measure as before. However, if HASONEFILTER is false, we know that we have a Total row and we calculate our Measure a different way.

 

 

 

 

 

 

 

 


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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
104 REPLIES 104
Bunmz_a
Frequent Visitor

Please I am experiencing the same issue

 

My objective is to calculate the total budget associated with each Workorder status however for Projected Workorders, the budget for Open and Initiated should be netted off till it gets to 0. Meaning the Budget measure would need to incorporate an adjustment for Projected Workorders

 

I have been able to do this successfully but the grand total does not work.

 

For the grand total, I am still getting a sum that reflect the original not adjusted projected budget regardless of the logic built into the measure

 

Below is my measure. When I use ‘HASONEVALUE’ I get 0 as the grand total

 

Please help

 

 

Budget =

VAR WOstatus =

    FIRSTNONBLANK ( 'Projected WO'[WO_Status], 1 )

 

VAR BudgetTotal =

    CALCULATE (

        SUM ( Budget[Amount] ),

        FILTER ( Budget, Budget[BudgetType] = "Budget" )

    )

   

VAR ProjectedAmount =

    CALCULATE (

        BudgetTotal,

        'Projected WO'[WO_Status] IN { "Projected", "projected" }

    )

 

VAR InitiatedAmount =

    CALCULATE (

        BudgetTotal,

        'Projected WO'[WO_Status] IN { "Initiated", "initiated" }

    )

 

VAR OpenAmount =

    CALCULATE (

        BudgetTotal,

        'Projected WO'[WO_Status] IN { "open", "Open" }

    )

 

VAR AdjustedProjectedAmount = MAX( (ProjectedAmount - InitiatedAmount - OpenAmount ), 0)

 

RETURN

    IF (

        NOT ( WOstatus IN { "Projected", "projected" } ),

        BudgetTotal,

        AdjustedProjectedAmount)

Hi,

Share data in a format that can be pasted in an MS Excel file.  Explain the question and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
cheid_4838
Helper I
Helper I

Due to how the data is structured I had to create columns to break out count versus the dollar amounts associated with each itemcode in the dataset  Each itemcode has a column for quantity and charge.  All I had to do was drag each column into the values field in the matrix to get everything to total up.  Do the totals calcualted or averages matter if the totals come from a measure versus a column?

cheid_4838_1-1708614511218.png

 

 

 

I guess I am trying to determine how this applies to me if the column totals are accurate since they are coming from column totals not measures.  I under how the averages will not be correct if calculating a measure, but shouldn't the averages be accurate since the totals come from columns and not measures?  Thanks for your help.

@cheid_4838 It certainly does matter. Column totals always work. Measure totals, it depends. Here is actually a better article 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
jonnyA
Responsive Resident
Responsive Resident

Thx for the input!  I'm from from an expert at putting together formula's.  Can you provide a sample given the formula i sent in my original message?

 

Thanks

Brad_Roberts
Frequent Visitor

Greg,

I'm brand new to Power BI and I'm attempting to apply your solution.  My row dax works fine but the total is not working.  Change SF is a measure of (Sum of All Area - Start SF) and I want to split that between two new measures (Move-In and Move-Out).

 

Brad_Roberts_0-1670441670754.png

Any help is appreciated.

 

Thanks,

Tony

 

 

rmckenna594
New Member

Hi, 

I am having some difficulties with linking two separate data tables with a CALCULATE(SUM) calculated column. I want to bring in the total production cost at item level using the calculated column, but then apply a formula on this to generate the cost per unit in stock.

 

I have tried to do this using a calculated measure but the Total of the Measure does not equate to the sum of all of my table row values.

Urgent help on this would be greatly appreciated 🙂

 

Regards,

Ryan

Patrick95
Frequent Visitor

Hi,

 

I've created a measure to calculate the distinct "Document No." when they have a certain value (FILTER ON: '42-CHECK-SERIALNO'). 

It could be that the same Document No. will have the value (42-...) on a different date. 

 

The totals are corrrect in the matrix, but the subtotals will count the value even if the Document No. has already hit the value (42-CHECK-SERIALNO) already on a different date. Herefor if you count the subtotals, you will get a different total als the one that is listed correctly in the matrix.

 

If the "Document No." occurs several times on different dates by value (42-...), then I do not want to count this (double) in the subtotals. It should only count the first time the "Document No." hits the status (42-...)

 

Patrick95_0-1661518906275.png

 

 

Patrick95_1-1661518906292.png

 

 

I hope someone can help me with this issue

 

Hi,

What is the problem there.  The subtotal shows 34.  Are you expecting a different result there?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

 

Thank you for replying! 

 

As you can see, the total is 34 which is correct. If you add up the subtotals (10+17+12+9 = 48), you get a different result. The addition of the subtotals is incorrect The subtotals will count the value even if the same Document No. has the value (42-CHECK-SERIALNO) on a different date.

 

Therefor, I would like to create a measure: If the "Document No." occurs several times on different dates by value (42-...), then I do not want to count this (double) in the subtotals. It should only count the first time the "Document No." hits the status (42-...).

 

Unfortunately, I cannot figure out how to do this.

 

Do you have experience how to do this?

 

Thanks in advance.

 

Patrick

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

It is shocking that after a number of years Power BI still does not offer an option to show the sum of the above columns as the total. Outside of a table - e.g. KPI - this "solution" breaks. This is disappointing.

100% agree. Ridiculous that a BI tool would behave this way. 

It's so easy to do in Tableau.

I'm totally agréé with you. In a visual table or others, the total row should have to be correct anyway the formula measure. Like in Excel with pivot table for instance. I would like PBI to correct this point to focus my reflection on the row ans not on the total.

jfsanchez
Frequent Visitor

.

bibee
Regular Visitor

Hello @Greg_Deckler  @Ashish_Mathur @Otto_Luvpuppy , 

 

I am lookin at this thread , to solve a similar problem and I tried the Sumx soln as well has HASONEVALUE but overall sum I am still not able to sum up to expected. Can you please Advise what wrong with the my formula . 

Source Data(Calculation in Excel)  :

DistriEAN Local Actual ForecastMAEWeightMAPE x WeightWMAPE
BD4740011550719.2517.564429%3.1779%0.28%16%
BD47400179240116.0995122.7436%19.1665%1.10% 
BD4740017934934.44125.1486327%5.6858%1.53% 
BD30142600078362.00164.536926127%0.3304%0.42% 
BD30142600078674.39245.48000125%0.7251%0.18% 
BD30142607810331.33445.009387275%0.2203%0.61% 
BD490243004423332.4667230.182357%5.3598%0.38% 
BD490243004425726.000317.2386234%4.2923%1.45% 
BD4902430102247227.6804247.69159%37.5871%3.30% 
BD4902430102254100.3049128.697228%16.5591%4.69% 
BD490243011865116.1025112.5100522%2.6583%0.59% 
BD490243018893713.6665320.0886947%2.2562%1.06% 
BD4902430188951128.7106727%1.9810%0.54% 
      16% 

 

Ouput in PowerBI :

bibee_0-1660592847603.png

 

Using SUMX:

MAPE * Weight =
VAR _MAE = CALCULATE(IF(temp_ean[Measure_Actual]=0,1,ABS(temp_ean[Measure_Actual]-temp_ean[Measure_Forecast])/temp_ean[Measure_Actual]))
VAR _WEIGHT = DIVIDE(temp_ean[Measure_Actual] , temp_ean[TotalActual])
RETURN

SUMX(VALUES(temp_ean[Distro]) , _MAE * _WEIGHT)

Using HASONEVALUE:
Measure1 =
VAR __table = SUMMARIZE(temp_ean,temp_ean[Distro],"__value",temp_ean[MAPE * Weight])
RETURN
IF (
    HASONEVALUE(temp_ean[Distro]),
    temp_ean[MAPE * Weight],
    SUMX(__table,[__value])
    )

Any help is appreciated!

Thanks

Hi,

It is very difficult to help you like this.  Describe the question and share the download link of your PBI file.  Also share the download link of your MS Excel file with your formulas there so that your logic can be understood and translated into the DAX language.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Buen dia, me considero nuevo en esto, 

si me puede ayudar por favor, tengo la siguiente tabla

jfsanchez_0-1660785094150.png

los archivos estan relacionados entre si.

1.- el MON. PPTO lo obtengo de un archivo, de la columna de totales

2.- el MON. REAL lo obtengo de otro archivo, de la columna de totales

3.- la diferencia la obtengo de la resta entre estas dos columnas de diferentes archivos usando esta medida -- 

DIFERENCIA = SUM('PRESUPUESTO DIRECTO'[MON_TOTAL]) - SUM('COSTO DIRECTO'[MON_TOTAL])
(si se pudiera una solucion desde esta medida para que me sume solo los positivos seria excelente)
 
el problema es que quiero obtener una columna mas con la suma unicamente de los valores positivos, que es el dato de la columna sin color en la imagen, el resultado de la medida es el correcto pero no el esperado por mi persona, ya que la medida esta haciendo su funcion lineal. 
esta es la medida usada
PRESUPUESTO POR EJECUTAR = if(SUMX('PRESUPUESTO DIRECTO','PRESUPUESTO DIRECTO'[MON_TOTAL]) > sum('COSTO DIRECTO'[MON_TOTAL]),SUMX('PRESUPUESTO DIRECTO','PRESUPUESTO DIRECTO'[MON_TOTAL]) - SUM('COSTO DIRECTO'[MON_TOTAL]))
 
ME PODRIA AYUDAR DANDOME UNA SOLUCION PARA QUE EL TOTAL ME SUME UNICAMENTE LOS VALORES POSITIVOS, YA REALICE VARIAS MEDIDAS PERO NINGUNA ME DA EL RESULTADO ESPERADO,  ESPERO DARME A ENTERDER

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.