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
erpbi
New Member

How to use distinct count from a slicer filtered table in a calculation applied to each row

Hello,

 

I have a table that contains various products, all identified by a unique Product ID.  This table can be filtered using slicers, by either Product ID, or Product Description.  However, some items may have the same description, although the Product ID remains unique.  I have costs for each product showing in each row of the table, and I need to add a formula to show a discounted price if more than 1 unique Product ID is contained within the table (based on the filtered slicer selection).

 

For example, if someone uses the slicers to filter down the table to 1 product, they will see the product attributes in separate columns, followed by a column for the full price of that item.  If they select multiple products via the slicers, then a set % discount needs to be applied to each row, and shown in its own column along with a grand total.

 

I've been able to use a measure to add a column showing the discount % to apply as follows:

DiscountPct = CALCULATE(DISTINCTCOUNT('ProductPricing'[ProductId]),ALLSELECTED('ProductPricing'))
 
Now ideally, I'd be able to create a new column to multiply this DiscountPct measure by each row, but when I do that, the calculated column doesn't update with each selection within the slicers.
 
Any suggestions on the best way to accomplish this?  Here are 2 examples of tables to show what the expected behavior should be, the Discounted Price column is the one I'm unable to get working:
 
1 unique product ID value selected by the slicers:
Product IDProduct DescriptionOriginal PriceMultiple Part DiscountDiscounted Price
P100Part 100$100.000%$100.00
Total: $100.000%$100.00

 

More than 1 unique Product ID selected:

Product IDProduct DescriptionOriginal PriceMultiple Part DiscountDiscounted Price
P100Spare Part$100.0010%$90.00
P101Another Spare Part$125.0010%$112.50
P102Some Other Spare Part$50.0010%$45.00
P103Spare Part$75.0010%$67.50
Total: $350.0010%$315.00

 

1 ACCEPTED SOLUTION

Thanks for the feedback, I hadn't thought to aggregate the price for some reason.  However, I did try that, and it made all the line-level calculations correct, but was still using the lowest price when calculating the total row, which doesn't work for this usage.  What I ended up doing is using a SUM instead of the MIN you included below, and that took care of both the line-level details as well as the grand totals.

 

Thanks for the help!

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Does this measure work?

=MIN('ProductPricing'[Original Price])*(1-[DiscountPct])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for the feedback, I hadn't thought to aggregate the price for some reason.  However, I did try that, and it made all the line-level calculations correct, but was still using the lowest price when calculating the total row, which doesn't work for this usage.  What I ended up doing is using a SUM instead of the MIN you included below, and that took care of both the line-level details as well as the grand totals.

 

Thanks for the help!

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.