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
M4x
Regular Visitor

Combining two tables in a pivot chart / calculating SUM table 2 based on row label of table 1

Hey everybody,

 

I assume this shouldn't be a big deal but I've already spend hours on this and I'm not able to figure it out on my own.

 

I've two tables which I'd like to combine in a pivot chart, including claculations between both tables. I'd like to have a pivot chart, showing:

  1. x-axis: products (working ✔️)
  2. y-axis (main): Distinct count of serial numbers of serviced products (working ✔️)
  3. y-axis (secondary): Values on x-axis (main) in relation to build products (not working )

The example file can be found here: example_combine_two_tables_in_pivot_chart.xlsx 

 

Input data (the two tables) - worksheet "Input_data"

table "tbl_build_products" - which products where build in which year and in which amount (multiple entries, not aggregated by year / product)

Productbuild yearamount of products build
A20201
B20201
C20202
A20202
B20203
C20213
A20214
B20214
C20215
A20215

 

table "tbl_serviced_products" - which products where serviced when (multiple entries per product and serial number possible)

Productserial numberservice year
AS12020
BS22020
CS32020
AS12021
BS22021
CS62021
AS72020
BS82020
CS92020
AS102020
BS22021
CS122021
AS132021
BS142021
CS152021
AS162020
BS172020
CS182021

 

current data model

I've marked the columns which contain identical values.

M4x_0-1699010146793.png

 

How it looks like at the moment - worksheet "Pivot_table_chart"

M4x_1-1699007361321.png

blue bars = Distinct count of serial numbers of serviced products (working ✔️)

orange bars = Instead, here I'd like to show the values on x-axis (main) in relation to build products (not working ). Currently, the orange bars are representing the sum of build products in total, not according to the corresponding row labels. Underlying, there's a measure which is currently summing column "amount of products build" in table "tbl_build_products".

 

This measure looks like this: 

 

=SUMX(VALUES(tbl_build_products[amount of products build]);[Sum of amount of products build])

 

 

M4x_2-1699007689132.png

 

What I'm trying to achieve (next steps)

  1. Change measure in a way that I'm getting the sum of column "amount of products build" in table "tbl_build_products" but using the row labels as a kind of filter
  2. Calculate the percentage of "Distinct Count of serial number" in relation to all build products of the same product (see Nr. 1)
  3. Instead of the orange bars, show the percentage value of Nr. 2 as a line diagram on the secondary y-axis

I'm open to other ideas to achieve my goal. I'm looking forward to your assistance!

Thanks 🙂

 

edit

I've created another table where I've used regular excel formulas to show what I'm trying to achieve in the end. My problem is that the real dataset is more complicated and the helper column "helper_column_count_distinct" I've inserted into "tbl_serviced_products" (worksheet Input_data) only works as long as all entries are valid. As soon as I start filtering those entries in a pivot chart using another column, the values in the helper column wouldn't be correct anymore. That's why I'm trying to make it work in a way where I can use the full power of a pivot chart.

 

Here is the updated example file: example_combine_two_tables_in_pivot_chart_2.xlsx 

 

Input

tbl_service_products with helper column

 

Productserial numberservice yearhelper_column_count_distinct
AS120200,5
BS220200,3
CS320201
AS120210,5
BS220210,3
CS620211
AS720201
BS820201
CS920201
AS1020201
BS220210,3
CS1220211
AS1320211
BS1420211
CS1520211
AS1620201
BS1720201
CS182021

1

 

Mockup end result using regular excel formulas - worksheet "input_combined"

tbl_input_combined

productbuild products amount totalserviced products distinct serial numberrate of serviced products
A12542%
B8450%
C106

60%

 

M4x_1-1699025488031.png

 

This results in this pivot table / chart (that's basically what I'd like to achieve without using a helper column and regular forumas):

M4x_2-1699025555665.png

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

It's not two tables, it's four.  Here's the data model

 

lbendlin_0-1699138390159.png

Then you can create your measure as needed.

 

lbendlin_1-1699138699018.png

 

I used an implicit DISTINCTCOUNT for the columns, in Excel you will need to create an explicit measure.

 

See attached.

View solution in original post

5 REPLIES 5
M4x
Regular Visitor

Thank you very much, that's what I've needed 😀

I replaced Products from tbl_serviced_products with Products from tbl_Products and now it's working 🙄 😁

 

M4x_4-1699259589336.png

 

M4x_5-1699259736585.png

 

M4x_6-1699259749431.png

 

M4x_7-1699259808413.png

 

M4x_8-1699259828180.png

 

Hint for myself or everybody else who's trying to achieve the same things: To be able to filter by build year, I've to add another column "build year" to tbl_serviced_products and link Year in tbl_year with build year in tbl_serviced_products. In my previous example files, I had Year in tbl_calendar linked to service year in tbl_serviced_products.

M4x_9-1699260630025.png

 

Thanks a lot, now I'm trying to adapt this to my original dataset.

M4x
Regular Visitor

I've adapted this to my original dataset and it's working great, thanks again @lbendlin ! 😁

lbendlin
Super User
Super User

It's not two tables, it's four.  Here's the data model

 

lbendlin_0-1699138390159.png

Then you can create your measure as needed.

 

lbendlin_1-1699138699018.png

 

I used an implicit DISTINCTCOUNT for the columns, in Excel you will need to create an explicit measure.

 

See attached.

Thank you very much for your reply!

 

Unfortunately, using Power BI is not possible for me (yet). I've recreated the data model you've shown in Excel and created three measures according to your example:

  • rate of service - part 1: Distinct count of SN (working ✔️)

 

=DISTINCTCOUNT(tbl_serviced_products[serial number])
​

 

  • rate of service - part 2: SUM of build products (not working  - I'm getting the total amount but I need it according to the product within the same row. This isn't a surprise, please have a look at my "statement" at the bottom)

 

=SUM(tbl_build_products[amount of products build])​

 

  • rate of service - part 3: Divide 1 by 2 (working ✔️ - but the result isn't what I'm looking for of course)

 

=DIVIDE([rate of service - part 1 (Distinctcount SN)];[rate of service - part 2 (SUM build products)])​

 

 

I've the feeling that you're aware of that and you've already tried to tell me that but I didn't get it... 🙄 

 

M4x_0-1699227241715.png

 

M4x_2-1699227467518.png

 

Here's the example file: example_combine_two_tables_in_pivot_chart_4 

Is the value in column A coming from the tbl_Products table?

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