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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors