Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Saxon10
Post Prodigy
Post Prodigy

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.

Saxon10_2-1644103007119.png

 

 

 

Data and Result:

 

itemcountry codeResult
123ADMKDMK
123DMKDMK
1234ADMKADMK
456DMKDMK
81DMKDMK
456ADMKDMK
890DMKDMK
890DMKDMK
564ADMKDMK
564DMKDMK

 

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.

 

 

Saxon10_1-1644102956124.png

 

I am looking for New calculated column options without duplicaation columns.

 

 

2 ACCEPTED SOLUTIONS
CNENFRNL
Community Champion
Community Champion

You can easily replicate the logic of Excel formula in calcualted column,

CNENFRNL_0-1644142278144.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

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] )

vkkfmsft_0-1644990853731.png

Result = 
VAR code =
    CALCULATE (
        MAX ( DATA[Column] ),
        KEEPFILTERS ( DATA[item] = EARLIER ( REPORT[Item] ) )
    )
RETURN
    COALESCE ( code, "NA" )

vkkfmsft_1-1644990965211.png

 

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.

 

View solution in original post

7 REPLIES 7
Saxon10
Post Prodigy
Post Prodigy

@CNENFRNL,

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)

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] )

vkkfmsft_0-1644990853731.png

Result = 
VAR code =
    CALCULATE (
        MAX ( DATA[Column] ),
        KEEPFILTERS ( DATA[item] = EARLIER ( REPORT[Item] ) )
    )
RETURN
    COALESCE ( code, "NA" )

vkkfmsft_1-1644990965211.png

 

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.

 

@v-kkf-msft,

Thanks for your reply and your solution working fine. 

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1644106165288.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL ,

 

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)

 

Saxon10_0-1644139219780.png

 

Winth in table:

 

=IF(COUNTIFS($A$3:$A$12,$A3,$B$3:$B$12,"DMK"),"DMK",$B3)

 

Saxon10_1-1644139302320.png

 

CNENFRNL
Community Champion
Community Champion

You can easily replicate the logic of Excel formula in calcualted column,

CNENFRNL_0-1644142278144.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@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_0-1644134493933.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors