Forum Discussion
Calculate Min/max column (Dax)
Hi,
I have table and the table contains the following columns are item and country code.
Query1
The same item has two different country code are ADMK and DMK. If same item has two different country code then DMK is first concern and ADMK is second concern. I want unique code against each item within the table.
Data and Result:
| item | country code | Result |
| 123 | ADMK | DMK |
| 123 | DMK | DMK |
| 1234 | ADMK | ADMK |
| 456 | DMK | DMK |
| 81 | DMK | DMK |
| 456 | ADMK | DMK |
| 890 | DMK | DMK |
| 890 | DMK | DMK |
| 564 | ADMK | DMK |
| 564 | DMK | DMK |
Query 2:
I have different situation.
I have a two tables are data and report in data table the following columns are item(item duplicated) and country code and report table item only(unique).
If same item has two different country code then DMK is first concern and ADMK is second concern.
I want unique item against the item in report table and if item does not exist then NA.
I am looking for New calculated column options without duplicaation columns.
You can easily replicate the logic of Excel formula in calcualted column,
Hi Saxon10 ,
Please try the following calculated columns:
Column = VAR DMK = CALCULATE ( COUNTROWS ( DATA ), FILTER ( DATA, DATA[item] = EARLIER ( DATA[item] ) && DATA[country code] = "DMK" ) ) RETURN IF ( DMK > 0, "DMK", [country code] )Result = VAR code = CALCULATE ( MAX ( DATA[Column] ), KEEPFILTERS ( DATA[item] = EARLIER ( REPORT[Item] ) ) ) RETURN COALESCE ( code, "NA" )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
7 Replies
- CNENFRNL
Community Champion
- CNENFRNL
Community Champion
- Saxon10
Post Prodigy
CNENFRNL ,
thanks for your reply and your solution working well but I can't see the both table item columns reference in your formula? How do I know it's giving the correct result against the id? Is that possibile to add the both item columns reference in your formula or alternative way to achive the result inculding both table item columns reference?
I want the same result within the table. How can I get it? I am try to copy the same formula in data table but it's not working. can you assit me.
- Saxon10
Post Prodigy
How can I replicated the same thing in power bi.
in Excel I am applying the following formula =IFERROR(IF(COUNTIFS(A$3:A$12,D3,B$3:B$12,"DMK"),"DMK",INDEX($B:$B,MATCH($D3,$A:$A,0))),"NA") (inbetween two tables)
- v-kkf-msft
Community Support
Hi Saxon10 ,
Please try the following calculated columns:
Column = VAR DMK = CALCULATE ( COUNTROWS ( DATA ), FILTER ( DATA, DATA[item] = EARLIER ( DATA[item] ) && DATA[country code] = "DMK" ) ) RETURN IF ( DMK > 0, "DMK", [country code] )Result = VAR code = CALCULATE ( MAX ( DATA[Column] ), KEEPFILTERS ( DATA[item] = EARLIER ( REPORT[Item] ) ) ) RETURN COALESCE ( code, "NA" )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- Saxon10
Post Prodigy
Thanks for your reply and your solution working fine.