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
Zealand
New Member

Return value of Column based on measure calculation in new measure otherwise return textstring

Hi all,

I need a dynamic calculation, that based on filters and slicers always will group countries with less than 1% of revenue as "Other Countries". Otherwise the name of the country should be taken from the Country Name Column.

The Code below is able to find all countries with less than 1% and return that value or the string "Other Countries" depending on what I put into the code.

 

But I can not return the name of the country with the rest of the code and hope that you can help?

 

The error message I get, when I try to insert the country is 
"A single value for Column "Country Name" in Table DimCountry can not be determined.

This can happen when a measure formula refers to a column that contains many values

without specifying an aggregation such as min max count or sum to get a single result.

 

Regards
Jørgen

 

Test Country =
VAR Revenuepct =
    CALCULATE (
        DIVIDE (
            [Total Amount LCY],
            [Total Net Sales LCY]
        ),
        FILTER (
            DimCountry,
            DIVIDE (
                [Total Amount LCY],
                [Total Net Sales LCY]
            ) < 0.01
        )
    ) 
VAR HighRevenue =
    CALCULATE (
        DIVIDE (
            [Total Amount LCY],
            [Total Net Sales LCY]
        ),
        FILTER (
            DimCountry,
            DIVIDE (
                [Total Amount LCY],
                [Total Net Sales LCY]
            ) > 0.01
        )
    )
RETURN
    IF (
        Revenuepct < 0,
        HighRevenue,
        Revenuepct
    )

 

Zealand_0-1671864317302.png

Zealand_1-1671864584940.png

 

 

1 ACCEPTED SOLUTION
Zealand
New Member

After one day of struggling, I found the code myself:

Test2 Country =
SWITCH (
    TRUE (),
    DIVIDE (
        [Total Amount LCY],
        [Total Net Sales LCY]
    ) > 0.01MAX ( Dimcountry[Country Name] ),
    "Other Countries"
)

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Zealand 

Thanks for your sharing. 

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Zealand
New Member

After one day of struggling, I found the code myself:

Test2 Country =
SWITCH (
    TRUE (),
    DIVIDE (
        [Total Amount LCY],
        [Total Net Sales LCY]
    ) > 0.01MAX ( Dimcountry[Country Name] ),
    "Other Countries"
)

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.