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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
OnlyPhilip
Frequent Visitor

TREATAS not picking a single value

Hi everybody, I need your help for this apparently simple problem.

 SUMX(Batch,
        CALCULATE(
	    MAX(MetalValues[Value]),
            TREATAS(VALUES(Batch[Metal]), MetalValues[Metal]),
            TREATAS(VALUES(Batch[Date]), MetalValues[Date])
        )
 )

The Batch table contains a list of production Dates of different Metals. I need to retrieve the Price for those dates and metals from the unrelated MetalValues table and sum them up.
The issue is that, at each iteration of SUMX, the MAX function returns the max value of the whole MetalValues table. My expectation and need is that it only returned the MetalValue value from that Date and Metal (which is unique being a daily trading value).
Any idea on what's my mistake here?
Thanks
Fil

 

1 ACCEPTED SOLUTION

Please try this measure expression instead

 

New Measure =
VAR summary =
    ADDCOLUMNS (
        SUMMARIZE ( Batch, Batch[Metal], Batch[Date] ),
        "@value",
        VAR thisdate = Batch[Metal]
        VAR thismetal = Batch[Metal]
        RETURN
            CALCULATE (
                MAX ( MetalValue[Value] ),
                MetalValue[Metal] = thismetal,
                MetalValue[Date] = thisdate
            )
    )
RETURN
    SUMX ( summary, [@value] )

 

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


View solution in original post

4 REPLIES 4
OnlyPhilip
Frequent Visitor

Thanks for your answers. The original pbix contains some confidential data, I'm attaching  a screenshot of the two tables, hope it helps. The first one is the Batch table, the second it MetalValues, where the values should be retrieved from.

I thought maybe there was a mismatch in the Date field, but they both appear formatted as Dates.

Thanks!

 

BatchBatch

 

MetalValuesMetalValues

 

 

 

 

 

 

 

 

Please try this measure expression instead

 

New Measure =
VAR summary =
    ADDCOLUMNS (
        SUMMARIZE ( Batch, Batch[Metal], Batch[Date] ),
        "@value",
        VAR thisdate = Batch[Metal]
        VAR thismetal = Batch[Metal]
        RETURN
            CALCULATE (
                MAX ( MetalValue[Value] ),
                MetalValue[Metal] = thismetal,
                MetalValue[Date] = thisdate
            )
    )
RETURN
    SUMX ( summary, [@value] )

 

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


amitchandak
Super User
Super User

@OnlyPhilip ,The information you have provided is not making the problem clear to me. Can you please explain with an example.
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
AntrikshSharma
Super User
Super User

Can you share the pbix file?

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.