cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular 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
Super User III
Super User III

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

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

Super User III
Super User III

@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

Regular Visitor

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

Helpful resources

Announcements
secondImage

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

secondImage

Power BI Women

Join our monthly meetings and learning sessions.

secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.