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
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
Employee
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
Employee
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
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.

Top Solution Authors