Forum Discussion

jamuka's avatar
jamuka
Helper IV
6 years ago
Solved

Divide between two tables

Hello,

I want to divide my total sales amount in Sales Table to total visitor number based on location in Visitors Table.

Tables have inactive relationship, based on store location (there are two location) between them.

When I tried to use simple divide, it divides all visitors instead of location level. 

 

 

Sales table

DateStore LocationStore NoProduct CategoryProduct IDSales Amount
1.05.2020AA-1Cat-A250
1.05.2020BB-1Cat-B375
1.05.2020AA-2Cat-A150
1.05.2020BB-2Cat-C475
2.05.2020AA-1Cat-A250
2.05.2020BB-1Cat-B575
2.05.2020AA-2Cat-B350
2.05.2020BB-2Cat-B775

 

Visitors table

DateStore LocationVisitor
1.05.2020A1.500
1.05.2020B2.000
2.05.2020A1.000
2.05.2020B1.750

 

in excel my expected result looks like this

 

Store LocationProduct CategoryTotal SalesSales Per Visitor
ACat-A1500,06
ACat-B500,02
BCat-B2250,06
BCat-C750,02

 

My Data model is

 

  • Hi jamuka 

    Since the relationship is inactive, place the fields shown from the Sales table in a table visual and create a measure:

    NumVisitors =
    CALCULATE (
        SUM ( VistorsT[Visitor] ),
        FILTER (
            ALL ( VistorsT ),
            VisitorsT[Store Location] = SELECTEDVALUE ( SalesT[Store Location] )
                && VisitorsT[Date] = SELECTEDVALUE ( SalesT[Date] )
        )
    )
    

     This will give you the number of visitors in that location and day. Yo can use that to calculate the quotient as required

    Please mark the question solved when done and consider giving kudos if posts are helpful.

     Cheers 

6 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi jamuka 

    Since the relationship is inactive, place the fields shown from the Sales table in a table visual and create a measure:

    NumVisitors =
    CALCULATE (
        SUM ( VistorsT[Visitor] ),
        FILTER (
            ALL ( VistorsT ),
            VisitorsT[Store Location] = SELECTEDVALUE ( SalesT[Store Location] )
                && VisitorsT[Date] = SELECTEDVALUE ( SalesT[Date] )
        )
    )
    

     This will give you the number of visitors in that location and day. Yo can use that to calculate the quotient as required

    Please mark the question solved when done and consider giving kudos if posts are helpful.

     Cheers 

    • jamuka's avatar
      jamuka
      Helper IV

      Hello AlB ,

       

      thanks for your help. Measure is working but I realized my question has missing information, I updated it.

      I want to show values based on location and product category level and filter it with a slicer based on year month (e.g Jan '20).

      So I tweaked my Visitor Table and add year month column, then tweaked your formula too.

      Although it shows correct values on product category and shows subtotal on location level it didn't show on total values on Total level. I guess I have to change my Sales Table, add visitor amount to it then tried to find another way to calculate with correct numbers.

       

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    You either need a better data model or USERELATIONSHIPS.

     

    If you made that relationship uni-directional from Sales to Visitors, it wouldn't be inactive.

    • jamuka's avatar
      jamuka
      Helper IV

      Hello Greg_Deckler  thank you for your reply.

      I made the relationship from sales to visitors but couldn't make it active due to ambiguity between Date and Visitors Tables.

      I tried to use USERELATIONSHIPS but couldn't finda relevant sample.

       

      also I realized my question has missing information therefore I updated it, sorry for inconvenience.

  • jamuka , you should join both tables with Store and then you can analyze data for the store , there you will be able to see both sum of sales and visitor

    • jamuka's avatar
      jamuka
      Helper IV

      Hello amitchandak,

       

      When I join Visitor Table to Store Table and add visitor column to my visual it shows same value (total visitor) for each row instead of location's sum of visitor.