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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.