Forum Discussion

RedaBi's avatar
RedaBi
Frequent Visitor
2 years ago
Solved

Measure to Calculate Objective

Using DAX, I want to create a measure to calculate the level reached based on the amount of sales by the seller, month, product, and year. It searches the objectives table based on the seller, month,...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi, RedaBi 

    Thank you very much for your reply. First, I've created a calculated column in the sales table to find the month of the current date as follows:

    At this point, put the month column and the Distrbuteur, YEAR column in the objectif table into the table visual:

     

    I created a Sum CA measure using the following DAX expression:

    Sum CA =
    VAR _cd_dist =
        SELECTEDVALUE ( objectif[Distrbuteur] )
    RETURN
        CALCULATE (
            SUM ( 'sales'[CA] ),
            TREATAS (
                SELECTCOLUMNS ( 'objectif', "cd dist", 'objectif'[Distrbuteur] ),
                sales[Cd Dist]
            ),
            'sales'[Cd Dist] = _cd_dist
        )
    

    Note that there is no relationship established between my two tables:

    I created a PALIER measure using the following DAX expression:

    PALIER =
    VAR _current_month =
        SELECTEDVALUE ( 'sales'[Month] )
    VAR _current_palier1 =
        CALCULATE ( MAX ( 'objectif'[PALIER 1] ), 'objectif'[MONTH] = _current_month )
    VAR _current_palier2 =
        CALCULATE ( MAX ( 'objectif'[PALIER 2] ), 'objectif'[MONTH] = _current_month )
    VAR _current_palier3 =
        CALCULATE ( MAX ( 'objectif'[PALIER 3] ), 'objectif'[MONTH] = _current_month )
    VAR _current_palier4 =
        CALCULATE ( MAX ( 'objectif'[PALIER 4] ), 'objectif'[MONTH] = _current_month )
    VAR _current_palier5 =
        CALCULATE ( MAX ( 'objectif'[PALIER 5] ), 'objectif'[MONTH] = _current_month )
    RETURN
        IF (
            [Sum CA] <> BLANK ()
                && _current_month
                    = CALCULATE ( MAX ( 'objectif'[MONTH] ), 'objectif'[MONTH] = _current_month ),
            SWITCH (
                TRUE (),
                [Sum CA] >= _current_palier5, "PALIER 5",
                [Sum CA] >= _current_palier4
                    && [Sum CA] < _current_palier5, "PALIER 4",
                [Sum CA] >= _current_palier3
                    && [Sum CA] < _current_palier4, "PALIER 3",
                [Sum CA] >= _current_palier2
                    && [Sum CA] < _current_palier3, "PALIER 2",
                [Sum CA] >= _current_palier1
                    && [Sum CA] < _current_palier2, "PALIER 1"
            )
        )
    

    Put these two measures into the table visual:

     

    In the example you gave, D11 has a Sum CA of 1,000,000 in March 2024. Sum CA = 82000000 + 138719422 + 145000000 = 365719422 in January 2024.

    Since in March 2024, the Sum CA of D11 is 1000000, according to the conditions you gave, it does not meet any of the grades in the objectif table, as shown in the figure below,

    I've provided the PBIX file used this time below.

     

     

     

    How to Get Your Question Answered Quickly

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

    Best Regards

    Jianpeng Li

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