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
ahumke
Helper I
Helper I

DAX table syntax to select max year and associated values within categories

I'm trying to create a new table using DAX that will select the max year and an associated value (KPI weighted score component) of that year within three categories. (area, program title, and KPI metric).  I can get the table to generate with the statement below but the "KPI Weghted Score Component" is not returning the expected value associated with that max year (it returns the max within the five years listed).  How do I fix this?
 
ProgramSummary = GROUPBY('SummaryKPI', 'SummaryKPI'[Area], 'SummaryKPI'[Program Title], 'SummaryKPI'[KPI Metric], "MAXYear", maxx(CURRENTGROUP(), 'SummaryKPI'[JanuaryDate]),"Score", maxx(CURRENTGROUP(),'SummaryKPI'[KPI Weighted Score Component]))
 
1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @ahumke ,

 

Make a little modification to above DAX formula.

ProgramSummary =
ADDCOLUMNS (
    GROUPBY (
        'SummaryKPI',
        'SummaryKPI'[Area],
        'SummaryKPI'[Program Title],
        'SummaryKPI'[KPI Metric],
        "MAXYear", MAXX ( CURRENTGROUP (), 'SummaryKPI'[JanuaryDate] )
    ),
    "Score", LOOKUPVALUE (
        SummaryKPI[KPI Weighted Score Component],
        SummaryKPI[Area], [Area],
        SummaryKPI[Program Title], [Program Title],
        SummaryKPI[KPI Metric], [KPI Metric],
        SummaryKPI[JanuaryDate].[Date], [MAXYear]
    )
)

1.png

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

5 REPLIES 5
v-yulgu-msft
Employee
Employee

Hi @ahumke ,

 

Make a little modification to above DAX formula.

ProgramSummary =
ADDCOLUMNS (
    GROUPBY (
        'SummaryKPI',
        'SummaryKPI'[Area],
        'SummaryKPI'[Program Title],
        'SummaryKPI'[KPI Metric],
        "MAXYear", MAXX ( CURRENTGROUP (), 'SummaryKPI'[JanuaryDate] )
    ),
    "Score", LOOKUPVALUE (
        SummaryKPI[KPI Weighted Score Component],
        SummaryKPI[Area], [Area],
        SummaryKPI[Program Title], [Program Title],
        SummaryKPI[KPI Metric], [KPI Metric],
        SummaryKPI[JanuaryDate].[Date], [MAXYear]
    )
)

1.png

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you!  that worked perfectly!

HotChilli
Super User
Super User

I'm not an expert in the GROUPBY function but it does look like any reference to CURRENTGROUP relates to the group created before you start using the CURRENTGROUP() function.  There may be a way to say 'get me the field next to the max [January Date]' but I don't know how to do that.

However, it looks like you could create a calculated column and use LOOKUPVALUE e.g.

Column1 = LOOKUPVALUE(SummaryKPI[KPI Weighted Score Component],  SummaryKPI[Area], ProgramSummary[SummaryKPI_Area], SummaryKPI[Program Title], ProgramSummary[SummaryKPI_Program Title], SummaryKPI[KPI Metric], ProgramSummary[SummaryKPI_KPI Metric], SummaryKPI[JanuaryDate], ProgramSummary[MAXYear] )

I am getting an error on that formula that "A single value for column 'summaryKPI_Area' cannot be determined. While using that code...      

OK, you are going to have to debug this. 

I used the data you provided. I used 'Get Data' to pull the data from Excel.  I ran the DAX to create the ProgramSummary table. I then created the new column (with the LOOKUPVALUE code) in the ProgramSummary table.

 

So at your side, something different is happening. Let me know what you find.

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.