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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
BorisTPL
Frequent Visitor

How to check if sales contain certain products?

Hi, I'm trying to create a calculated column or measure that does the following:
I have two tables, a sale table and a saleline table. The Sale table contains 1 line per sale and only has the salevalue, but no product info. The Saleline table contains a more detailed overview and has more lines per sale when more than 1 product is purchased.

For example,

Sale table looks something like:

BorisTPL_3-1626253715776.png

And for the same sale the Saleline table looks like this:

BorisTPL_1-1626253580011.png

 

We are a phone repairshop. Now I want to measure how many sales contain a screen replacement ánd a screenprotector. The code for a calculated column in the Sale table should check for the same SaleID in the Saleline table and check if this is the case with 3 possible outcomes: 

- No screen repair

- Screen repair without screenprotector

- Screen repair with screenprotector

 

I can calculate the amount of screenrepairs using measure:

Amount of screen repairs = CALCULATE(SaleLine[Aantal Workorder sales], FILTER('Item','Item'[Type] = "Scherm"))
I can calculate the amount of screen protectors using measure:
Amount of screenproctors = CALCULATE(sum(SaleLine[unitQuantity]),Category[Subcategory1] = "Clearplex", FILTER(SaleLine, SaleLine[calcSubtotal] <> 0 ))
 
Screenproctors are also sold without a screen repair so just dividing them is not the desired output.
Is there a way to combine the filters in a way for multiple lines? 

 

Hope you can push me in the right direction. Thanks in advance

 

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@BorisTPL  You can filter the sales table using the measures you've already created: 

 

Sales Count with Screen Repair & Protector =
CALCULATE( [Total Sales Count]
, FILTER(Sales,
[Sales Count with Screen Protector]>0 && [Sales Count with Screen Repair]>0
)
)
 

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

1 REPLY 1
AllisonKennedy
Super User
Super User

@BorisTPL  You can filter the sales table using the measures you've already created: 

 

Sales Count with Screen Repair & Protector =
CALCULATE( [Total Sales Count]
, FILTER(Sales,
[Sales Count with Screen Protector]>0 && [Sales Count with Screen Repair]>0
)
)
 

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors