Forum Discussion

Lexi's avatar
Lexi
Frequent Visitor
4 years ago
Solved

Nested if statements/Switch function?

Howdy!    I need some direction from you nice guys ðŸ˜Š   I am new to Powerbi and I am trying to get to a solution to my issue. I have a dataset and I am assigning groups to our customers  Custome...
  • smpa01's avatar
    smpa01
    4 years ago

    Lexi  can you try this

    Column =
    VAR _home =
        SELECTCOLUMNS (
            SUMMARIZE (
                CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[CustID] ) ),
                'Table'[CustID],
                'Table'[Home]
            ),
            "cust", [CustID],
            "country", [Home]
        )
    VAR _shipping =
        SELECTCOLUMNS (
            SUMMARIZE (
                CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[CustID] ) ),
                'Table'[CustID],
                'Table'[Shipping]
            ),
            "cust", [CustID],
            "country", [Shipping]
        )
    VAR _intersect =
        INTERSECT ( _home, _shipping )
    VAR _except =
        EXCEPT ( _shipping, _home )
    RETURN
        IF (
            MAXX ( _except, [country] ) = BLANK (),
            MAXX ( _intersect, [country] ),
            MAXX ( _except, [country] )
        )
    

     

    which generates this