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

Dynamic Slicer - Count Distinct Value if one Criteria is met within a group

I'm having an issue where I'm trying to calculate if something is covered or not based on if a value is met within a category. I would like to have a slicer for the column "Provider" where I can select numerous combinations of the provider, and if atleast one of them is "Covered" then I'd like the product to be considered covered. Currently, my bar chart (with "Covered?" as the legend) is double counting values (distinct count of product ID) when i select various combinations. 

 

The dataset I'm working with looks like this:

UnitProductProviderCovered?
Computers     AAppleCovered
Computers     AGoogleNot Covered
Computers     AMicrosoftCovered
Computers     ATeslaCovered
Computers     BAppleNot Covered
Computers     BGoogleCovered
Computers     BMicrosoftNot Covered
Computers     BTeslaNot Covered
Computers     CAppleCovered
Computers     CGoogleCovered
Computers     CMicrosoftCovered
Computers     CTeslaCovered
Computers     DAppleCovered
Computers     DGoogleCovered
Computers     DMicrosoftNot Covered
Computers     DTeslaCovered

 

For example, if I select Microsoft and Tesla in the slicer, then I would want :

Product A to return "Covered",

Product B to return "Not Covered",

Product C to retun "Covered",

Product D to return "Covered"

 

The picture below shows how its double counting Product D. I would like this to just have a 1 for "Covered", and for the breakdown by unit be a split of 3 covered, 1 not covered

Specialist707_2-1677527858135.png

 

Any ideas how I can accomplish this? Thank you!

 

 

 

 

1 ACCEPTED SOLUTION

@Specialist707 

 

I added a second Unit "Phones" to my test data, & slightly changed the "Coverage" column data for it so that it differs a bit from the data you provided for unit "Computers".  This was done to test the final breakdown for the Covered / Not Covered Line Chart.

 

Step 1 - Create a calculated column.

WinterMist_0-1677601660701.png

 

Step 2 - Create a measure to count the number of Unit + Product combinations which are covered.

 

WinterMist_1-1677601786380.png

 

 

 

 

Step 3 - Create a measure to count the number of Unit + Product combinations which are NOT covered.

 

 

WinterMist_2-1677601820676.png

 

Finally, add the 2 measures to the line chart.

 

WinterMist_3-1677601879236.png

 

Data is as follows (your original "Computers" data + my additional "Phones" data):

 

WinterMist_4-1677601960444.png

 

Hopefully this is helpful to you.

Nathan

 

View solution in original post

7 REPLIES 7
WinterMist
Impactful Individual
Impactful Individual

Hello @Specialist707 

 

Let me know if this works.

 

Regards,

Nathan

 

WinterMist_0-1677531884236.png

 

 

Thanks - I dont think that solution would work because I ultimately need to roll this up at a "Unit" level by a distinct count of products and need to have the "Covered" / "Not Covered" legend to show the segmentation in a bar chart.

@Specialist707 

 

I added a second Unit "Phones" to my test data, & slightly changed the "Coverage" column data for it so that it differs a bit from the data you provided for unit "Computers".  This was done to test the final breakdown for the Covered / Not Covered Line Chart.

 

Step 1 - Create a calculated column.

WinterMist_0-1677601660701.png

 

Step 2 - Create a measure to count the number of Unit + Product combinations which are covered.

 

WinterMist_1-1677601786380.png

 

 

 

 

Step 3 - Create a measure to count the number of Unit + Product combinations which are NOT covered.

 

 

WinterMist_2-1677601820676.png

 

Finally, add the 2 measures to the line chart.

 

WinterMist_3-1677601879236.png

 

Data is as follows (your original "Computers" data + my additional "Phones" data):

 

WinterMist_4-1677601960444.png

 

Hopefully this is helpful to you.

Nathan

 

Thank you! That worked for the purpose of what I was trying to do. The only additional thing is the filter ability gets removed from the stacked bar chart. Is there a solution to be able to click on the "Covered" or "Not Covered" segmentation in the stacked bar chart to be able to filter for those products/units that are, or are not covered?

 

As always, appreciate the assistance!

@Specialist707 

 

If this was helpful to you, would you mind marking it as a solution?

 

Regards,

Nathan

The bar chart visual is predefined so that when you click on a bar for "Covered" or "Not Covered", you're not actually selecting the bar, but rather the entire category "Computers".

WinterMist_0-1677619201898.png

 

If you want to isolate only what is covered or not covered, I would recommend simply adding a slicer for the "Coverage" column.

Thanks - thats what I figured. One other note I would add is originally my dataset looked like the below table, but I ended up transposing it because I thought that would be the easiest in terms of filter layout. Note the 1 represents if it is covered by that provider, and the 0 is not covered. The original concept I designed was fairly static, so thats why the overall coverage column is there. As mentioned previously, I'm looking for that column to be dynamic based on the selections (e.g For product B, if Apple and Microsoft are selected, then "not covered", but if Apple and Google are selected, then "covered"

 

UnitProductAppleGoogleMicrosoftTeslaOverall Coverage
ComputersA1011Covered
ComputersB0100Covered
ComputersC1111Covered
ComputersD1101Covered
PhonesE1000Covered
PhonesF1111Covered
PhonesG0101Covered
PhonesH0101Covered
PhonesI0000Not Covered

 

If I used that layout instead, would a similar solution be available that would allow me to select the providers via slicer and based on the selections, it would return covered or not covered in the same segmented bar chart fashion, but allow for the filtering to be done at the covered/not covered level in the bar chart? I'm not sure on the exact DAX logic, but I would imagine it would be something like "If Apple and Tesla are selected, and the sum of both columns is >1, then 1, else 0". I'm just not sure how to account for the filtering aspect of the bar chart that I'm looking for. Perhaps a disconnected Covered/Not Covered table that acts as a legend (although If its disconnected, im not sure the filtering by segment in the bar chart would work)?

 

Really appreciate any help/guidence! 

 

 

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