Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Group by Dax functions

Hi,

 

I have data that looks like this: 

 

Brown colored are input columns

Blue colored are output column

 

Anchor Config IDTarget Config ID

Dealer

(of target config ID)

Enabled for requested dealer# of dealers target config mapped to 
101101D140Yes1 
101102H200Yes2 
101102D140Yes2 
101103Z050No1 
102101N050Yes1 
102102N050Yes1 
102103D140No1 
103101E070No1 
103102E300No1 
103103N150Yes1 

 

Logic

1 Enabled for requested dealer:

 

In the above example, Anchor Config is a filter.

If (Dealer of Anchor Config = Dealer of Target Config) then Yes else No

 

Eg dealer of 102 is D140 and so is the dealer of 101 so Enabled for requested dealer for 102=Yes

 

 

Caveat: If target config ID has  > 2 dealers with atleast 1 Yes, then all those rows for target config id will become Yes

 

 

 

# of dealers target config mapped to

If target config ID occurs more than once then count (rows)

 

Eg there are 2 dealers for 102 Target Config or 2 rows of repeated values, so all 102 Target Config IDs values will become 2 for # of dealers target config mapped to

 

 

  • Hi Anonymous ,

    Try this:

    Enabled for requested dealer = 
    VAR CurrentAnchor = 'Table'[Anchor Config ID]
    VAR CurrentAnchorDealer =
        CALCULATE ( MAX ( 'Table'[Dealer] ), CurrentAnchor = 'Table'[Target Config ID] )
    VAR CountOfTargetDealer =
        CALCULATE (
            COUNT ( 'Table'[Target Config ID] ),
            ALLEXCEPT ( 'Table', 'Table'[Anchor Config ID], 'Table'[Target Config ID] )
        )
    RETURN
        IF (
            CurrentAnchorDealer <> BLANK (),
            "Yes",
            IF ( CountOfTargetDealer >= 2 && CurrentAnchorDealer = BLANK (), 
            "Yes", 
            "No" )
        )
    # of dealers target config mapped to =
    CALCULATE (
        COUNT ( 'Table'[Target Config ID] ),
        ALLEXCEPT ( 'Table', 'Table'[Anchor Config ID], 'Table'[Target Config ID] )
    )

     

    Best Regards,

    Icey

     

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

     

1 Reply

  • Icey's avatar
    Icey
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

    Try this:

    Enabled for requested dealer = 
    VAR CurrentAnchor = 'Table'[Anchor Config ID]
    VAR CurrentAnchorDealer =
        CALCULATE ( MAX ( 'Table'[Dealer] ), CurrentAnchor = 'Table'[Target Config ID] )
    VAR CountOfTargetDealer =
        CALCULATE (
            COUNT ( 'Table'[Target Config ID] ),
            ALLEXCEPT ( 'Table', 'Table'[Anchor Config ID], 'Table'[Target Config ID] )
        )
    RETURN
        IF (
            CurrentAnchorDealer <> BLANK (),
            "Yes",
            IF ( CountOfTargetDealer >= 2 && CurrentAnchorDealer = BLANK (), 
            "Yes", 
            "No" )
        )
    # of dealers target config mapped to =
    CALCULATE (
        COUNT ( 'Table'[Target Config ID] ),
        ALLEXCEPT ( 'Table', 'Table'[Anchor Config ID], 'Table'[Target Config ID] )
    )

     

    Best Regards,

    Icey

     

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