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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Applicable88
Impactful Individual
Impactful Individual

Different Totals after selection of bar chart

Hello,

I have a rather conceptual question, about an acutal problem.

I have a measure where I make a calculation based on two different table variables tables. 

Conceptual it looks like that:

Measure =

var Table 1 = Calculatetable....

Var Table 2 = Calculatetable ..

return

calculate ( sum ( Sales ), Except (Table1, Table2)

Everything is great so far. I put the Date from Table 1 into a table visual and the Measure as well. For every date I get the correct Sales per day.

But if I drag the same date and measure into a bar chart, and for instance clikcing on two or three date bars its also filters the right dates in the table visual. But strangely the total sales isn't correct. 

Is there something I can do to modify the last calculate function to get the context right? Why every sales per day is right, but not the totals in the table visual after I click on the bars?

 

I hope someone knows what happened here.

Cheers. 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Applicable88 

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.

In your sample , you just need to create one more measure to solve the problem .

Measure 2 = SUMX(Table1,[Measure])

The final result is as shown :

Ailsamsft_0-1645151864131.png

I have attached my pbix file , you can refer to it .

 

Best Regard

Community Support Team _ Ailsa Tao

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

View solution in original post

Hi @Applicable88 
I have loaded the data from GoogleDrive and realized some mistakes in the formulas. You can use the same link to re-download the file but with updates.
I will recap all over again. The report now looks like this
Untitle.png
No changes in the data model
The code of the Ranking column in the date table

Working Day Number = 
VAR WrkingDay =
    'Date'[Working Day]
VAR WorkingDates =
    CALCULATETABLE (
        VALUES ( 'Date'[Date] ),
        REMOVEFILTERS ( 'Date' ),
        'Date'[Working Day]
    )
VAR Result =
    RANKX ( WorkingDates, 'Date'[Date], , ASC )
RETURN
    Result 


The Previous Working Day Column should be in the shipping table not in the preparation table. Here is the code

Previous Working Day = 
VAR CurrentWorkingDayNumber =
    RELATED ( 'Date'[Working Day Number] )
VAR PreviousWorkingDayNumber =
    CurrentWorkingDayNumber - 1
VAR PreviousWorkingDayDate =
    LOOKUPVALUE (
        'Date'[Date],
        'Date'[Working Day Number],
        PreviousWorkingDayNumber,
        'Date'[Working Day],
        TRUE
    )
RETURN
    PreviousWorkingDayDate 

Finally the code of the tricky measure is

Measure = 
SUMX (
    Shipping,
    VAR PreviousWorkingDay1 =
        Shipping[Previous Working Day]
    VAR ShippedAmount1 =
        CALCULATE ( SUM ( Shipping[Sales] ) )
    VAR PrevWorkDayAmountInPrep1 =
        CALCULATE (
            SUM ( Preparation[Sales] ),
            REMOVEFILTERS ( 'Date' ),
            'Date'[Date] >= PreviousWorkingDay1,
            USERELATIONSHIP ( Shipping[OrderNo.], Preparation[OrderNo.] )
        )
    VAR Result1 =
        ShippedAmount1 - PrevWorkDayAmountInPrep1
    RETURN
        Result1
)

The reason we need to iterate over the shipping table is to provide correct results at the total level which I forgot to do it in the first revision of the file.
Actually we are plying with the filter context using calculate to remove the last working day transactions. This exactly what is expected to happen at the grand total level, only  the last working day transactions are removed and the other dates are simply ignored. Therefore in order to force the engine to consider the caculation date by date and then aggregate the values, we need to use SUMX and iterate over the Shipping table.

View solution in original post

15 REPLIES 15
Anonymous
Not applicable

Hi @Applicable88 

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.

In your sample , you just need to create one more measure to solve the problem .

Measure 2 = SUMX(Table1,[Measure])

The final result is as shown :

Ailsamsft_0-1645151864131.png

I have attached my pbix file , you can refer to it .

 

Best Regard

Community Support Team _ Ailsa Tao

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

Hi  @Anonymous, thanks for your explanation. But specifically in that measure, what is the context of the total row / column to make it return "wrong" value? Is it maybe that the function works for every row, because every cell get a new calculation for each row, but the total is actually calculated through whole table? 

I'm really curious what actually happened here in this case. 

tamerj1
Community Champion
Community Champion

Hi @Applicable88 
Did you try FILTER instead of CALCULATETABLE or you need it to play with the filter context?

Hello @tamerj1 ,

 

the complete Measure actually looks like this: 

Calculated Tables = 
Var _CurrentDate = 
Max ( ShippingTable[Date] )

Var _LatestPreparationDate = 
Calculate ( 
    Max ( PreparationTable[Date] ),
    PreparationTable[Date] < _CurrentDate 
)

Var _Orders_S =
Calculatetable (
    Values ( ShippingTable[OrderNo] ) , 
    ShippingTable[Status] = "S",
    
)

Var _Orders_P =
Calculatetable (
    Values ( PreparationTable[OrderNo] ) , 
    PreparationTable[Status] = "P",
PreparationTable[Date] = _LatestPreparationDate ) Return Calculate ( Count ( ShippingTable[OrderNo] ), Except ( _Orders_S, _Orders_P ) )

 I tried to do it with FILTER instead of CALCULATETABLE. But it gives me a wrong result. 

Also in the Filterexpression of FILTER. I cannot write  "PreparationTable[Date] = _LatestPreparationDate.

Instead I need to write: 

Var _Orders_P = Filter( Values ( PreparationTable[OrderNo] ) , Calculate (Max( PreparationTable[Status])) = "P",
Calculate (Max (PreparationTable[Date] ))= _LatestPreparationDate )

 

Maybe you have an different idea. 

Best. 

@Applicable88 

Too many nested CALCULATE's  it is almost impossible to understand the behavior without looking at the whole picture. Seems to me this measure removes the last "order number". Can you please explain what are you trying to calculate? 

I did make a small sample data, if its better to understand the problem:

https://drive.google.com/drive/folders/1Fq7YwtEsKhix7HEY2IL-8o9UA803-78v?usp=sharing

 

I do have the right Sales amount for every day in the table visual, but the total is not correct:

Applicable88_1-1645109059543.png

Neither when filtering with Table1[Date] in bar chart:

 

Applicable88_2-1645109120727.png

 

 

 

 

 

Okay, @tamerj1 , I try to explain what I trying to reach here:

Basically I have two not connected tables:

The shipping table: 

OrderNo. Date  Status  Sales
1111 10/01/2022  1000
1112 10/01/2022  1000
1113 10/01/2022  1000
1119 10/01/2022  1500
1118 10/01/2022  1500
1000 10/01/2022  3000

 

The preparation table:

OrderNo. Date  Status  Sales
1111 09/01/2022 P 1000
1112 09/01/2022 P 1000
1113 09/01/2022 P 1000
1114 09/01/2022 P 8000
1115 09/01/2022 P 10000
1116 09/01/2022 P 1500

 

Everyday at work there is a table record from last working day. This table consist order which were already prepard for shipping, but never made it on the shipping truck so far. If Order No. 1253 were prepared and didn't got shipped today its on the preparation table. It stays in the preparation table as long as it got finally shipped out. So the orderNo. are not distinct on that table, in this case the orderNo. will get a new entry with an updated preparation date. 

 

The shipping table is a record of orders which were shipped on the stated shipping dates. 

So to correctly measure the performance of the shipping department, we always need to deduct those orders from the shipping table, which were already on the preparation list on the "last workday." I emphasize last working day, because Friday is the last working day from Monday point of view. 

 

Specifically for above example: Total Shipped value performance of 10th january is  9000.

But order no. 1111,1112 and 1113 are orders which were on the preparation table the last working day before, hence are not belonging to the performance of 10th January. 

The real performance value of 10th January is 6000.

 

The measure above is actually already given me the right sales values per shipping date. 

But when I select the shipping dates in a bar chart visual its not filtering the right total value in the table visual:

 

Applicable88_3-1645088938449.png

 

375105 + 554310 = 929.415

The Totals are not right. 

Hope you might have an solution to this. 

 

 

 

Hi @Applicable88 
Here is the sample file with the solution https://www.dropbox.com/t/bCTwHBpfSNMVMYS7
Please test it with complete data and let me know if it works
First you need to have a date table "Included in the file" then you need to set relationships between tables as this
Untitled.png
In order to restore the previous working day, you need to create two calculated columns. One in the date table 

Working Day Number = 
VAR WrkingDay =
    'Date'[Working Day]
VAR WorkingDates =
    CALCULATETABLE (
        VALUES ( 'Date'[Date] ),
        REMOVEFILTERS ( 'Date' ),
        'Date'[Working Day]
    )
VAR Result =
    IF (
        WrkingDay,
        RANKX ( WorkingDates, 'Date'[Date], , ASC )
        )
RETURN
    Result 

and one in the Preparation table

Previous Wrking Day = 
VAR CurrentWorkingDayNumber =
    RELATED ( 'Date'[Working Day Number] )
VAR PreviousWorkingDayNumber =
    CurrentWorkingDayNumber - 1
VAR PreviousWorkingDayDate =
    LOOKUPVALUE (
        'Date'[Date],
        'Date'[Working Day Number],
        PreviousWorkingDayNumber
    )
RETURN
    PreviousWorkingDayDate 

Then your measure will be 

Measure = 
VAR PreviousWorkingDay =
    MAX ( Preparation[Previous Wrking Day] )
VAR ShippedAmount =
    SUM ( Shipping[Sales] )
VAR PrevWorkDayAmountInPrep =
    CALCULATE (
        SUM ( Preparation[Sales] ),
        REMOVEFILTERS ( 'Date' ),
        USERELATIONSHIP ( Shipping[OrderNo.], Preparation[OrderNo.] ),
        VALUES ( Shipping[OrderNo.] )
    )
VAR Result =
    ShippedAmount - PrevWorkDayAmountInPrep
RETURN
    Result

I guess it should work. Please check and let me know if further modifications are required.

@tamerj1 thank you so much for your effort. But did you get the same results? I downloaded the pbix of yours and there is only one value displayed:

Applicable88_0-1645132655392.png

 

oic, now... you didn't use the sample data within my pbix file. I created a larger sample file to make it more realistic.

You used the two example tables above, which only display for one day.  

Does it also works when there are more than one day involved?

Cheers

Hi @Applicable88 
I have loaded the data from GoogleDrive and realized some mistakes in the formulas. You can use the same link to re-download the file but with updates.
I will recap all over again. The report now looks like this
Untitle.png
No changes in the data model
The code of the Ranking column in the date table

Working Day Number = 
VAR WrkingDay =
    'Date'[Working Day]
VAR WorkingDates =
    CALCULATETABLE (
        VALUES ( 'Date'[Date] ),
        REMOVEFILTERS ( 'Date' ),
        'Date'[Working Day]
    )
VAR Result =
    RANKX ( WorkingDates, 'Date'[Date], , ASC )
RETURN
    Result 


The Previous Working Day Column should be in the shipping table not in the preparation table. Here is the code

Previous Working Day = 
VAR CurrentWorkingDayNumber =
    RELATED ( 'Date'[Working Day Number] )
VAR PreviousWorkingDayNumber =
    CurrentWorkingDayNumber - 1
VAR PreviousWorkingDayDate =
    LOOKUPVALUE (
        'Date'[Date],
        'Date'[Working Day Number],
        PreviousWorkingDayNumber,
        'Date'[Working Day],
        TRUE
    )
RETURN
    PreviousWorkingDayDate 

Finally the code of the tricky measure is

Measure = 
SUMX (
    Shipping,
    VAR PreviousWorkingDay1 =
        Shipping[Previous Working Day]
    VAR ShippedAmount1 =
        CALCULATE ( SUM ( Shipping[Sales] ) )
    VAR PrevWorkDayAmountInPrep1 =
        CALCULATE (
            SUM ( Preparation[Sales] ),
            REMOVEFILTERS ( 'Date' ),
            'Date'[Date] >= PreviousWorkingDay1,
            USERELATIONSHIP ( Shipping[OrderNo.], Preparation[OrderNo.] )
        )
    VAR Result1 =
        ShippedAmount1 - PrevWorkDayAmountInPrep1
    RETURN
        Result1
)

The reason we need to iterate over the shipping table is to provide correct results at the total level which I forgot to do it in the first revision of the file.
Actually we are plying with the filter context using calculate to remove the last working day transactions. This exactly what is expected to happen at the grand total level, only  the last working day transactions are removed and the other dates are simply ignored. Therefore in order to force the engine to consider the caculation date by date and then aggregate the values, we need to use SUMX and iterate over the Shipping table.

Sorry I didn't notice that you have shared a file

Sorry @Applicable88,  I was not available. I will read your reply and get back to you.

amitchandak
Super User
Super User

@Applicable88 , In such cases,where you have two tables. You should use common date and dimension tables for axis,row,column and group by

 

Try to be in star schema

https://docs.microsoft.com/en-us/power-bi/guidance/star-schema

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak, Table2 consist of rows which should be except in Table1. I got right sum per date. Only after selection its not sum up value right. I don't think the data model is the problem. 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.