Forum Discussion

Nicpet0's avatar
Nicpet0
Frequent Visitor
1 year ago
Solved

Adding column from seperate table to unique combination

Hi Community i am facing an issue with updating my DAX measure. Below you will find the current code which intends to count the number of unique combinations of variant item no and variant code w...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for the reply from DataNinja777, please allow me to provide another insight.
    Hi Nicpet0 ,

     

    I am not sure how your dataset is designed, here is my data model.

     

    In my model, the 'Variant' table and the 'Sales Person' table are indirectly connected through the intermediate table 'Sales'.

    Therefore, you can try the following measure.

    # Count of Margin between 10-25% = 
    VAR tb =
        ADDCOLUMNS (
        Variant,
        "SalesPerson", CALCULATE ( MAX ( 'SalesPerson'[Sales Person Name] ),RELATEDTABLE(Sales))
        )
    RETURN
        CALCULATE (
            COUNTROWS (
                SUMMARIZE (
                    FILTER (
                        tb,
                        NOT ( ISBLANK ( [Invoiced Amount Incl All Charges] ) )&& 
                        [Gross Margin 2 %] > 0.10 && [Gross Margin 2 %] <= 0.25
                    ),
                    Variant[Variant Item No],
                    Variant[Variant Code],
                    [SalesPerson]
                )
            )
        )

    The 'tb' variable creates a virtual table that adds a corresponding SalesPerson to each 'Variant Item No' row in the 'Variant' table.

    The virtual table is as follows.

    The result of the measure is as follows.

     

    Please see the attached pbix for reference.

     

    Best Regards,
    Dengliang Li

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