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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ylin88_waters
Helper I
Helper I

How to Create Measures to Calculate Totals by ID, and by Types in Another Related Table:

Hi

I have two sales data tables linked by PartNumber:

Table 1 -

IDPartNumberSalesUnit
111101110
111201120
111201215
222101117
22220118
222201214
333101112
333201218

 

Table 2 -

PartNumberProdTypeType
1011AA
2011B1B
2012B2B

 

I'm trying to create following measures to calculate the sum of units by ID, and also by types in the table2:

1. Total Units: sum of all units by ID
2. Units_by_Type: sum of units by Type by ID
2. Units_by_ProdType: Sum of units by ProdType by ID

 

When I put them in a table visual on PBI dashboard, I should get following:

IDProdTypeTypeSalesUnitsUnits_by_ProdTypeUnits_by_TypeTotal_Units
111AA10101045
111B1B20203545
111B2B15153545
222AA17171739
222B1B882239
222B2B14142239
333AA12121230
333B2B18181830

 

Because the types are in another table,  that makes Dax code more complicated and I was not able to get it right. Any help is really appreciated.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @ylin88_waters 

 

You can try the following methods.

Column:

ProdType = RELATED('Table 2'[ProdType])
Type = RELATED('Table 2'[Type])

vzhangti_1-1676012236136.png

Measure:

Units_by_ProdType = CALCULATE(SUM('Table 1'[SalesUnit]),ALLEXCEPT('Table 1','Table 1'[ID],'Table 1'[ProdType]))
Units_by_Type = CALCULATE(SUM('Table 1'[SalesUnit]),ALLEXCEPT('Table 1','Table 1'[Type],'Table 1'[ID]))
Total_Units = CALCULATE(SUM('Table 1'[SalesUnit]),ALLEXCEPT('Table 1','Table 1'[ID]))

vzhangti_2-1676012257468.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @ylin88_waters 

 

You can try the following methods.

Column:

ProdType = RELATED('Table 2'[ProdType])
Type = RELATED('Table 2'[Type])

vzhangti_1-1676012236136.png

Measure:

Units_by_ProdType = CALCULATE(SUM('Table 1'[SalesUnit]),ALLEXCEPT('Table 1','Table 1'[ID],'Table 1'[ProdType]))
Units_by_Type = CALCULATE(SUM('Table 1'[SalesUnit]),ALLEXCEPT('Table 1','Table 1'[Type],'Table 1'[ID]))
Total_Units = CALCULATE(SUM('Table 1'[SalesUnit]),ALLEXCEPT('Table 1','Table 1'[ID]))

vzhangti_2-1676012257468.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Yes, This works. Thanks for your help!!

 

YL

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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