Forum Discussion
pnem
3 years agoFrequent Visitor
Count items in hierarchy
Hey, I have issue in counting ItemVariant for each Item for Brand in selected Store So the hierarchie looks like Store/Brand/Item/ItemVariant from top to the bottom I need to count first how ma...
- Anonymous3 years ago
Hi pnem ,
Here are the steps you can follow:
1. Create measure.
failedVariant = var _select=SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])&&'Table'[name]=MAX('Table'[name])&&'Table'[brand]=MAX('Table'[brand])),"itemgroup",[StockQty]) return IF( [StockQty] = 0 && HASONEVALUE('Table'[item]) ,1, IF( [StockQty] <> 0&& HASONEVALUE('Table'[item]) ,0, IF( 0 in _select && HASONEVALUE('Table'[brand]),COUNTX(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])&&'Table'[name]=MAX('Table'[name])&&'Table'[brand]=MAX('Table'[brand])&&[StockQty]=0),[item]), IF( HASONEVALUE('Table'[name]), COUNTX(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])&&'Table'[name]=MAX('Table'[name])),[item]), IF( HASONEVALUE('Table'[loc1]),COUNTX(FILTER(ALL('Table'),'Table'[loc1]=MAX('Table'[loc1])),[item]),0))))) divide = DIVIDE( [failedVariant],[StockQty])2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Anonymous
3 years agoNot applicable
Hi pnem ,
I created some data:
Here are the steps you can follow:
1. Create measure.
Measure 2 =
IF(
ISINSCOPE('Flag'[ItemVariant])&&MAX('Flag'[Value])=0,
FORMAT(
DIVIDE(
COUNTX(
FILTER(ALL(Flag), 'Flag'[Store]=MAX('Flag'[Store])&&'Flag'[Brand]=MAX('Flag'[Brand])&&'Flag'[Item]=MAX('Flag'[Item])&&'Flag'[Value]=0),[ItemVariant]),
COUNTX(
FILTER(ALL(Flag), 'Flag'[Store]=MAX('Flag'[Store])&&'Flag'[Brand]=MAX('Flag'[Brand])&&'Flag'[Item]=MAX('Flag'[Item])),[ItemVariant])),"Percent"),
IF(
ISINSCOPE('Flag'[ItemVariant]),MAX('Flag'[Value]),
IF(
ISINSCOPE('Flag'[Item]),
COUNTX(
FILTER(ALL(Flag), 'Flag'[Store]=MAX('Flag'[Store])&&'Flag'[Brand]=MAX('Flag'[Brand])&&'Flag'[Item]=MAX('Flag'[Item])),[ItemVariant]),
IF(
ISINSCOPE('Flag'[Brand]),
COUNTX(
FILTER(ALL(Flag),
'Flag'[Store]=MAX('Flag'[Store])&&'Flag'[Brand]=MAX('Flag'[Brand])),[ItemVariant]),
IF(
ISINSCOPE('Flag'[Store]),
COUNTX(
FILTER(ALL(Flag),
'Flag'[Store]=MAX('Flag'[Store])),[ItemVariant]),
COUNTX(ALL(Flag),[Value]))))))
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
pnem
3 years agoFrequent Visitor
Hey Anonymous ,
This was very helpful from you but the end result should be slightley modified.
Percentage should be on Item line, not on item variant line.
If you expand hierarchy it could be both ways - item variant rows could be empty or to replacate value from item line
Please advice, thank you!