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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

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 Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

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.