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
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
v-rzhou-msft
Community Support
Community Support

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
v-rzhou-msft
Community Support
Community Support

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 )

 

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.

Top Solution Authors