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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mclawler
Helper III
Helper III

Calculate Count & Sum to 1 Row of a Matrix Table Only

Hi there, I'm going to try and explain this as simply as possible.  I have this matrix table built:

 

mclawler_0-1721958675211.png

From a separate data table, I need to to account for this negative count and negative sum from the Auto row of the above table.

 

mclawler_1-1721958777420.png

 

I can't figure out how to incorporate this negative count/sum into the Auto group row ONLY.  I can't seem to isolate the Auto row.  Any measure I create affects all of the other rows (Marine, Motorcycle, Quad, RV/ Shareback) also, no matter what I try.  

 

Thank you for your time, this forum has helped me so much in the past!  

 

 

2 ACCEPTED SOLUTIONS

Hi @mclawler,

The condition should be placed before the calculation. I didn't understand the logic of the transformation from 35 to 345, but I can still demonstrate the logic for manipulating the "Auto" category versus other categories.

The measure can use the following logic:
Test =
IF(
SELECTEDVALUE('Table'[Category]) = "Auto",
SUM('Table'[Value]) - SUM('Table 2'[Value]),
SUM('Table'[Value])
)

Ritaf1983_0-1722055960808.png

The pbix with the example is attached

 

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Hi @mclawler 
Modify the formula to :

Test =
VAR AdjustedTable =
    ADDCOLUMNS(
        VALUES('Table'[Category]),
        "AdjustedValue",
        IF(
            [Category] = "Auto",
            CALCULATE(SUM('Table'[value])) - CALCULATE(SUM('Table 2'[Value])),
            CALCULATE(SUM('Table'[value]))
        )
    )
RETURN
SUMX(AdjustedTable,[AdjustedValue])
it will fix the total 
Ritaf1983_0-1722306868482.png

The updated pbix is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

11 REPLIES 11
mickey64
Super User
Super User

For your reference.

 

Measure = SUMX(FILTER('Table','Table'[#]<0 && 'Table'[Column]="Auto"),'Table'[#])

This is what I have so far but it's adding too many to Auto, all other rows still count normal as they should but instead of -35 it's like -345 to Auto.  It's almost like it's now disregarding my DateTable slicer for the Collateral count. 

 

mclawler_0-1722024361627.png

 

 

SUMX(OutstandingBalancesMaster,IF(OutstandingBalancesMaster[Type Description Column] = "Auto",OutstandingBalancesMaster[OB_Count] + 'PwBi CIPL'[SoldFeesCount],OutstandingBalancesMaster[OB_Count]))
 
Let me put it another way to see if you can replicate on your desktop
 
Table 1 :
Auto = 23733
Marine = 2
Motorcycle = 7
Quad = 2
RV = 102
 
Table 2:
Collateral = 35
 
End result needs to be Table 3:
Auto = 23768
Marine = 2
Motorcycle = 7
Quad = 2
RV = 102
Ritaf1983
Super User
Super User

Hi @mclawler 
You can use selectedvalue function , like :
if(selectedvalue(category) = "Auto", abc,xyz)
guide for using selectedvalue() here :

https://www.sqlbi.com/articles/using-the-selectedvalue-function-in-dax/

For more detailed suggestion 

please share a pbix or some dummy data that keeps the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

It won't allow me to use the IF statement and I'm not sure why?  Maybe cause I'm building a measure and not a column?  

 

This is what I have so far but it's adding too many to Auto, all other rows still count normal as they should but instead of -35 it's like -345 to Auto.  It's almost like it's now disregarding my DateTable slicer for the Collateral count. 

 

mclawler_1-1722024457273.png

 

 

 

SUMX(OutstandingBalancesMaster,IF(OutstandingBalancesMaster[Type Description Column] = "Auto",OutstandingBalancesMaster[OB_Count] + 'PwBi CIPL'[SoldFeesCount],OutstandingBalancesMaster[OB_Count]))
 
Let me put it another way to see if you can replicate on your desktop
 
Table 1 :
Auto = 23733
Marine = 2
Motorcycle = 7
Quad = 2
RV = 102
 
Table 2:
Collateral = 35
 
End result needs to be Table 3:
Auto = 23768
Marine = 2
Motorcycle = 7
Quad = 2
RV = 102

 

 

Hi @mclawler,

The condition should be placed before the calculation. I didn't understand the logic of the transformation from 35 to 345, but I can still demonstrate the logic for manipulating the "Auto" category versus other categories.

The measure can use the following logic:
Test =
IF(
SELECTEDVALUE('Table'[Category]) = "Auto",
SUM('Table'[Value]) - SUM('Table 2'[Value]),
SUM('Table'[Value])
)

Ritaf1983_0-1722055960808.png

The pbix with the example is attached

 

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

I do have a new issue however, my Total row isn't accurate:

mclawler_0-1722292088428.png

 

The Total row should = 23,865

 

Please advise 🙂

Hi @mclawler 
Modify the formula to :

Test =
VAR AdjustedTable =
    ADDCOLUMNS(
        VALUES('Table'[Category]),
        "AdjustedValue",
        IF(
            [Category] = "Auto",
            CALCULATE(SUM('Table'[value])) - CALCULATE(SUM('Table 2'[Value])),
            CALCULATE(SUM('Table'[value]))
        )
    )
RETURN
SUMX(AdjustedTable,[AdjustedValue])
it will fix the total 
Ritaf1983_0-1722306868482.png

The updated pbix is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Any idea why this measure would be dropping the Motorcycle row data?  It keeps the Auto & RV data but drops Motorcycle row data:

 

mclawler_2-1722445185918.png

mclawler_3-1722445389353.png

 

This is the Measure I'm using:

VAR AdjustedTable =
    ADDCOLUMNS(
        VALUES('PwBi LoanData'[Product (groups)]),
        "AdjustedValue",
        IF('PwBi LoanData'[Product (groups)] = "Auto",
    CALCULATE(TOTALYTD(SUM(AutoLoanMatrix[AmountAdvanced]),'DateTable'[Date])),
    CALCULATE(TOTALYTD(SUM('PwBi LoanData'[Amount Booked]),'DateTable'[Date]))))
   
RETURN
SUMX(AdjustedTable,[AdjustedValue]) + 0


Does the same thing with PreviousMonth/Year etc... 

That worked perfectly, absolutely amazing.  Thank you so much! 

Happy to help 🙂

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

It worked!!!!!!  Thank you so much!!!! 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.