Count values = 1 in a measure

zapppsr

Board Regular
Joined
Aug 19, 2010
Messages
189
Hi. I have a measure like this:

Visits = COUNTA(T_Visits[Oportunities])

It results the number of visits. If I associate it with a company it goes like this:

Company name - Visits
Company A - 300
Company B - 200
Company C - 123
Company D - 1
Company E - 1

Since there are lots of companies with only one visit, I want to know how many companies have only one visit.

How can I do that?
 
Playing with the formula, I tried to see how many companies have more than 20 visits and changed [cnt]=1 to [cnt]>20

It resulted 245, which is the sum of the number of visits of the 10 companies that have more than 20 visits. Do you know why?
[TABLE="width: 170"]
<colgroup><col></colgroup><tbody>[TR]
[TD="align: right"]35[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[/TR]
[TR]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD="align: right"]24[/TD]
[/TR]
[TR]
[TD="align: right"]23[/TD]
[/TR]
[TR]
[TD="align: right"]22[/TD]
[/TR]
[TR]
[TD="align: right"]22[/TD]
[/TR]
[TR]
[TD="align: right"]21[/TD]
[/TR]
[TR]
[TD="align: right"]21[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
That my measure is simplified because rows of T_Visits table has really one row per a company only. But for your new case
Code:
CALCULATE(COUNTROWS(
    SUMMARIZE('T_Visits',T_Visits[Company],"cnt",COUNTA(T_Visits[Company]))
    ),
    FILTER(
        SUMMARIZE('T_Visits',T_Visits[Company],"cnt",COUNTA(T_Visits[Company])),
        [cnt]>20
    )
)
Maybe Matt will make that simpler :)
Regards,
 
Upvote 0
It is simpler
Code:
COUNTROWS(
    FILTER(SUMMARIZE('T_Visits',T_Visits[Company],"cnt",COUNTA('T_Visits'[Company])),[cnt]>1)
)
 
Upvote 0
Hi anvg. That "cnt" in the expression, is like creating a virtual column/field where the values are summarized, and then we use it as a field later on [cnt]>1?

For my limited understanding of DAX, I guess it could be any string there... or is it a function too?

I'm very new to DAX, do you recommend any readings or videos to learn nice expressions such the one you taught me?

And thanks again!
 
Upvote 0
Hi. zapppsr.
I am sorry. I was not near any computer yesterday. My answer is for last solution.
SUMMARIZE function gets a rows subset of 'T_Visists' table which is defined by filter content of a current pivot cell. SUMMARIZE function splits rows from that subset for each equal 'Company' name and computes a count into a 'cnt' virtual column. At result we have a virtual calculated table.
FILTER function allows a row of that virtual table goes to COUNTROWS function if it has 'cnt'>20. And COUNTROWS simple considers those filtered rows.
do you recommend any readings or videos to learn
You could buy and read Matt Allington book Learn to Write DAX - Excelerator BI and his , Blog - Excelerator BI and read https://www.sqlbi.com/articles/
and maybe read https://www.sqlbi.com/books/the-definitive-guide-to-dax/ but it is not simple for beginner.
I know English badly and never looked at any video about Power Pivot :(
Regards, Andrey.
 
Upvote 0

Forum statistics

Threads
1,225,625
Messages
6,186,071
Members
453,336
Latest member
Excelnoob223

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top