Forum Discussion

sajohnson05's avatar
sajohnson05
Frequent Visitor
1 year ago
Solved

Matrix Table not giving the correct total amount

I have created the below meaure that is being implemented in a Matrix table that the column vendor is being pulled from a helper table called Vendor_template which has specific vendors as rows along with a total row.  The measure gives me the correct amount for each vendor but when it comes to the total row it is not adding up correctlty.  I have added a screenshot below of the issue along with the full measure.  Any help would be greatly appreciate




TotalSellPrice_BillsReceived =
 
VAR SelectedYear = VALUE(SELECTEDVALUE('Calendar'[Year]))
VAR CurrentVendor = SELECTEDVALUE(Vendor_Template[Vendor Reference])

-- Functionally simulate fiscal start and end based on majority overlap with SelectedYear
VAR GetFiscalDates =
    ADDCOLUMNS (
        VALUES ( VendorProjectType[Manufacturer] ),
        "FYStart",
            VAR VendorName = VendorProjectType[Manufacturer]
            VAR FiscalStartMonth =                
                    LOOKUPVALUE (
                    VenChampTable[FYStartMonth],
                    VenChampTable[Vendor],
                    VendorName
                    )                
            VAR StartOption1 = DATE ( SelectedYear - 1, FiscalStartMonth, 1 )
            VAR StartOption2 = DATE ( SelectedYear, FiscalStartMonth, 1 )
            VAR MidPoint1 = StartOption1 + 180
            VAR FiscalYearStart =
                IF (
                    YEAR ( MidPoint1 ) = SelectedYear,
                    StartOption1,
                    StartOption2
                )
            VAR FiscalYearEnd = EOMONTH ( FiscalYearStart, 11 )
            RETURN FiscalYearStart,
        "FYEnd",
            VAR VendorName = (VendorProjectType[Manufacturer])
            VAR FiscalStartMonth =            
                LOOKUPVALUE (
                    VenChampTable[FYStartMonth],
                    VenChampTable[Vendor],
                    VendorName
                    )                
            VAR StartOption1 = DATE ( SelectedYear - 1, FiscalStartMonth, 1 )
            VAR StartOption2 = DATE ( SelectedYear, FiscalStartMonth, 1 )
            VAR MidPoint1 = StartOption1 + 180
            VAR FiscalYearStart =
                IF (
                    YEAR ( MidPoint1 ) = SelectedYear,
                    StartOption1,
                    StartOption2
                )
            RETURN EOMONTH ( FiscalYearStart, 11 )
    )

RETURN
IF (
    CurrentVendor = "Total",
    SUMX (
        GetFiscalDates,
        VAR ThisVendor = [Manufacturer]
        VAR StartDate = [FYStart]
        VAR EndDate = [FYEnd]
        RETURN
            CALCULATE (
                SUM ( VendorProjectType[SellPrice] ),
                VendorProjectType[Source] = "Bills Received",
                VendorProjectType[Manufacturer] = ThisVendor,
                VendorProjectType[Date] >= StartDate,
                VendorProjectType[Date] <= EndDate,
                REMOVEFILTERS ( 'Calendar' )
            )
    ),
    VAR FiscalStartMonth =    
        LOOKUPVALUE (
            VenChampTable[FYStartMonth],
            VenChampTable[Vendor],
            CurrentVendor
            )        
    VAR StartOption1 = DATE ( SelectedYear - 1, FiscalStartMonth, 1 )
    VAR StartOption2 = DATE ( SelectedYear, FiscalStartMonth, 1 )
    VAR MidPoint = StartOption1 + 180
    VAR FiscalYearStart =
        IF (
            YEAR ( MidPoint ) = SelectedYear,
            StartOption1,
            StartOption2
        )
    VAR FiscalYearEnd = EOMONTH ( FiscalYearStart, 11 )
    RETURN
        CALCULATE (
            SUM ( VendorProjectType[SellPrice] ),
            VendorProjectType[Source] = "Bills Received",
            VendorProjectType[Manufacturer] = CurrentVendor,
            VendorProjectType[Date] >= FiscalYearStart,
            VendorProjectType[Date] <= FiscalYearEnd,
            REMOVEFILTERS ( 'Calendar' )
        )
)

 

  • It would have been easier for us to provide a solution had you provided a sample pbix (confidential data removed). But just given what's available, here's what I would try: Keep a separate measure for vendor level only. Create another measure to return the total

    TotalSellPrice_BillsReceived - Vendor and Total =
    IF (
        SELECTEDVALUE ( Vendor_Template[Vendor Reference] ) = "Total",
        SUMX (
            VALUES ( VendorProjectType[Manufacturer] ),
            [TotalSellPrice_BillsReceived - vendor]
        ),
        [TotalSellPrice_BillsReceived]
    )
    

     

7 Replies

  • Hi,

    Share the download link of the PBI file.  Show the problem and expected result there.

  • It would have been easier for us to provide a solution had you provided a sample pbix (confidential data removed). But just given what's available, here's what I would try: Keep a separate measure for vendor level only. Create another measure to return the total

    TotalSellPrice_BillsReceived - Vendor and Total =
    IF (
        SELECTEDVALUE ( Vendor_Template[Vendor Reference] ) = "Total",
        SUMX (
            VALUES ( VendorProjectType[Manufacturer] ),
            [TotalSellPrice_BillsReceived - vendor]
        ),
        [TotalSellPrice_BillsReceived]
    )
    

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sajohnson05 ,

    Thank you for reaching out to the Microsoft fabric community forum.

     

    As correctly mentioned by Greg_Deckler , this is a classic case of the “measure totals” issue in Power BI where total rows in visuals (like matrix tables) don’t aggregate row-level logic correctly due to context differences. While your measure works per vendor, the "Total" row needs special handling. danextian  provided solution separate the measure logic into two parts: one for vendor-level ([TotalSellPrice_BillsReceived - VendorOnly]), and another that uses SUMX over manufacturers to calculate the total row correctly. You can then wrap both in a final measure using an IF condition based on "Total". This ensures accurate totals and preserves your fiscal year logic per vendor.

    Hope this helps. Please reach out for further assistance.

     

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sajohnson05 ,

     

    I wanted to follow up on our previous suggestions. We would like to hear back from you to ensure we can assist you further.

     

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sajohnson05 ,

     

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

     

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sajohnson05 ,

     

    We haven’t received an update from you in some time. Could you please let us know if the issue has been resolved?
    If you still require support, please let us know, we are happy to assist you.

     

    Thank you.