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

Summarize keeping only the last value for each id

Hello everyone, I'm trying to create a summarized table where I get the latest score for each item. 

 

My data is like this:

id_item      id_week

     score

11

90

12

70

13

80

21

40

22

60

33

30

 

And, with the use of summarize I would like to accomplish the following table:

id_item      id_week

       score

13

80

22

60

33

30

 

Where there is a row for each item and the score corresponding to the latest id_week that an item have.

 

Is it possible?

 

Thanks in advance

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Untitled.png

 

New table =
CALCULATETABLE (
    Data,
    TREATAS (
        GROUPBY (
            Data,
            Data[id_item],
            "@maxidweek", MAXX ( CURRENTGROUP (), Data[id_week] )
        ),
        Data[id_item],
        Data[id_week]
    )
)

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.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Untitled.png

 

New table =
CALCULATETABLE (
    Data,
    TREATAS (
        GROUPBY (
            Data,
            Data[id_item],
            "@maxidweek", MAXX ( CURRENTGROUP (), Data[id_week] )
        ),
        Data[id_item],
        Data[id_week]
    )
)

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.


Go to My LinkedIn Page


Thank you Jihwan, that's working perfectly.
I have another doubt, what would you new to modify if you would like to have another column in the original table showing the score value for of the latest week for each row?

e.g.

id_item id_weekscorelast_score for item
119080
127080
138080
214060
226060
333030

 

Thanks!

Hi,

thank you for your message.

If you want to create a new column in the table, please check the below picture and the attached pbix file.

It is for creating a new column.

 

Picture1.png

 

Last_week_score CC =
VAR _maxweeknumber =
    MAXX (
        FILTER ( Data, Data[id_item] = EARLIER ( Data[id_item] ) ),
        Data[id_week]
    )
RETURN
    SUMMARIZE (
        FILTER (
            Data,
            Data[id_item] = EARLIER ( Data[id_item] )
                && Data[id_week] = _maxweeknumber
        ),
        Data[score]
    )

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.


Go to My LinkedIn Page


Excelent! thank you very much again.

 

Have a nice day!

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.