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
Syndicate_Admin
Administrator
Administrator

joining tables or measures

Comrades good day:

I have a problem with a result that I have not been able to obtain.

I have two tables with shops and cities. The first table is where the stores make a presence with sales and the other is where the stores are authorized to have a physical premises.

What I want is that I can have a list of each store where the cities where they make a presence and where they have sales are unified.

Example: store 1 has sales in 14 cities but is only authorized to have physical stores in a single city, then the total would not be 15 cities but 14 because there is a city that agrees in the two tables.

ShopsPresence citiesAuthorized citiesTotal
shop 114114
shop 2144 144
shop 3788
shop 4214200201
shop 510289106
shop 6145111145
shop 71 1
shop 81 1

Create two measures with DISTINCOUNT but when I try to join those two in a table I do not get the result I am looking for.

Do you have a recommendation?

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Let's see if this works for you.

First create dimension tables for Stores and Cities. The model looks like this:

model.jpgAnd it creates the following measures:

For the number of physical stores

Tiendas Físicas = 
DISTINCTCOUNT('Listado de Tiendas'[Ciudad])

For the number of cities with presences

Ciudades con Ventas = 
DISTINCTCOUNT('Ventas'[Ciudad])

And for the total calculation

Total =
VAR FT =
    VALUES ( 'Listado de Tiendas'[Ciudad] )
VAR CV =
    VALUES ( Ventas[Ciudad] )
RETURN
    COUNTROWS ( DISTINCT ( UNION ( FT, CV ) ) )

result.jpg

I attach the sample PBIX file

View solution in original post

9 REPLIES 9
Syndicate_Admin
Administrator
Administrator

Let's see if this works for you.

First create dimension tables for Stores and Cities. The model looks like this:

model.jpgAnd it creates the following measures:

For the number of physical stores

Tiendas Físicas = 
DISTINCTCOUNT('Listado de Tiendas'[Ciudad])

For the number of cities with presences

Ciudades con Ventas = 
DISTINCTCOUNT('Ventas'[Ciudad])

And for the total calculation

Total =
VAR FT =
    VALUES ( 'Listado de Tiendas'[Ciudad] )
VAR CV =
    VALUES ( Ventas[Ciudad] )
RETURN
    COUNTROWS ( DISTINCT ( UNION ( FT, CV ) ) )

result.jpg

I attach the sample PBIX file

Hi, @Syndicate_Admin 

 

What should be the correct result for Total?

 

Best Regards

PaulDBrown
Community Champion
Community Champion

Sorry, can you provide a wider sample? I Take it that there are more values than shop 1 (is Shop 1 a store brand?) and that other shops can be selling in the same cities?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hello;

In each city there may be several stores and tambein each store can make sales to the same cities where other stores also make sales.

What a shame not to be able to give the data but it is that as it is confidential information I have to invent data to be able to replicate the real problem. I will try to replicate more data.

Just add some rows to what you already have with made up cities, store number etc which reflect what you have in the actual data. I'm still not sure if "Shop 1" is a shop ID





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






See the largest sample

Store Archive

Store 1 is the name of the store, there is also a store 2, store 3 and so on.

I'm finishing a sample file to share.

PaulDBrown
Community Champion
Community Champion

Can you share some sample data?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Table of cities where stores had sales

ShopCitySales
shop 147001 - SANTA MARTA1
shop 147001 - SANTA MARTA1
shop 111001 - BOGOTÁ D.C.11229
shop 111001 - BOGOTÁ D.C.1501
shop 111001 - BOGOTÁ D.C.2847
shop 185001 - YOPAL2
shop 108001 - BARRANQUILLA2
shop 125377 - LA CALERA3
shop 111001 - BOGOTÁ D.C.223872
shop 113001 - CARTAGENA3
shop 147001 - SANTA MARTA5
shop 111001 - BOGOTÁ D.C.9651
shop 166001 - PEREIRA1
shop 144001 - RIOHACHA1
shop 125754 - SOACHA1
shop 120001 - VALLEDUPAR1
shop 117001 - MANIZALES1
shop 125286 - FUNZA1
shop 123001 - MONTERIA1
shop 113683 - SANTA ROSA1

Table of cities where stores are authorized

ShopCityLocal
shop 147001 - SANTA MARTA1

Expected result

ShopTownsLocal
shop 1141

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.