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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
OnlyPhilip
Frequent Visitor

Text value from a column to filter another table

Hi everybody,

I can't figure out how to retrieve the text value (the metal field in the example below) from a column to be used as a filter for another column, row by row, so to fill a visual table.

 

I have this two tables:

MetalValues, with the market value of different metals (here just two as an example) along the year:

DateMetalValue
1/1/2020Iron200
2/1/2020Iron199
1/1/2020Copper50
2/1/2020Copper51

 

Production, with the metals production of the day for the full year: 

DateMetalProducedQuantity
1/1/2020 Iron10
1/1/2020 Copper50
2/1/2020 Iron12
2/1/2020 Copper60

 

The two tables are linked with an inactive relation between the Date columns, so that I can make use of USERELATIONSHIP to temporarily activate the relation and filter by date (it would create issues if I leave the relation active).

But I can't figure out how to also filter by metal so to have the correct multiplication.

 

I would like to have a visual table that shows Production and its values, like this:

Production[Date]Production[Metal]TotalValue
1/1/2020Iron2000
2/1/2020Iron2388
...  

 

Given that I need to relate both by date and by metal, I assumed this could have worked:

 

 

TotalValue= 
  CALCULATE(
    MAX(MetalValues[Value])*MAX(Production[ProducedQuantity]),
    FILTER(MetalValues, MetalValues[Metal]=Production[Metal]),
    USERELATIONSHIP(Production[Date],MetalValues[Date])
  )

 

 

In the code above, USERELATIONSHIP actually retrieves the right dates from MetalValues, but I get an error on the FILTER that aims to also retrieve the right metal, because I'm providing a column (Production[Metal]) instead than a single value.

How shall I code this second filter on the metal value?

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

You can not need the inactive relationship at all if your use an approach using TREATAS() as follows:

 

Total Value =
VAR __qty =
SUM ( Production[Produced Quantity] )
VAR __metalvalue =
CALCULATE (
MIN ( MetalValues[Value] ),
TREATAS ( VALUES ( Production[Date] ), MetalValues[Date] ),
TREATAS ( VALUES ( Production[Metal] ), MetalValues[Metal] )
)
RETURN
__qty * __metalvalue

 

Or you could use USERELATIONSHIP for the date and just use TREATAS() on metal column.  Note: this assumes you are using the columns from Production in your visuals (for Metal and Date).

 

If this works for you, please mark it as 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


View solution in original post

1 REPLY 1
mahoneypat
Microsoft Employee
Microsoft Employee

You can not need the inactive relationship at all if your use an approach using TREATAS() as follows:

 

Total Value =
VAR __qty =
SUM ( Production[Produced Quantity] )
VAR __metalvalue =
CALCULATE (
MIN ( MetalValues[Value] ),
TREATAS ( VALUES ( Production[Date] ), MetalValues[Date] ),
TREATAS ( VALUES ( Production[Metal] ), MetalValues[Metal] )
)
RETURN
__qty * __metalvalue

 

Or you could use USERELATIONSHIP for the date and just use TREATAS() on metal column.  Note: this assumes you are using the columns from Production in your visuals (for Metal and Date).

 

If this works for you, please mark it as 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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.