Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

powerbi - Power BI - Matrix Count Blank Rows

I have created a matrix having data of salesman and their chemist visited.

enter image description here

I have added a count formula

Customer Count = DISTINCTCOUNTNOBLANK('Source Data'[CustomerNameFull])

The total in the above matrix is of the salesman who visited the chemist, along with that I want to calculate the total of chemist that is not visited by a salesman. i.e. the count of the blank. The blank count should be shown along with the total value.

Source File: BI SAS

Expected Output

Below is the expected output that I want. The zero total is the distinct count

enter image description here

Any help would be highly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With the expected result in place I propose the following measures. One to count the distinct unvisited chemists for the selected salesman/salesmen:

Unvisited Chemists := 
VAR _customerCount = CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Source Data'[CustomerNameFull] ) , ALLSELECTED ( Dates ) )
VAR _visitedCount = [Customer Count]
RETURN _customerCount - _visitedCount

And one to format the matrix:

Customer Count w/ Unvisited = 
IF ( [Customer Count] <> BLANK () ,
    SWITCH ( 
        TRUE (), 
        NOT ISINSCOPE ( 'Source Data'[CustomerNameFull] ) && ISINSCOPE ( Dates[Month] )  ,
        [Customer Count] & " (" & [Unvisited Chemists] & ")" ,
        FORMAT ( [Customer Count] , "#" )
    )
)

Please note that here I am using a date table instead of using auto date/time on the INVDATE column. This is considered best practice anyway. Remember to set the correct sort column, see guide here: https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column

I have used a simple date table:

Dates = 
ADDCOLUMNS ( 
    CALENDARAUTO () , 
    "Year" , YEAR ( [Date] ) ,
    "MonthNo" , MONTH ( [Date] ) ,
    "Month" , FORMAT ( [Date] , "MMMM" )
)

The data model looks like this:

Data model

The result looks like this:

Resulting matrix visual


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...