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
petejigsaw
Frequent Visitor

Calculating sales of add-on products

I'm working on measuring penetration of sales of add-on products by order so that I can prepare a dashboard for each salesperson showing penetration of 'add-ons' in various product groups.

 

The below table shows my raw data.  It lists the SQL database lines by order (multiple entries per order item - that's just how our system records transactions), including a column showing if the item is a 'qualifying product' for the 'add-on' type. It then has a column showing whether the 'add-on' was sold.

 

My desired output is at the bottom - essentially I need to be able to show:

  • Total orders
  • Total orders that have a qualifying product on them
  • Total orders which include the 'add-on'

 

Order No.Stock_IDItemQualifying productAdd-on soldSales ValueGroup Code
39843158048Bed 110-£1,394BE-MA-PS
39843158048Bed 110£1,334BE-MA-PS
39843158048Bed 110£1,394BE-MA-PS
39843140562Bed 210-£1,896BE-DB-PS
39843140562Bed 210£1,825BE-DB-PS
39843140562Bed 210£1,896BE-DB-PS
39843130111Pillow0-1-£26BE-BA-PI
39843130111Pillow01£26BE-BA-PI
39843130111Pillow01£26BE-BA-PI
       
40152165256Table00-£1,000DI-TB-OK
40152165256Table00£950DI-TB-OK
40152165256Table00£1,000DI-TB-OK
40152131999Bed 210-£1,896BE-DB-PS
40152131999Bed 210£1,825BE-DB-PS
40152131999Bed 210£1,896BE-DB-PS
       
39999175845Table00-£1,000DI-TB-OK
39999175845Table00£950DI-TB-OK
39999175845Table00£1,000DI-TB-OK
       
Desired output     
Number of orders3    
Number of qualifying orders2   
Number of qualifying orders with add-on1  

 

I have tried all manner of measures to achieve this, without success.

 

Any suggestions or pointers on how to achieve the required output would be awesome!

 

Thanks in advance

 

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can use the below measures

Number of orders = DISTINCTCOUNT( 'Table'[Order no])

Number of qualifying orders =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Order no] ),
    'Table'[Qualifying product] = 1
)

Number of qualifying orders with addon =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Order no] ),
    'Table'[Add-on sold] = 1
)

View solution in original post

6 REPLIES 6
petejigsaw
Frequent Visitor

@johnt75Thanks for the follow-up answer on this query.

Your logic makes perfect sense, and performance is an issue given the size of my dataset.

 

I have come across a quirk using your original solution which I wondered if you could help overcome. In my original data, if the first order only had the below lines (because the add-on was entered on the order and then removed), how would I show that Add-on sales were ZERO?  Your

 

Order No.Stock_IDItemQualifying productAdd-on soldSales ValueGroup Code
39843158048Bed 110-£1,394BE-MA-PS
39843158048Bed 110£1,334BE-MA-PS
39843158048Bed 110£1,394BE-MA-PS
39843140562Bed 210-£1,896BE-DB-PS
39843140562Bed 210£1,825BE-DB-PS
39843140562Bed 210£1,896BE-DB-PS
39843130111Pillow0-1-£26BE-BA-PI
39843130111Pillow01£26BE-BA-PI
       

 

Your solution would still show 1, where it needs to show 0. A simple SUM doesn't work, as if there are multiple add-ons sold (and not cancelled), the total would be incorrect as it needs to show either 1 (where add-ons (any number) are sold) or 0 (where none are sold).

 

Thanks in advance for any assistance on this.

 

You can try

Number of qualifying orders with addon = 
VAR SummaryTable = ADDCOLUMNS(
	SUMMARIZE( 'Table', 'Table'[Order No.], 'Table'[Item]),
	"@total", CALCULATE( SUM( 'Table'[Add-on sold]))
)
VAR Result = CALCULATE(
	DISTINCTCOUNT( 'Table'[Order No.]),
	FILTER( SummaryTable, [@total] > 1)
)
RETURN COALESCE( Result, 0 )

@johnt75  Thank you - I had to make one change, as this line:

 

FILTER (SummaryTable, [@total] > 1)

 

needed to have > 0 at the end, rather than 1.

 

Much kudos for your help!

johnt75
Super User
Super User

You can use the below measures

Number of orders = DISTINCTCOUNT( 'Table'[Order no])

Number of qualifying orders =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Order no] ),
    'Table'[Qualifying product] = 1
)

Number of qualifying orders with addon =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Order no] ),
    'Table'[Add-on sold] = 1
)

@johnt75Thank you - they work a treat.

 

Could I ask a follow-up question - currently I am using 'Add a conditional column' to create the [Qualifying Product] and [Add-on Sold] data. Is there a better way, avoiding this type of manipulation stage, to achieve the same output?

 

That would depend on a few things. It would be possible in principle to use whatever logic determines your conditional column in the filter arguments to calculate but that would mean the processing time required would be used during report consumption, when the user can see it, rather than during data load.

Given that the columns will only be storing a very small number of distinct values the size of the columns should be really small, even for a large dataset, and it will likely give you better performance than doing the same calculation in DAX.

Another option might be to push the calculation up to the SQL stage so that the columns are returned from the base query and no further calculation would be required.

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.