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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.