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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Glenan
Frequent Visitor

contar una columna en base a otra columna en otra tabla

Hola, espero me puedan ayudar.

tengo dos tablas, la TABLA_A tiene los campos de (id_region, Región, Ciudad), la segunda TABLA_B tiene los campos(id_clave,id_region,actividad,fecha), el caso es que quiero contar cuantas ciudades únicas fueron visitadas en cada actividad), tengo la siguiente formula

Total Ciudad = calculate(DISTINCTCOUNT(TABLA_A[Ciudad]),USERELATIONSHIP(TABLA_B[id_region],TABLA_A[id_region]))
Pero me cuenta los valores unicos de la TABLA_A, no me cuenta en base a la TABLA_B, osea me trae todas las ciudades existentes de cada region.
X ejemplo en la TABLA_B tengo varias actividades en la misma y distintas ciudades, no en todas, pero me cuenta como si hubiera estado en todas las ciudades.
Si me pueden ayudar gracias.
 
 

 

 

 

1 ACCEPTED SOLUTION

@Glenan 

If you have an active 1-many relationship betwee Table_A[idregion] and Table_B[idregion] this should work too, although I'd need some sample data to do a quick check

Total Ciudad =
CALCULATE ( DISTINCTCOUNT ( Tabla_A[Ciudad] ), Tabla_B )

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

View solution in original post

3 REPLIES 3
AlB
Super User
Super User

Hi @Glenan 

It would help if you show a sample of the tables in your model and their relationships (active and inactive). Try this:

1. Place Tabla_B[Actividad] in a table visual

2.  Update the measure and place it in the visual: 

 

Total Ciudad =
CALCULATE (
    DISTINCTCOUNT ( Tabla_A[Ciudad] ),
    FILTER ( Tabla_A, Tabla_A[id_region] = SELECTEDVALUE ( Tabla_B[id_region] ) )
)

 

 If this does not work please show a sample of your tables

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

@Glenan 

If you have an active 1-many relationship betwee Table_A[idregion] and Table_B[idregion] this should work too, although I'd need some sample data to do a quick check

Total Ciudad =
CALCULATE ( DISTINCTCOUNT ( Tabla_A[Ciudad] ), Tabla_B )

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

Glenan
Frequent Visitor

Thanks!!, the best solution it's the most simple

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors