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
jamuka
Advocate II
Advocate II

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

Data Model.png

 

1 ACCEPTED SOLUTION
AlB
Super User
Super User

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 

SU18_powerbi_badge

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@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

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.

Greg_Deckler
Super User
Super User

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.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

AlB
Super User
Super User

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 

SU18_powerbi_badge

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.

 

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.