cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

COUNT VALUES FROM A COLUMA (CONTAR.SI)

Hi, I'm new using Power Bi. I'm having a problem counting the values in a column.

In my case I want to get the count of the total occurrences of a value in a column, but I can't get the correct number

In a table I have the Effector and Prescriber fields. I want to count the total number of times an effector is itself a prescriber, regardless of whether the effector and prescriber coincide.

Example: In the following table visualization I select the effecter as the column. In the case that I analyze Amato Alicia tells me that when I do the prescriber count is 10. However when in the table filter by prescriber amato alice appears 12 times in the table. In excel with a CONTAR.SI works by referencing the cell over which you want to get the total =CONTAR.SI("ATORANGED";" CELL WITH VALUE"). I try to solve it using view and a count of values, with DAX functions like CALCULTA AND COUNT and obviously something I'm not doing right.

vgalvan_0-1627482273572.png

vgalvan_1-1627482446391.png

1 ACCEPTED SOLUTION

Hi @Syndicate_Admin 

In addition to   's reply, try this measure.

Medida =
IF (
    HASONEVALUE ( Hoja1[Efector] ),
    COUNTROWS (
        FILTER ( ALL ( Hoja1 ), Hoja1[Prescriptor] = MAX ( Hoja1[Efector] ) )
    ) + 0,
    COUNTROWS ( ALLSELECTED ( Hoja1 ) )
)

Result is as below.

1.png

Here we use all in countrows is to calculate in whole table in each Efector, or it will just count in current row. Max in measure is to get the current value in text format. You see here Medida measure will return a correct result.

 

Best Regards,

Rico Zhou

 

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

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

It's weird, I don't have any filters applied. What I see is that it seems that logic tells me the number of times that effector and prescriber coincide and I want it to bring me the total number of times that the prescriber appears in the table.

Greg_Deckler
Super User IV
Super User IV

@Syndicate_Admin So, you would need to construct a measure like:

Measure = 
  VAR __Efector = MAX('Table'[Efector])
RETURN
  COUNTROWS(FILTER(ALL('Table'),[Prescriptor] = __Efector))

---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




I managed to create a column with the value I need but I can't create a measure that calculates the same for me

"Prescripciones: =
var CONTEO=CALCULATE(COUNT('CrudosDev Ambulatorio'[Prescriptor]))
var PRESC='CrudosDev Ambulatorio'[Prescriptor]
RETURN 
SUMX(FILTER('CrudosDev Ambulatorio','CrudosDev Ambulatorio'[Prescriptor]=PRESC),CONTEO)"

Hi @Syndicate_Admin 

In addition to   's reply, try this measure.

Medida =
IF (
    HASONEVALUE ( Hoja1[Efector] ),
    COUNTROWS (
        FILTER ( ALL ( Hoja1 ), Hoja1[Prescriptor] = MAX ( Hoja1[Efector] ) )
    ) + 0,
    COUNTROWS ( ALLSELECTED ( Hoja1 ) )
)

Result is as below.

1.png

Here we use all in countrows is to calculate in whole table in each Efector, or it will just count in current row. Max in measure is to get the current value in text format. You see here Medida measure will return a correct result.

 

Best Regards,

Rico Zhou

 

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

Thank you a lot Thanks @Syndicate_Admin try to understand what the measure does but I get lost, you can explain it to me so I can understand the logic?

Thank you!

@Syndicate_AdminI'll give you a smaller example of what I want to achieve. In the excel what I want to get, in the pbix what returns me

https://sanatoriolaslomas-my.sharepoint.com/:f:/p/vgalvan/EvEuJTvma5FBtTKH_DwO4UoBlif_1HKWjuVDCEBJx3...

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

Get Ready for Power BI Dev Camp

Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors