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 September 15. Request your voucher.

Reply
Joop_de_Bont
Frequent Visitor

Counting on row level unique values in MatrixTable

Hi,

I'am new to PowerBI and like to see if what I want is possible.
I have a matrix table with two row levels (Account Manager, Customer) and the count of Unique customer per month. Now I would like to count on row level in a column the total of how many month a customer has placed order(s).

On Account Manager level it should also be 12, but on customer level it could less as see with the last column

 

The question is how do it get this in PowerBI Desktop/Services as show below, any suggestion?

Joop_de_Bont_0-1734615529117.png

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi,audreygerred ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.
Hello,@Joop_de_Bont .I am glad to help you.
First of all, you need to be clear that the value of the Total column in the matrix in Power BI can not be directly modified, it itself as a non-existent data, the system is based on the logic you put into the matrix to perform the calculation of the measurement of simple aggregation operations, if the calculation of the logic of the measurement of SUM, then the total perform the same SUM, if the calculation of the logic of the measurement of DISTINCTCOUNT, then the total of the same DISTINCTCOUNT. If the measure's logic is DISTINCTCOUNT, then total performs the same DISTINCTCOUNT, and it is important to note that the logic of a complex measure is not always passed correctly to the total column, so the value of the total column may be incorrect.
The influence on the value of the total column can be indirectly implemented in the matrix by means of ISINCPOE.
You can get the logic of calculating Total in Power BI's matrix from the following code

vjtianmsft_0-1734676742173.png

Therefore, the total column is determined not to be a value in the row field and column field filtering hierarchy and can be set to a special value (99)

here is my test data.

vjtianmsft_1-1734676827677.png
here is my test measure:

vjtianmsft_2-1734676923318.png

 

 

M_Test = 
VAR _table =
 SUMMARIZECOLUMNS ( 'TestData'[CustomerName], 'MonthTable'[MonthName] )
RETURN
    IF (
        NOT ( ISINSCOPE ( 'TestData'[CustomerName] ) )
            && NOT ( ISINSCOPE ( 'MonthTable'[MonthName] ) ),
        [Total Month],
        COUNTX ( _table,[M_DisCount]  )
    )
Total Month = 
VAR _accountManger =
    MAX ( 'TestData'[AccountManager] )
VAR _discountPerYear =
    CALCULATE (
        DISTINCTCOUNT ( 'TestData'[MonthName] ),
        FILTER ( ALL ( 'TestData' ), 'TestData'[AccountManager] = _accountManger )
    )
RETURN
    _discountPerYear
M_DisCount = DISTINCTCOUNT('TestData'[CustomerName])

 

 


URL:

Solved: help COUNTX - Microsoft Fabric Community


I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
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

Thnx, It looks like what i needed.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi,audreygerred ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.
Hello,@Joop_de_Bont .I am glad to help you.
First of all, you need to be clear that the value of the Total column in the matrix in Power BI can not be directly modified, it itself as a non-existent data, the system is based on the logic you put into the matrix to perform the calculation of the measurement of simple aggregation operations, if the calculation of the logic of the measurement of SUM, then the total perform the same SUM, if the calculation of the logic of the measurement of DISTINCTCOUNT, then the total of the same DISTINCTCOUNT. If the measure's logic is DISTINCTCOUNT, then total performs the same DISTINCTCOUNT, and it is important to note that the logic of a complex measure is not always passed correctly to the total column, so the value of the total column may be incorrect.
The influence on the value of the total column can be indirectly implemented in the matrix by means of ISINCPOE.
You can get the logic of calculating Total in Power BI's matrix from the following code

vjtianmsft_0-1734676742173.png

Therefore, the total column is determined not to be a value in the row field and column field filtering hierarchy and can be set to a special value (99)

here is my test data.

vjtianmsft_1-1734676827677.png
here is my test measure:

vjtianmsft_2-1734676923318.png

 

 

M_Test = 
VAR _table =
 SUMMARIZECOLUMNS ( 'TestData'[CustomerName], 'MonthTable'[MonthName] )
RETURN
    IF (
        NOT ( ISINSCOPE ( 'TestData'[CustomerName] ) )
            && NOT ( ISINSCOPE ( 'MonthTable'[MonthName] ) ),
        [Total Month],
        COUNTX ( _table,[M_DisCount]  )
    )
Total Month = 
VAR _accountManger =
    MAX ( 'TestData'[AccountManager] )
VAR _discountPerYear =
    CALCULATE (
        DISTINCTCOUNT ( 'TestData'[MonthName] ),
        FILTER ( ALL ( 'TestData' ), 'TestData'[AccountManager] = _accountManger )
    )
RETURN
    _discountPerYear
M_DisCount = DISTINCTCOUNT('TestData'[CustomerName])

 

 


URL:

Solved: help COUNTX - Microsoft Fabric Community


I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.


V-tjian,

Thanks for your give option, I will investigate and see if this helps me fixing the problem

joop

Thnx, It looks like what i needed.

audreygerred
Super User
Super User

Hi! You can create 14 measures to achieve this. Create one that is the count of unique customers (this will also serve as your total), then from that measure created for each of your months, then create one for the count of months.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi Audrey,

Thanks for the suggestions, but how does these measure will look like?
(then from that measure created for each of your months, then create one for the count of months.)

Unique Customer Measure I have [Unique Customers = countrows(DISTINCT('Fact Sales'[Customer ID]))]

The first step I already had, but problem is the last bit of the puzzle. 

How does those month measure look like and how do I visualize in my report like my example?


Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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