Forum Discussion

Qootaro's avatar
Qootaro
New Member
1 year ago
Solved

How to select column with conditional in measure

I am newbie and please give suggestion.

I faced issue to make measure with conditional selection to display in matrix table

 

As my case, need to make if condition to separate 2 groups as "abc" and other else then display different column depend on each group.

 

Here is my commands

 

Measure =

CALCULATE(

     IF(CONTAINS('Table','Table'[Col1],"abc"),

          SUM('Table'[cnt]),

          SUM('Table'[sum_cnt])

     ,'Table'[date]=MAX('Table'[date])

)

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi ,

    The method rajendraongole1 provided should be helpful.

    Besides, creating the sample table. You can also try the following DAX formula to select value in measure..

    Measure = 
    IF(
        CONTAINS('Table', 'Table'[Col1], "abc"),
        CALCULATE(
            SUM('Table'[cnt]),
            'Table'[date] = MAX('Table'[date])
        ),
        CALCULATE(
            SUM('Table'[sum_cnt]),
            'Table'[date] = MAX('Table'[date])
        )
    )

    The matrix visual is shown below.

    Best Regards,

    Wisdom Wu

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

4 Replies

  • Hi Qootaro  - Your measure has some syntax issues and logical gaps.

     

    can you please update the measure as below:

    Measure =
    VAR IsABC =
    CONTAINS('Table', 'Table'[Col1], "abc")
    RETURN
    CALCULATE(
    IF(
    IsABC,
    SUM('Table'[cnt]),
    SUM('Table'[sum_cnt])
    ),
    'Table'[date] = MAX('Table'[date])
    )

     

    change the table names as per your model.

    Hope this helps.

  • Hi Qootaro

    You can try using,

    Measure =
    IF(
    MAX('Table'[Col1]) = "abc",
    CALCULATE(
    SUM('Table'[cnt]),
    'Table'[date] = MAX('Table'[date])
    ),
    CALCULATE(
    SUM('Table'[sum_cnt]),
    'Table'[date] = MAX('Table'[date])
    )
    )

     

    ๐ŸŒŸ I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.

    ๐Ÿ’ก Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.

    ๐ŸŽ– As a proud SuperUser and Microsoft Partner, weโ€™re here to empower your data journey and the Power BI Community at large.

    ๐Ÿ”— Curious to explore more? [Discover here].

    Letโ€™s keep building smarter solutions together!

  • Hello Qootaro ,

     

    Can you share what exactly you need ? Your dax looks incorrect and you can update like :

     

    Measure =
    CALCULATE(
    IF(
    CONTAINS('Table', 'Table'[Col1], "abc"),
    SUM('Table'[cnt]),
    SUM('Table'[sum_cnt])
    ),
    'Table'[date] = MAX('Table'[date])
    )

     

    There might be potential issues depending on the context in which you're using this formula. 

    If you intend to evaluate whether "abc" is present for each row individually and sum the values based on the most recent date, you may need to adjust the logic slightly.

     

    Measure =
    CALCULATE(
    IF(
    'Table'[Col1] = "abc",
    SUM('Table'[cnt]),
    SUM('Table'[sum_cnt])
    ),
    'Table'[date] = CALCULATE(MAX('Table'[date]))
    )

     

    I hope this helps.

    You can share input and expected output to check further.

    Did I answer your query ? Mark this as solution if this helps, Kudos are appreciated.

     

    Cheers

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ,

    The method rajendraongole1 provided should be helpful.

    Besides, creating the sample table. You can also try the following DAX formula to select value in measure..

    Measure = 
    IF(
        CONTAINS('Table', 'Table'[Col1], "abc"),
        CALCULATE(
            SUM('Table'[cnt]),
            'Table'[date] = MAX('Table'[date])
        ),
        CALCULATE(
            SUM('Table'[sum_cnt]),
            'Table'[date] = MAX('Table'[date])
        )
    )

    The matrix visual is shown below.

    Best Regards,

    Wisdom Wu

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