Forum Discussion

Saxon10's avatar
Saxon10
Icon for Post Prodigy rankPost Prodigy
4 years ago
Solved

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:

 

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.

 

 

 

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

 

 

  • 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

    • Saxon10's avatar
      Saxon10
      Icon for Post Prodigy rankPost Prodigy

      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)

       

       

      Winth in table:

       

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

       

       

      • CNENFRNL's avatar
        CNENFRNL
        Icon for Community Champion rankCommunity Champion

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

    • Saxon10's avatar
      Saxon10
      Icon for Post Prodigy rankPost 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's avatar
    Saxon10
    Icon for Post Prodigy rankPost 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)

    • v-kkf-msft's avatar
      v-kkf-msft
      Icon for Community Support rankCommunity 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.