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
ybatistamayo
Helper III
Helper III

RELATIONSHIP

I have two tables, one of "Cost" and one of "Taxes", in the latter the "tax" column is updated every year.
also the column that I have to relate both tables is "IDCOST".
The first problem is that I tried the "Many to many" relationship and it didn't work.
I want to relate both tables to get a final result as shown.
that is, calculate the tax according to the year of the date column.

 

Sin título.png

2 ACCEPTED SOLUTIONS

That file has an extension of .7z.  I cannot open that on my system.


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

View solution in original post

v-lili6-msft
Community Support
Community Support

hi, @ybatistamayo 

For your case, you don't need to create the relationship between two tables, just try this formula to create a measure:

Result = var _table=ADDCOLUMNS(COST,"_Tax",CALCULATE(SUM(TAX[TAX]),FILTER(TAX,COST[IDCOST]=TAX[IDCOST]&&YEAR(COST[DATE])=YEAR(TAX[DATE])))) return
SUMX(_table,[QUANTITY]*[PRICE]+[_Tax])

Result:

9.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

15 REPLIES 15
Yakob_Logerfo
New Member

 

I need help, new to Power bi, How can I create relationship between this table?
Annotation 2019-11-04 101616.png

v-lili6-msft
Community Support
Community Support

hi, @ybatistamayo 

For your case, you don't need to create the relationship between two tables, just try this formula to create a measure:

Result = var _table=ADDCOLUMNS(COST,"_Tax",CALCULATE(SUM(TAX[TAX]),FILTER(TAX,COST[IDCOST]=TAX[IDCOST]&&YEAR(COST[DATE])=YEAR(TAX[DATE])))) return
SUMX(_table,[QUANTITY]*[PRICE]+[_Tax])

Result:

9.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 Excellent!, it worked perfect. Could you explain to me what exactly this calculation is doing?

Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


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

 

The file has three other tables that I suggested that a previous user add to the model

Here the link

https://we.tl/t-OKPRfpoVgx 

Hi,

There is no file there.  To avoid confusion, please only share 2 Tables - Cost and Tax.  Also, share the correct result for the data that you share.


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

well here it goes again only with two original tables

https://we.tl/t-zyQ1y6R9GM

 

 

and the result I aspire to get is this

 

solucion3.png

total = quantity * price * tax

 

 

That file has an extension of .7z.  I cannot open that on my system.


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

Hi,

I need to carry out a transformation in the Query editor.  Share the source Excel files which have both tables.


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

Very interesting qns for something seemingly straight forward.

If i get what you are intending to do, can i say for each IDCOST, the ID is not important , its only the year:

100 is 2 in 2018 regardless of A or B

100 is 4 in 2019

101 is 3 in 2018.

 

If that is the case, in table 1 , let newIDCOST= Year&IDCOST ( example 2018_100) , do this in source or power querry

in table 2 concatenate this to newIDCOST,Tax

2018_100, 2

2019_100,4

2018_101,3

(remove duplcates is necessary(after removing column ID, row 1,2 would be same)

create a 1 to many relationship from table 2 to table 1.

to be neat you can have a seperate calendar table or if your table is not too complicated just have a year column in your table 2.

 

regards

 

 

leed
Advocate II
Advocate II

Hi,

Power BI is Excel like but you shoudn't think like that way.

Below I will describe my solution, but first I suggest you read this article about data modeling in Power BI Desktop written by radacad : https://radacad.com/basics-of-modeling-in-power-bi-fact-tables

 

1/ Refer to that article, you are actually having 2 fact tables : cost and tax.

which share common dimension tables : Dates, Products and Costs

 

2/ To create:

-Date table : https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

-Products table : In Edit Query, do a duplicate of the Cost table and Keep only column Product, do a DISTINCT on that column

-Costs table : In Edit Query, do a duplicate of the Cost table and Keep only column IDCOST, do a DISTINCT on that column

 

3/ Your model will have 5 tables :

-new table issues from step 2 : Dates, Products, Costs

-your origin table : Fact_Sales, Fact_Tax

-By folowwing the link I sent at the beginning : https://radacad.com/basics-of-modeling-in-power-bi-fact-tables you will be able to link these tables by using they key (all of them shoudl be 1 to many relationship)

-at the end, you can create your measure Total = quanity * price + tax

 

Best,

 

 

when you put cgo tax to values ​​in the matrix this is what happens

solucion2.png

what I want is every year to show the correct tax

 

 

I'm sorry I'm sorry, I'm wrong to type, the right thing is that each product is assigned an IDCosto

SOLUCIONÇ.png

I'm sorry I'm sorry, I'm wrong to type, the right thing is that each product is assigned an IDCosto

A 100

B 103

C 101

D 102

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.