Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.


Follow on LinkedIn
@ 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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Users online (421)