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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AloisOh
Frequent Visitor

Sum of latest values based on the latest distinct value of another column

Hi everyone,

For context, the title column is named after project sites and the worker and staff columns indicate the strength at the point of time. How can I sum the latest worker and staff values from all sites?

AloisOh_0-1640925632280.png

Regards,
Alois

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @AloisOh,

 

As  smpa01 mentioned, we couldn't find the columns which can distinguish the time sequence, like Date or others. I think the time sequenc is distinguished according to the sequence of the same site. Here I suggest you to add an Index column by Group by Power Query.

Firstly, Group all rows by [Title] in Power Query.

1.png

 Go to Advanced editor and add a new line of code that can generate indices in all the previously grouped tables.

Indexed = Table.TransformColumns(#"Grouped Rows", {{"Rows", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}})

Then expand your table and rename column names.

1.png

For reference: How to create group index with Power Query or R

Measure:

Sum of Latest Worker =
VAR _SUMMARIZE =
    SUMMARIZE (
        'Table',
        'Table'[Title],
        "MAXINDEX", CALCULATE ( MAX ( 'Table'[GroupIndex] ) ),
        "LATESTWORKER",
            CALCULATE (
                SUM ( 'Table'[Worker] ),
                FILTER ( 'Table', 'Table'[GroupIndex] = MAX ( 'Table'[GroupIndex] ) )
            )
    )
RETURN
    SUMX ( _SUMMARIZE, [LATESTWORKER] )
Sum of Latest Staff =
VAR _SUMMARIZE =
    SUMMARIZE (
        'Table',
        'Table'[Title],
        "MAXINDEX", CALCULATE ( MAX ( 'Table'[GroupIndex] ) ),
        "LATESTSTAFF",
            CALCULATE (
                SUM ( 'Table'[Staff] ),
                FILTER ( 'Table', 'Table'[GroupIndex] = MAX ( 'Table'[GroupIndex] ) )
            )
    )
RETURN
    SUMX ( _SUMMARIZE, [LATESTSTAFF] )

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @AloisOh,

 

As  smpa01 mentioned, we couldn't find the columns which can distinguish the time sequence, like Date or others. I think the time sequenc is distinguished according to the sequence of the same site. Here I suggest you to add an Index column by Group by Power Query.

Firstly, Group all rows by [Title] in Power Query.

1.png

 Go to Advanced editor and add a new line of code that can generate indices in all the previously grouped tables.

Indexed = Table.TransformColumns(#"Grouped Rows", {{"Rows", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}})

Then expand your table and rename column names.

1.png

For reference: How to create group index with Power Query or R

Measure:

Sum of Latest Worker =
VAR _SUMMARIZE =
    SUMMARIZE (
        'Table',
        'Table'[Title],
        "MAXINDEX", CALCULATE ( MAX ( 'Table'[GroupIndex] ) ),
        "LATESTWORKER",
            CALCULATE (
                SUM ( 'Table'[Worker] ),
                FILTER ( 'Table', 'Table'[GroupIndex] = MAX ( 'Table'[GroupIndex] ) )
            )
    )
RETURN
    SUMX ( _SUMMARIZE, [LATESTWORKER] )
Sum of Latest Staff =
VAR _SUMMARIZE =
    SUMMARIZE (
        'Table',
        'Table'[Title],
        "MAXINDEX", CALCULATE ( MAX ( 'Table'[GroupIndex] ) ),
        "LATESTSTAFF",
            CALCULATE (
                SUM ( 'Table'[Staff] ),
                FILTER ( 'Table', 'Table'[GroupIndex] = MAX ( 'Table'[GroupIndex] ) )
            )
    )
RETURN
    SUMX ( _SUMMARIZE, [LATESTSTAFF] )

Result is as below.

1.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

smpa01
Super User
Super User

@AloisOh  How can I sum the latest worker and staff values from all sites _ what indication the table has that defines latest? Is there a Date column or somehing else?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
amitchandak
Super User
Super User

@AloisOh , do you have the site and date?

 

You need to try a measure like

 

Measure =
VAR __id = MAX ('Table'[site] )
VAR __date = CALCULATE ( MAX('Table'[Date] ), ALLSELECTED ('Table' ), 'Table'[site] = __id )
CALCULATE ( Sum ('Table'[Worker] ), VALUES ('Table'[site] ),'Table'[site] = __id,'Table'[Date] = __date )

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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