Forum Discussion

DanPell's avatar
DanPell
Icon for Helper I rankHelper I
1 year ago
Solved

Need help please to sum and filter based on different value criteria from the same column

Hi there I'm having trouble summing values based on values contained in another column.   I would like to sum store Campaign Sales Targets based on Campaign Names to get a Group number.    The only...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi DanPell ,

     

    I see. I assume the user is in the southern hemisphere to observe the seasons. You can hard-code the country code into the measure:

    MEASURE = 
    VAR __N_countries = { "US" }
    VAR __curr_selected_value =
        SELECTEDVALUE ( 'Table'[Campaign Name] )
    VAR __result =
        SWITCH (
            TRUE (),
            ISBLANK ( __curr_selected_value ), SUM ( 'Table'[Campaign Targets] ),
            __curr_selected_value = "Spring Sale",
                CALCULATE (
                    SUM ( 'Table'[Campaign Targets] ),
                    NOT 'Table'[Country Code] IN __N_countries
                )
                    + CALCULATE (
                        SUM ( 'Table'[Campaign Targets] ),
                        'Table'[Campaign Name] = "Autumn Sale",
                        'Table'[Country Code] IN __N_countries
                    ),
            __curr_selected_value = "Autumn Sale",
            CALCULATE (
                    SUM ( 'Table'[Campaign Targets] ),
                    NOT 'Table'[Country Code] IN __N_countries
                )
                    + CALCULATE (
                        SUM ( 'Table'[Campaign Targets] ),
                        'Table'[Campaign Name] = "Spring Sale",
                        'Table'[Country Code] IN __N_countries
                    )
        )
    RETURN
        __result

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

  • DanPell's avatar
    DanPell
    1 year ago

    Hey thanks for this, awesome.  Just a quick one if I have multiple Northern Hem countries (i.e. US, CA, UK,) is that as easy as putting the respective country codes into the VAR measure i.e.

    VAR__N_Countries = {"US","CA","UK"}??

    Thanks!