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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

Create a measure to get year corresponding to peak sales sum

We have two input tables and I want to return a grid as shown below. The tables are related based on the Product column via one to many relationship.  The year corresponds to the maximum sales sum for an Asset.

Example : for A1 the max sales sum is 90 so the year corresponding to that is 2022

Pixie123_0-1667299099763.png

 

1 ACCEPTED SOLUTION

Hi,

Sorry for the mistake.

Please kindly check the below whether it suits your requirement.

 

 

Year of max sales sum: =
VAR _maxsales =
    MAXX ( SUMMARIZE ( Table2, Table2[Year], Table2[Sales] ), Table2[Sales] )
VAR _maxsalesyear =
    FILTER (
        SUMMARIZE ( Table2, Table2[Year], Table2[Sales] ),
        Table2[Sales] = _maxsales
    )
RETURN
    IF ( HASONEVALUE ( Table1[Asset] ), MAXX ( _maxsalesyear, Table2[Year] ) )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1667299865285.png

 

 

Year of max sales sum: =
VAR _newtable =
    ADDCOLUMNS (
        DISTINCT ( Table2[Year] ),
        "@salessum", CALCULATE ( SUM ( Table2[Sales] ) )
    )
VAR _maxsales =
    GROUPBY (
        _newtable,
        Table2[Year],
        "@maxsales", MAXX ( CURRENTGROUP (), [@salessum] )
    )
RETURN
    IF ( HASONEVALUE ( Table1[Asset] ), MAXX ( _maxsales, Table2[Year] ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Thanks! But this not render the correct result for A1, it should be 2022

 

Hi,

Sorry for the mistake.

Please kindly check the below whether it suits your requirement.

 

 

Year of max sales sum: =
VAR _maxsales =
    MAXX ( SUMMARIZE ( Table2, Table2[Year], Table2[Sales] ), Table2[Sales] )
VAR _maxsalesyear =
    FILTER (
        SUMMARIZE ( Table2, Table2[Year], Table2[Sales] ),
        Table2[Sales] = _maxsales
    )
RETURN
    IF ( HASONEVALUE ( Table1[Asset] ), MAXX ( _maxsalesyear, Table2[Year] ) )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Kudoed Authors