Forum

Need strong query t...
 
Notifications
Clear all

Need strong query to calculate profit value

8 Posts
3 Users
0 Reactions
76 Views
(@aldelemy)
Posts: 7
Active Member
Topic starter
 

Hi, Is it possible to add a new column that calculates the value using the relationships between the 3 tables?

Actually, I want to calculate the total profit for each country.

Table 1: Country Id, Country Name

Table 2: Country Id, Property Id

Table3: Property Id, Profit

The difficulty is that there are several properties in each country, which means several values represent the profits in each country. so the query should sum all these profit values for each country.

new-value.png

 
Posted : 11/04/2021 3:21 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Ahmed,

As answered to the same question you posted on YouTube:

If you use the Country Name from Table 1 and the Profit from Table 3 in a PivotTable or chart/visual, you should get the result you want, assuming the relationships are set up correctly.
 
Mynda
 
 
 
Posted : 11/04/2021 8:59 pm
Anders Sehlstedt
(@sehlsan)
Posts: 968
Prominent Member
 

Hello,

Or you can simplify this and have one table with following structure: Country Name, Property, Profit

Br,
Anders

 
Posted : 12/04/2021 4:07 am
(@aldelemy)
Posts: 7
Active Member
Topic starter
 

Thanks for your reply, I could find the total profit through Power Bi and also through PivotTable. However, I am trying to use a formula to find that like using Vlookup or index without using PivotTable. just trying to practice use complex tools.

Thanks again    

 
Posted : 12/04/2021 10:16 am
(@aldelemy)
Posts: 7
Active Member
Topic starter
 

Thank you, Anders, for your response, I think the data is complex and overlapping, and it's not that easy to do the table as you mentioned. As you can see from the attached worksheets, the company has several agents in several countries, and each agent has several properties. And for each property, many values represent the profits for several years.

 
Posted : 12/04/2021 2:22 pm
Anders Sehlstedt
(@sehlsan)
Posts: 968
Prominent Member
 

Hello,

Yes, the data also seems to be part of a training excercise.
You can join data using relationships and Pivot, as Mynda writes in her reply, but as this post is in the Power Query section I assume you want a PQ solution to tidy up the data and I would go for a simplified table so I could use a Pivot Table without needing to create relationships.

Br,
Anders

 
Posted : 13/04/2021 12:45 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Ahamd,

There's no formula based solution for this because formulas cannot detect relationships that are indirect, i.e. route via multiple tables. That's why you must use Power Pivot so you can create relationships.

Mynda

 
Posted : 13/04/2021 4:01 am
(@aldelemy)
Posts: 7
Active Member
Topic starter
 

Thank you for your response Anders and Mynda, I agree with you.

I have created relationships between tables and have been able to get required using the following DAX formula:

TotalProfit =
CALCULATE (
    SUM ( Profit[TotalProfit] ),
    'Country'[CountryID] IN DISTINCT ( 'Property'[CountryID] ),
    'Property'[PropertyID] IN DISTINCT ( 'Profit'[PropertyID] )
)

 

By the way, I have an interesting question and worth thinking about the same tables but using Power BI, but I do not know where the best place to post it?

 
Posted : 15/04/2021 8:49 pm
Share: