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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
alir22456
Helper I
Helper I

Power Query DAX

I have a dataset of customers and the services (Plans) they had bought. I am working on a Cross-Selling analysis project. The data is arranged as below:

 

alir22456_0-1720944592188.png

Based on this data, I was able to generate the list of the customers who (for example) bought Plan 4 and Plan 10.

alir22456_1-1720944591846.png

 

Now I need a list of customers who bought Plan 10 minus the customers who bought Plan 10 and Plan 4

For example:

 

alir22456_3-1720945121454.png

 

Targeted Customers = Plan 10 Customers - (Plan 10 Customers and Plan 4 Customers)

 

Thanks

3 REPLIES 3
PhilipTreacy
Super User
Super User

Hi @alir22456 

 

You've posted in the Power Query forum.  Power Query doesn't use DAX.

 

I'll move this topic to the Desktop forum where you will get a solution in DAX.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


dufoq3
Super User
Super User

Hi @alir22456

 

Result

dufoq3_0-1720947019796.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci4tLsnPTS0yVNJRCshJzFMwNFCK1cEiboRd2ARF2AgmbIYibAwTNsUubIRd2Bi7sKEhirgJDpebYjfdFLvpptg9ZIrd5aaE7DRENd0Mu+lmyMbEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customers = _t, Services = _t]),
    GroupedRows = Table.Group(Source, {"Customers"}, {{"Services", each List.Distinct([Services]), type table}}),
    Transformed = [ plan10 = Table.SelectRows(GroupedRows, each List.Contains([Services], "Plan 10"))[Customers],
    plan10_and_4 = Table.SelectRows(GroupedRows, each List.ContainsAll([Services], {"Plan 10", "Plan 4"}))[Customers],
    tbl = #table(type table[Services=text, Customers=text], {
        { "Plan 10", Text.Combine(plan10, ", ") },
        { "Plan 10 and Plan4", Text.Combine(plan10_and_4, ", ") },
        { "Plan 10 - (Plan10 and Plan4)", Text.Combine(List.Difference(plan10, plan10_and_4), ", ") }
      })
   ][tbl]
in
    Transformed

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi @dufoq3 

Thanks but i'm looking for a DAX Measure to calculate the list of customers. I have a slicer for the service plans. The below DAX measure returns a list of customers who had purchased the selected services in the slicer.

alir22456_0-1720948959739.png

Customers with Selected Services = 
VAR __tmpTable1 =
GENERATE(
DISTINCT('Table'[Customers]),
EXCEPT(
DISTINCT('Table'[Services]),
CALCULATETABLE(DISTINCT('Table'[Services]))
)
)
VAR __tmpTable2 = SUMMARIZE(__tmpTable1, 'Table'[Customers])
VAR __tmpTable3 = EXCEPT(DISTINCT('Table'[Customers]), __tmpTable2)
VAR __Result = CONCATENATEX(__tmpTable3, [Customers], ",", [Customers])
RETURN
__Result

It returns a list of customers who bought Plan 10 and Plan 4 as below:

Customer1, Customer5, Customer 6

 

I want another meausre that returns a list of total customers who bought Plan 10 minus the customers who bought Plan 10 and Plan 4.

 

Note: The names Plan 10, Plan 4... are just for examples.

 

Thanks

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.