Forum Discussion
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])
)
- Anonymous1 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
- rajendraongole1
Super User
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.
- grazitti_sapna
Super User
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!
- divyed
Super User
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
- AnonymousNot 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.