Search code examples
daxpowerbi-desktopdaxstudio

Groupby and sum the max in DAX


I have a sample data as below and I would like to create a powerbi card. The dax code should first groupby based on Source and sum the measure of max(FYandFW). How to get around with this ?

Source  FYandFW num 
Company A   202453  **
Company A   202452  
Company A   202451  
Company B   202501  
Company B   202502  **
Company B   202453  

Expected Answer Summing measures for **

Solution

  • Here is one approach:

    Your Measure = 
      SUMX(
        DISTINCT(YourTable[Source]),
        CALCULATE(
          [your sum measure],
          TOPN(1, CALCULATETABLE(YourTable), [FYandFW num], DESC)
        )
      )