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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
FH_1
Frequent Visitor

Show products purchased at a certain service

Dear all,

 

I need you help with the following. I want to show what are the (top x) products I sold for a certain service. The service I sold has the same order_ID as the product. But I have a struggle to get this done and I hope I could explain it well enough.

 

My data table looks like this: 

 

 

2020-00012-1-2020 15:44Dagmar2676653serviceHeren knippen1
2020-00022-1-2020 16:06Dagmar2679205serviceHeren knippen 2 week actie1
2020-00032-1-2020 18:50Dagmar2709407serviceWoman | Cutting Delux1
2020-00032-1-2020 18:50Dagmar2709407serviceHighlights medium45
2020-00032-1-2020 18:50Dagmar2709407serviceVibrance toner 60cc1
2020-00043-1-2020 11:32Dagmar2682832serviceHeren knippen1
2020-00053-1-2020 12:31Dagmar2911638serviceWoman | Cutting Delux1
2020-00053-1-2020 12:31Dagmar2911638serviceHighlights medium40
2020-00053-1-2020 12:31Dagmar2911638serviceVibrance toner 60cc1
2020-00053-1-2020 12:31Dagmar2911638productGrand Opening Shampoo1
2020-00053-1-2020 12:31Dagmar2911638productEssential1
2020-00063-1-2020 13:02Dagmar4071646serviceHeren knippen1
2020-00073-1-2020 13:32Dagmar2676681serviceHeren knippen1
2020-00083-1-2020 16:24Dagmar3023540serviceWoman | Cutting Delux1
2020-00083-1-2020 16:24Dagmar3023540serviceUitgroei verven1
2020-00083-1-2020 16:24Dagmar3023540serviceVibrance toner 120cc1
2020-00093-1-2020 16:35Dagmar4243604productPicture Perfect1
2020-00104-1-2020 11:33Dagmar2726032serviceWoman | Cutting Delux1
2020-00104-1-2020 11:33Dagmar2726032serviceUitgroei verven1
2020-00104-1-2020 11:33Dagmar2726032productRhassoul Oil1

 

It would be great if someone could support me.

 

Regards, Fabian

9 REPLIES 9
v-juanli-msft
Community Support
Community Support

Hi @FH_1 

If Rocco_sprmnt21's answer help you slove problems, could you kindly accept it as a solution to close this case and help the other members find it more quickly?

If not, please feel free to let me know, we will work further to help you.
 
Best Regards
Maggie
FH_1
Frequent Visitor

FH_1_0-1593001811224.png

 

Hi @FH_1 

Would you like to order the [quantity] per [type]?

If not, you could give expected result on your sample.

 

Best Regards

Maggie

Anonymous
Not applicable

add these lines to your code:

 

 

 

  top=5, 
  tab=Table.MaxN(Table.SelectRows(youTab, each [type]="service"),{"quantity"},top)
in
    tab

 

 

or, if you need a more complex filter condition, use some similar to this

 

 

Table.MaxN(Table.SelectRows(youTab, each [type]="service" and Text.Contains([desc],"Heren")),{"quantity"},top)

 

 

Hi @Anonymous 

 

Tryed your soulition but the I got an error in my query. BTW this is my first time using a code in the table itself.

 

Can this be solved with a measure or a new colomun as well?

Anonymous
Not applicable

Ok. I will give another try. But you should clarify the relation between service and product.

If for the same order-id you have one service e multiple products, all is ok.

But in your table there are cases where for the same order-id you have many services and many products.

In this case what is the expected results?

 

hi @Anonymous ,

 

In deed there can be several services and multiple products. What I need to show is the following:

 

Left tabel is my actual data from my database. What I want to express in my report is the right tabel. Is this possible?

 

Service_vs_Product.png

 

If this is not possible it would ok to show the relation of the first service in an order to mutiple products.

 

Big thanks in advance.

Anonymous
Not applicable

try appending this in your advanced a editor just after the line where you loaded in your table (in my code called yourTab):

 

 

    #"Raggruppate righe" = Table.Group(yourTab, {"ID"}, {{"serv_and_prod", each  Table.Group(_,{"type","desc"},{"quantity", each _[quantity]{0}})}}),
    #"Tabella serv_and_prod espansa" = Table.ExpandTableColumn(#"Raggruppate righe", "serv_and_prod", {"type", "desc", "quantity"}, {"type", "desc", "quantity"}),

    servizi = Table.SelectRows(#"Tabella serv_and_prod espansa", each ([type] = "service")),
    prodotti = Table.SelectRows(#"Tabella serv_and_prod espansa", each ([type] = "product")),


    mt = Table.NestedJoin(servizi,{"ID"},prodotti,{"ID"},"TypeProduct",JoinKind.LeftOuter),
    #"Tabella TypeProduct espansa" = Table.ExpandTableColumn(mt, "TypeProduct", {"type", "desc", "quantity"}, {"type.1", "desc.1", "quantity.1"})
in
    #"Tabella TypeProduct espansa"

 

hi @v-juanli-msft ,

 

let me share an example, if you look to the table, you can see at order ID 2020 - 0010 that someone purchased 2 services and 1 product. I want to be able to show that if a customers bought service X, what are the products people bought as wel.

 

e.g.

 

hi @v-juanli-msft ,

 

let me share an example, if you look to the table, you can see at order ID 2020 - 0010 that someone purchased 2 services and 1 product. I want to be able to show that if a customers bought service X, what are the products people bought as wel.

 

e.g.

ServiceProduct
Woman CuttingProduct A 90 pcs
 Product B 75 pcs
 Product C 60 pcs
 Product D 30 pcs
 Product E 10 pcs

 

 

So I dont know if this is possible with having the data all in on table.

 

Regards, Fabian

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors
Top Kudoed Authors