Forum Discussion

santoshlearner2's avatar
santoshlearner2
Resolver II
7 months ago
Solved

Total is wrong when categorised is vendor wise

Dear All,

Measure used: 

Dax measures for total sales is 

CALCULATE(sum(table1(sales), DATESMTD(DIMDatesQ[EOM])). I tried using sumx but gives and error.

 

Issue: When I use only the month and the total measure, it shows correct, but as soon as I put vendor option in the matrix and I sum the total of all the vendors does not match the one displayed.  The irony is the total is correct, but summation of all the total of the vendors is wrong please refer table below.

When i show like this it is correct.

MonthActual Total which is correct. Matrix shows the same, but refer pls another table below. Table A 
Dec-255956
Nov-255761
Oct-256217
Sep-255717
Aug-256592

Now the issue is  when i show like this in the matrix. Column highligted in Red is correct, but the

Table A

MonthDistributor 1Distributor 2Distributor 3Distributor 4Distributor 5Total Displayed in matrix ( Which is correct)             (Column H )Total of all the ones highlighted in red comes to mentioned below (Column I ) This is incorrectDifference from Column H (actual)
Dec-251,6841372,3131,436795,9565,649 (1684+137+2313+1436+79)307
Nov-251610140228313279657615,456 (1610+140+2283+1327+96)305
Oct-2517401432461142511162175,880 (1740+143+2461+1425+111)337
Sep-2515671282259133912157175,414 (1567+128+2259+1339+121)303
Aug-2518461322527162012965926,254 (1846+132+2527+1620+129)338

 

  • I have data which contains monthly sales values, in this you have the month the product name (unique) / the vendor code / and the sales amount. Table 1
  • In another table I have the dimcodes where it bifurcates the product further into categories. Table 2
  • In the third table I have the dimcodes for Type of vendors. Table 3

Table 1

MonthProductVendor codeSales
31-12-2025product 1vendor 1100
31-12-2025product 2vendor 2200
31-12-2025product 3vendor 3300
31-12-2025product 4vendor 4400
    
31-12-2025product 1vendor 4500
31-12-2025product 2vendor 3600
31-12-2025product 3vendor 2700
31-12-2025product 4vendor 1800
    
31-12-2025product 4vendor 3200
31-12-2025product 3vendor 1250
31-12-2025product 2vendor 4300
31-12-2025product 1vendor 2600

 

Table 2

category for productsMain Category
product 4Books
product 3Books
product 2Pens
product 1Pens

 

Table 3

category for VendorsMain Category
vendor 3Cat 2
vendor 1Cat 1
vendor 4Cat 2
vendor 2Cat 3

 

 

Dax measures for total sales is 

CALCULATE(sum(table1(sales), DATESMTD(DIMDatesQ[EOM])). I tried using sumx but gives and error.

 

Requesting your assitance please

Warm Regards

Santosh

 

 

 

  • santoshlearner2 Please check which MonthDate-field are you using in the report. 
    One common mistake is to have a DateDimTable, but use the Date-field from a transaction table.
    Best practice: Use the DateDimTable Field at the report 

    Alternate solution if you are using the Table1[Month] field at the report: 

    Sales Amount MTD :=
    VAR LastVisibleDate =
        MAX ( 'Table1'[Month] )
    VAR CurrentYear =
        YEAR ( LastVisibleDate )
    VAR CurrentMonth =
        MONTH ( LastVisibleDate )
    VAR SetOfDatesMTD =
        FILTER (
            ALL ( 'Table1'[Month] ),
            'Table1'[Month] <= LastVisibleDate
                && YEAR ( 'Table1'[Month] ) = CurrentYear
                && MONTH ( 'Table1'[Month] ) = CurrentMonth
        )
    VAR Result =
        CALCULATE (
            SUM ( Table1[Sales] ),
            SetOfDatesYTD,
            KEEPFILTERS ( 'table 1'[Vendor code] )
        )
    RETURN
        Result




    If this response was helpful in any way,
    I’d gladly accept a kudo.

    Please mark it as the correct solution.
    It helps other community members find their way faster.

  • Hi,

    Thanks for everyone for assisting. I truly appreciate, But the response is not working. I cannot upload any file due to restrictions. Closing this, Thanks for every one.

13 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi santoshlearner2,

     

    Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to pcoley , krishnakanth240 , Ashish_Mathur and Rajavenkatesh  for prompt and helpful responses.

    Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists please share the PBIX file to help further.

     

    Best regards,
    Prasanna Kumar

     

  • Hello santoshlearner2 

     

    for MTD try with below DAX Code

     

    MTD Sales =
    SUMX (
    VALUES ( Table1[Vendor code] ),
    CALCULATE (
    SUM ( Table1[Sales] ),
    DATESMTD ( DimDatesQ[EOM] )
    )
    )

     


    If my response helped you, please consider clicking
    Accept as Solution and giving it a Like 👍 – it helps others in the community too.

     
    Your code is not working reason is 

    DATESMTD() redefines the filter context

    At Total level, Power BI recalculates the measure once

    At Vendor level, it recalculates separately per vendor

    Total ≠ Sum of vendors when time intelligence is involved

     


    Thanks,


    Connect with me on:

    LinkedIn

     

    • santoshlearner2's avatar
      santoshlearner2
      Resolver II

      Hi,

       

      I appreciate your quick reply, but getting the same error, am i doing something wrong.

       

      Measure 1 : Total Sales = CALCULATE(SUMX(Table 1( Sales))

       

      Measure 2: Total Sales MTD = CALCULATE([Total Sales],DATESMTD (DIMDatesQ[Date]))

      Measure 3: Total Inflows by distributors=  SUMX ( VALUES (table 1 ( vendor code),  CALCULATE ([Total Sales MTD], DATESMTD ( DIMDatesQ[Date]))) )

  • Hi santoshlearner2 

    This is a classic Power BI / DAX context issue, and your observation is 100% correct. Let me break it down clearly and then give you the exact fix.

    Problem Summary (Why this is happening):
    You are seeing this behavior:
    Month level total -> Correct
    Vendor-wise values -> Individually look fine
    Sum of vendor rows ≠ Month total -> Mismatch
    This means Power BI is not actually summing vendor rows to get the total.

    Instead, Power BI is re-calculating the measure at total level with a different filter context.

    • This is NOT a data issue
    • This is NOT a visual bug
    • This is a DAX filter-context + relationship issue

    Root Causes (There are 3 working together):

    1. Incorrect use of DATESMTD
    2. Dimension tables are filtering the same fact table
    3. Matrix totals are recalculated, not summed

    The Correct & Safe Solution:
    Step 1: Create a Base Measure (VERY IMPORTANT)
         Total Sales = SUM (Table1[Sales])
    Note: Never mix aggregation + time intelligence directly.

    Step 2: Correct MTD Measure (Vendor-safe)
         MTD Sales = CALCULATE([Total Sales],DATESMTD (DIMDatesQ[Date]))
    Note: Use Date column, NOT EOM column.

    Step 3: Force Correct Vendor Granularity (Fix Totals)
    If totals still mismatch, use SUMX pattern:
    ---DAX---
    MTD Sales (Correct)=
    SUMX (
    VALUES ( Table1[Vendor code] ),
    CALCULATE (
    [Total Sales],
    DATESMTD ( DIMDatesQ[Date] )
    )
    )
    ---DAX---

    This is the KEY fix

    • Now Power BI adds vendor-level values.
    • Total = Sum of visible vendors
    • Your Column H and Column I will match perfectly

    =================================================================
    Did I answer your question? Mark my post as a solution! This will help others on the forum!

    Appreciate your Kudos!!

    Jaywant Thorat | MCT | Data Analytics Coach
    LinkedIn: https://www.linkedin.com/in/jaywantthorat/
    Join #MissionPowerBIBharat: https://shorturl.at/5ViW9
    #MissionPowerBIBharat
    LIVE with Jaywant Thorat

    • santoshlearner2's avatar
      santoshlearner2
      Resolver II

      Dear Sir, 

      Amazing, thank you for such detailed reply, i did that but i am getting the same error. Am i doing something wrong. The measures which i created it as follows

      Measure 1 : Total Sales = CALCULATE(SUMX(Table 1( Sales))

       

      Measure 2: Total Sales MTD = CALCULATE([Total Sales],DATESMTD (DIMDatesQ[Date]))

      Measure 3: Total Inflows by distributors=  SUMX ( VALUES (table 1 ( vendor code),  CALCULATE ([Total Sales MTD], DATESMTD ( DIMDatesQ[Date]))) )

       

  • Try this
    VAR IsSingleVendor =
    HASONEVALUE(Table3[Vendor Category])
    RETURN
    CALCULATE(
    SUM(Table1[Sales]),
    DATESMTD(DIMDatesQ[Date]),
    IF(
    IsSingleVendor,
    VALUES(Table3[Vendor Category]),
    ALL(Table3[Vendor Category])
    )
    )

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi @santoshlearner2,

     

    Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists please share the PBIX file to help further.

     

    Best regards,
    Prasanna Kumar

    • santoshlearner2's avatar
      santoshlearner2
      Resolver II

      Hi,

      Thanks for everyone for assisting. I truly appreciate, But the response is not working. I cannot upload any file due to restrictions. Closing this, Thanks for every one.