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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Veigar
Frequent Visitor

Filtered table to ALL function

Hi everyone,
I'm trying to perform an ABC Analysis.

I have three tables:
ITEMS[ID, Description],
STOCKS[Item, Stock_qty],
SALES[Item, Value].

SALES[Item]and STOCKS[Item] are both linked to ITEMS[ID].

I built a measure to calculate the average:

Average stock = AVERAGE(STOCKS[Stock_qty])


The following code calculates the class A, B, C or D for every item in ITEMS table:

ABC Warehouse = 

VAR T1 = SUMMARIZE(ALL(ITEMS), ITMES[ID], "QTY", [Average Stock])
VAR T2 = ADDCOLUMNS(T1, "QTY_CUMULATED", SUMX(FILTER(T1, [QTY] >= EARLIER([QTY])), [QTY]))
VAR QTY_TOT = SUMX(ALL(ITEMS), [Average Stock])
VAR T3 = ADDCOLUMNS(T2, "PRC", DIVIDE([QTY_CUMULATED], QTY_TOT, 0))
VAR T4 = ADDCOLUMNS(T3, "ABC", SWITCH(TRUE(), [PRC] <= 0.8, "A", [PRC] <= 0.95, "B", [QTY] <> 0, "C",  "D"))
VAR T5 = FILTER(T4, ITEMS[ID] = MAX(ITEMS[ID]))
RETURN MAXX(T5, [ABC])

 
There are althought items that i wanna remove, before doing this calculation. There are items that have a SALES[Value] equal to zero. So, i want to remove them with a filter. I tried many ways but i don't know how to get the right result.

In other words i want the table in ALL function in var T1 and in var QTY_TOT to NOT have items that have SALES[Value] equal to zero.

Thanks

2 REPLIES 2
Fowmy
Super User
Super User

@Veigar 

Can you replace the 3rd line with the following:

 

 

var QTY_TOT = SUMX(FILTER(ALL(ITEMS), calculate(sum(SALES[Value])) <> 0), [Average Stock])

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Veigar
Frequent Visitor

Hi @Fowmy ,
Thanks for your answer.
The measure is wrong, because now it shows that there are 80% of items in class A, while before there where around 20%. I managed to do it in another way, but i'm still interested in this solution, i'll try to modify it. 
But i saw that this solution is very slow, i have to manage around 7000 items.

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors