Forum Discussion

Bailo220587's avatar
Bailo220587
New Member
3 years ago
Solved

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...
  • Barthel's avatar
    3 years ago

    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