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
IvoryKoss
Frequent Visitor

Divide 2 different columns from different tables and linked with 2 relations

Hi All,

I want to calculate the KWH per Volume

-the 2 colums are in deffernt tables

-The tables are linked by relationships trough intermediate tables

-the expected KWH per Volume shoud be per week and per factory

 

 screenshot.PNG

I have tried this DAX formula, but don't expected results.

 

KWH per Volume = 
DIVIDE(
Energy[KWH],
CALCULATE(SUM(Volume[volume]),ALLEXCEPT(Volume,Factories[factory]),ALLEXCEPT(Volume,datemaster[WEEKs])),
0
) 

 

 

Rgds,

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

In your visual, drag week from the Datamaster table and factory from the Factories table.  Then this measure should work

 

=SUM(Energy[KwH])/SUM(Volume[Volume])

 

If this does not help, then share the link from where i can download your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

13 REPLIES 13
IvoryKoss
Frequent Visitor

One finding I did is that the result of the measure is different according the table where you created it.

 

Please elaborate.  What problem are you facing?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

 

In your visual, drag week from the Datamaster table and factory from the Factories table.  Then this measure should work

 

=SUM(Energy[KwH])/SUM(Volume[Volume])

 

If this does not help, then share the link from where i can download your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thx it works perfectly!Smiley Happy

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Dear Mr. Ashish,

 

I need solution for given below:

 

Thank You.

Table 1

  Table 2  Requirement 
Store IDDis Amt Store IDSales Store IDDis % To Sales
ABC2 ABC50 ABC

20%

ABC4      
BCD2      
ABC4      
BCD6      
DEF4      
DEF2      

Hi,

Create a third table with a single column which lists all unique Store ID's.  Create a relationship (Many to One and Single) from the StoreID column of the 2 tables to the StoreID column of the third table.  To your visual, drag StoreID from Table3.  Write these measures:

Dis Amount = sum('Table1'[Dis Amt])

Total sales = sum('Table2'[Sales])

Dis% to sales = divide([Dis Amount],[Total sales])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Dear Mr. Ashish,

 

Thank yoi for your reply.

 

However, i am not able to get % when i select ABC from my store ID list. Over all it gets tally when i divide total discount with total sales.

 

However when i select store ID ABC then i must get 20% (ABC dis amt is 10 and Sales is 50 = 20%). But i am not getting the same.

 

Kindly help.

 

I followed all steps which you given above.

 

Thank You.

Regards

CA Dhaval Shah

 

Dear Mr. Ashish,

 

Due to confidentiality i can't share my pbi file, but i can try to give all details below. Hopefully you will be able to provide solution on the same:

 

Table 1 - Birthday Discount - Invoice wise and Store wise (It has line items more than '000 - Particular store has many line items)

Table 2 - Sales Master - It shows store wise Sale (Only Store ID and it's Total Sale Amount)

Table 3 - Store Master -(Store ID, Store Name, City, Region etc..)

 

I connected - Table 1 with Table 2 on Store ID

I connected - Table 1 with Table 3 on Store ID

 

Now my requirements are - 

1. Total Discount per store (Which i will get from table 1)

2. Total Sales store wise (Already given in Table 2)

3. Final requirement - Store wise % to Sales

 

For more clarification, sample given below:

 

Table 1 Table 2 Requirement   
Store IDDis Amt SalesAmt Requirement (As filter box, where I can select store ID and it will reflect % to Sales   
112 1300 Store ID% to Sales  
213 2200 125.33%(76/300)76 is Total Discount
116    220%(40/200)40 is Total Discount
110        
28        
118        
120        
219        

Hi,

To your visual, drag StoreID from Table 3.  Write these measures:

Dis amount = sum('Table1'[Discount])

Total sales = sum('Table2'[Amount])

Dis (%) = divide([dis amount],[total sales])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

Share the link from where i can download your PBI file and show the problem very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-sihou-msft
Employee
Employee

@IvoryKoss

 

Based on your screenshot, both Volume and Energy are fact tables, Week and Factory are dimension tables. Since both volumn and KWH are sliced by Week and Factory, you should be able to directly have KWH divided by volume.

 

=DIVIDE(Energy[KWH],RELATED(Volume[volume]))

Or you can lookup corresponding volume into Energy table. 

 

=LOOKUPVALUE(Volume[volume],Volume[factory],Energy[factory],Volume[Week],Energy[Week])

Then use KWH column divied by above lookup column.

 

Regards,

 

 

Merci @v-sihou-msft for your answer,

however I still got errors:

 

=DIVIDE(Energy[KWH],RELATED(Volume[volume]))

returns : The column 'Volume[volume]' either doesn't exist or doesn't have a relationship to any table available in the current context.

 

 

and

LOOKUPVALUE(Volume[volume],Volume[factory],Energy[factory],Volume[Week],Energy[Week])

 

 

 returns:

A single value for column 'factory' in table 'Energy' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

is it possible with the 2nd option to returns a table and then sum up to have the total volume. So that the division can happen?

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.