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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Syndicate_Admin
Administrator
Administrator

Count Excesses and Defects with pooled data

Dear, I am writing to you asking for help with the problem I am having.

To make it better understood, I made a small query with fictitious data that I think can serve (the query is called Example)

GroupProductDayDetour
Group 2Product 112
Group 2Product 211
Group 2Product 313
Group 2Product 12-1
Group 2Product 22-1
Group 2Product 32-2
Group 2Product 132
Group 2Product 231
Group 2Product 33-1
Group 1Product 413
Group 1Product 512
Group 1Product 42-1
Group 1Product 52-1

My intention is to create two matrix tables, in the first I would have the Group and Product in the rows, the days in the columns and the sum of the deviations as values while in the second I would have the Group and Product in the rows and as values two calculated Measures, one to count the number of days 'in Excess' (when the sum of the variations of each day is positive) and another that counts the days 'in Default' (when the sum of the variations is negative). I made the second table with a matrix because my intention is to put it next to the first and that they can be visualized as if it were one.
The measurements in the second table are:

# Excesses = CALCULATE(DISTINCTCOUNT(Example[Day]),Example[Detour]>0)
# Defects = CALCULATE(DISTINCTCOUNT(Example[Day]),Example[Detour]<0)

I leave an image with what I get.
Vista del resultado obtenidoVista del resultado obtenidoView of the result obtained

As you can see, for group 1 it tells me that I have an excess and a defect and that corresponds to the data on the left, however for group 2 it tells me that I have 2 excesses and 2 defects and that is incorrect, since I only have 3 days. In fact looking at the table on the left you can see that it should have 2 excesses, but only 1 defect. I understand that the problem comes from the way to count the excess and defect but I do not know how to fix it (I count the days when the product is in excess or defect and if we see the table, for group 2 I have a defect on day 3, although the total is excess),

I leave an image of the same table but with the detail by group

Chequeo PBI 2.jpg

I have a fairly simple example file, but the page is giving me enough error to upload it in case it helps solve the problem.

From now on thank you very much for everything.

Best regards

Gustavo

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Write these measures

Detour value = SUM(Data[Detour])
Excesses = COUNTROWS(FILTER(VALUES(Data[Day]),[Detour value]>0))
Defects = COUNTROWS(FILTER(VALUES(Data[Day]),[Detour value]<0))

Hope this helps.

Untitled.png


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

You are welcome.


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

Hi,

Write these measures

Detour value = SUM(Data[Detour])
Excesses = COUNTROWS(FILTER(VALUES(Data[Day]),[Detour value]>0))
Defects = COUNTROWS(FILTER(VALUES(Data[Day]),[Detour value]<0))

Hope this helps.

Untitled.png


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

Thank you very much for your solution! You saved me

Please mark my reply as Answer - the reply which carries the solution.


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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors