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
db2907
Helper II
Helper II

Compare two columns from different tables in Power BI

Hi there.

I've got this question. This is the model that has been created for the client (I can not modify anything only use it).

 

Capture.JPG

 

There is a many to many relationship between category and item. For this specific requirement it is necessary to create a metric that should have values only for a particular category, otherwise it should return 0 as value, However I can not show the ID of the category on the calculation. It's a specific requirement of the client. 

So I should have a metric with a logic similar to this:

CALCULATE( SUM(Fact[Amount]),

                     Category[Category ID] = Fact[Category ID])

 

On the report there will be a filter that will indicate the specific category for this metric. I only need to do this comparison.

Is there a way to do this on Power? So far I have not found any possible solution.

 

Regards

2 REPLIES 2
amitchandak
Super User
Super User

@db2907 , Ideally Category should be part of the Item table. But try one of the two as new measure

sumx(summarize(filter(Fact,Fact[Category ID] =max(Category[Category ID])),Fact[Category ID],"_1",sum(Fact[Amount])),[_1])

or

sumx(summarize(filter(Fact,Fact[Item ID] =max(Category[Item ID]) && Fact[Category ID] =max(Category[Category ID])),Fact[Category ID],"_1",sum(Fact[Amount])),[_1])

mahoneypat
Employee
Employee

Yes.  You should be able to use a measure like this

 

NewMeasures = var __thiscategory = SELECTEDVALUE(Category[CategoryID])

Return CALCULATE(Sum(Fact[Amount]), Fact[CategoryID]=__thiscategory)

 

This assumes there will only be a single value for Category[CategoryID] in the context you use it.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.