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

Summarize table and grouping values by multiple conditions in one column

Hello,

 

Please can someone help me with my calculation.

 

I have a dataset which looks like the below, I cannot change the structure of the data. I need to create a calculation which will multiply the 'UnitOfMeasure' (Recycled and Reused) against the associated Unit Weight for that 'AssetType'. e.g. Laptops Recycled (1438) * Laptops Unit Weight (2) = 2876

 

KpiDateAssetTypeUnitOfMeasurevolume
30/06/2023DocksRecycled               613
30/06/2023DocksReused         10,492
30/06/2023DocksUnit Weight                   1
30/06/2023keyboard / mouseRecycled           1,219
30/06/2023keyboard / mouseReused           4,357
30/06/2023keyboard / mouseUnit Weight                   1
30/06/2023LaptopsRecycled           1,438
30/06/2023LaptopsReused         16,676
30/06/2023LaptopsUnit Weight                   2
30/06/2023MobilityRecycled                 20
30/06/2023MobilityReused                 20
30/06/2023MobilityUnit Weight                   1
30/06/2023MonitorsRecycled               450
30/06/2023MonitorsReused           9,571
30/06/2023MonitorsUnit Weight                   8
30/06/2023NetworkingRecycled               202
30/06/2023NetworkingReused               322
30/06/2023NetworkingUnit Weight                   5
30/06/2023PrintersRecycled                  -  
30/06/2023PrintersReused                 11
30/06/2023PrintersUnit Weight                 20
30/06/2023ServerRecycled                 25
30/06/2023ServerReused                 26
30/06/2023ServerUnit Weight                 12
30/06/2023StorageRecycled               288
30/06/2023StorageReused               231
30/06/2023StorageUnit Weight                   1
30/06/2023SystemsRecycled               778
30/06/2023SystemsReused           6,379
30/06/2023SystemsUnit Weight                   3

 

I need to calculate the total for Recycled and Reused, in the example provided I should be returned with the total below of 12,218 Recycled and 146,299 Reused. I need to work out the row by row values for each asset type and then be able to role this up to the 'UnitofMeasure' so I can great graphs for 'Recycled' and 'Reused'

 

Asset TypeKPI DateUnitOfMeasure(Recycled)UnitOfMeasure(Reused)
Docks30/06/2023                                               631                                      10,492
keyboard / mouse30/06/2023                                           1,219                                        4,357
Laptops30/06/2023                                           2,876                                      33,352
Mobility30/06/2023                                                 20                                              20
Monitors30/06/2023                                           3,600                                      76,568
Networking30/06/2023                                           1,010                                        1,610
Printers30/06/2023                                                  -                                              220
Server30/06/2023                                               300                                            312
Storage30/06/2023                                               228                                            231
Systems30/06/2023                                           2,334                                      19,137
TotalTotal                                         12,218                                   146,299

 

I've tried the below measure which was worked against 'AssetType' but didn't like me rolling up to 'UnitofMeasure'

1.

recycled =
sumx(
    SUMMARIZE('Table','Table'[AssetType],"total rec",CALCULATE(sum('Table'[volume]),'Table'[UnitOfMeasure]="Recycled")*CALCULATE(sum('Table'[volume]),'Table'[UnitOfMeasure]="Unit Weight")),[total rec])
2.
reused =
sumx(
    SUMMARIZE('Table','Table'[AssetType],"total reu",CALCULATE(sum('Table'[volume]),'Table'[UnitOfMeasure]="Reused")*CALCULATE(sum('Table'[volume]),'Table'[UnitOfMeasure]="Unit Weight")),[total reu])



1 ACCEPTED SOLUTION

@Raymz112 

You can add an additional measure as follows this will work based on the selected UOM, 

UOM = IF( SELECTEDVALUE( Table7[UnitOfMeasure] ) = "Recycled" , [UnitOfMeasure(Recycled)] , [UnitOfMeasure(Reused)] ) 

You can add this to your chart 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

8 REPLIES 8
Thejeswar
Resident Rockstar
Resident Rockstar

Hello @Raymz112 ,

You can use the below measure to get the desired result

1. First Pivot your table such that Recycled, Reused and Unit_Weight are separate columns

2. Create the below 2 measures

Measure4 = SUMX('Table', 'Table'[Recycled] * 'Table'[Unit Weight])
Measure5 = SUMX('Table', 'Table'[Reused] * 'Table'[Unit Weight])

 

Thejeswar_0-1701783024395.png

 

Regards,

Hello,

 

Thank you for your help on this but I need to keep the data model the same. Do you know of a solution which doesn't involve pivoting? 

Fowmy
Super User
Super User

@Raymz112 

Create the following three measures and add it to a matrix viz, make sure you have Asset Type alrady added in your Matrix Row section:

 

 

KPI Date =  CALCULATE( MAX( Table7[KpiDate] ) )
------------------------------------------------------
UnitOfMeasure(Reused) = 
SUMX(
    VALUES(Table7[AssetType]),
    VAR __Reused = CALCULATE( MAX( Table7[volume] ) , Table7[UnitOfMeasure] = "Reused" )	
	VAR __UnitWeigh = CALCULATE( MAX( Table7[volume] ) , Table7[UnitOfMeasure] = "Unit Weight" )
	VAR __Result = __Reused * __UnitWeigh
		RETURN
		__Result
)
-------------------------------------------------------
UnitOfMeasure(Recycled) = 
SUMX(
    VALUES(Table7[AssetType]),
    VAR __Recycled = CALCULATE( MAX( Table7[volume] ) , Table7[UnitOfMeasure] = "Recycled" )	
	VAR __UnitWeigh = CALCULATE( MAX( Table7[volume] ) , Table7[UnitOfMeasure] = "Unit Weight" )
	VAR __Result = __Recycled * __UnitWeigh
		RETURN
		__Result
)

 

 

Fowmy_0-1701781568147.png

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hello,

 

Thank you for your help, unfortunately it doesn't work as the totals at the bottom are incorrect. I also want the associated value to show next to the 'UnitofMeasure' so that I can use it in my visuals, displaying the difference between the two.

 

The below is what I got from your calculation

Raymz112_0-1701782252367.png

 

@Raymz112 

Please check the reply, I just updated it

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

The update works as shown below but then doesn't allow me to filter the data from the 'UnitofMeasure' column which I need for my visualisations. I ideally want all of them to be in one measure and filterable by 'UnitofMeasure' being either 'Recycle' or 'Reused'

Raymz112_0-1701784133648.png

 

@Raymz112 

You can add an additional measure as follows this will work based on the selected UOM, 

UOM = IF( SELECTEDVALUE( Table7[UnitOfMeasure] ) = "Recycled" , [UnitOfMeasure(Recycled)] , [UnitOfMeasure(Reused)] ) 

You can add this to your chart 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Smashed it - thank you! 🙂

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.