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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
Bailo220587
New Member

help with this dax formula

Hello, I am posting this message for you to help me build a dax formula.
I would like from this table to construct the following sentence: "462 tons are from abroad including 221 in ES and 214 in SE". that is to say that in the sentence I want to extract the 2 maximum values ​​and the country by excluding France. 

I put the picture for you to understand better.

Please Help me! 

 

Capture.PNG

1 ACCEPTED SOLUTION
Barthel
Solution Sage
Solution Sage

Hey @Bailo220587

Give this a try:

 

Measure = 
VAR _total =
    CALCULATE ( SUM ( 'Table'[weight] ), 'Table'[country] <> "FR" )
VAR _max_weights =
    TOPN (
        2,
        CALCULATETABLE ( VALUES ( 'Table'[weight] ), 'Table'[country] <> "FR" ),
        'Table'[weight], DESC
    )
VAR _max_weight_1 =
    MAXX ( _max_weights, 'Table'[weight] )
VAR _max_weight_2 =
    MINX ( _max_weights, 'Table'[weight] )
VAR _max_country_1 =
    CALCULATE ( SELECTEDVALUE ( 'Table'[country] ), 'Table'[weight] = _max_weight_1 )
VAR _max_country_2 =
    CALCULATE ( SELECTEDVALUE ( 'Table'[country] ), 'Table'[weight] = _max_weight_2 )
VAR _result = _total & " tons are from abroad including " & _max_weight_1 & " in " & _max_country_1 & " and " & _max_weight_2 & " in " & _max_country_2 & "."
RETURN
    _result

 

View solution in original post

2 REPLIES 2
Barthel
Solution Sage
Solution Sage

Hey @Bailo220587

Give this a try:

 

Measure = 
VAR _total =
    CALCULATE ( SUM ( 'Table'[weight] ), 'Table'[country] <> "FR" )
VAR _max_weights =
    TOPN (
        2,
        CALCULATETABLE ( VALUES ( 'Table'[weight] ), 'Table'[country] <> "FR" ),
        'Table'[weight], DESC
    )
VAR _max_weight_1 =
    MAXX ( _max_weights, 'Table'[weight] )
VAR _max_weight_2 =
    MINX ( _max_weights, 'Table'[weight] )
VAR _max_country_1 =
    CALCULATE ( SELECTEDVALUE ( 'Table'[country] ), 'Table'[weight] = _max_weight_1 )
VAR _max_country_2 =
    CALCULATE ( SELECTEDVALUE ( 'Table'[country] ), 'Table'[weight] = _max_weight_2 )
VAR _result = _total & " tons are from abroad including " & _max_weight_1 & " in " & _max_country_1 & " and " & _max_weight_2 & " in " & _max_country_2 & "."
RETURN
    _result

 

Hello, I had to create an aggregation table to succeed. but I used your sequence Thank you for everything

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.