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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Super User

@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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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. 

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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