Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
4 years ago
Solved

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?

  • 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

9 Replies

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      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

  • PaulDBrown's avatar
    PaulDBrown
    Icon for Community Champion rankCommunity 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?

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      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.

      • PaulDBrown's avatar
        PaulDBrown
        Icon for Community Champion rankCommunity Champion

        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

  • 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