Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello all,
I need help with DAX code that would produce results in a matrix table under the following conditions. So far not much luck..
Conditions
For example, i have the following data with items under "Inventory", "Shipped", and "Invoiced" column.
The actual table consists of thousands of rows, and the items in "Inventory", "Shipped" are not unique. They can consist of same/similar items.
The requirement
1) Filter "Invoiced" column as "No". (this will determine the "Inventory" items)
2) Based on the Inventory items in 1), I need all of the "Shipped" items for each Inventory item, if the "Invoiced" condition is set to "Yes".
*In the actual data, per each "Inventory" item, it will usually consist of 1 or more "Shipped" items.
Inventory | Shipped | Invoiced |
A | Z | Yes |
B | Y | No |
C | X | Yes |
A | W | No |
B | V | Yes |
C | U | Yes |
A | T | No |
B | S | Yes |
C | R | No |
A | Q | Yes |
・ | ・ | ・ |
・ | ・ | ・ |
Thank you in advance!
Solved! Go to Solution.
HI @tkwh1,
It seems like I missed the first condition to filter items which 'Invoiced' field equal to 'No' , you can try to the following measure formula if it suitable for your requirement:
Distinct Shipped Count Per Inventory =
VAR InventoryList =
CALCULATETABLE (
VALUES ( Table1[Inventory] ),
FILTER ( ALLSELECTED ( Table1 ), [Invoiced] = "No" )
)
RETURN
CALCULATE (
COUNTROWS ( VALUES ( Table1[Shipped] ) ),
FILTER (
ALLSELECTED ( Table1 ),
[Invoiced] = "Yes"
&& [Inventory] IN InventoryList
),
VALUES ( Table1[Inventory] )
)
Regards,
Xiaoxin Sheng
HI @tkwh1,
You can try to use following measure formula to get Invoiced and shipped count based on inventory group:
Distinct Shipped Count Per Inventory =
CALCULATE (
COUNTROWS ( VALUE ( Table1[Shipped] ) ),
FILTER ( ALLSELECTED ( Table1 ), [Invoiced] = "Yes" ),
VALUES ( Table1[Inventory] )
)
Regards,
Xiaoxin Sheng
hi Xiaoxin,
Thank you for your response, really appreciate the suggested code you provided.
I tried it and thought it had worked initially, but after checking the result, it seems that the "Inventory" items displayed included other Inventory items as well.
Using your code I tried different variations but still cannot get the exact result I need.,,
HI @tkwh1,
It seems like I missed the first condition to filter items which 'Invoiced' field equal to 'No' , you can try to the following measure formula if it suitable for your requirement:
Distinct Shipped Count Per Inventory =
VAR InventoryList =
CALCULATETABLE (
VALUES ( Table1[Inventory] ),
FILTER ( ALLSELECTED ( Table1 ), [Invoiced] = "No" )
)
RETURN
CALCULATE (
COUNTROWS ( VALUES ( Table1[Shipped] ) ),
FILTER (
ALLSELECTED ( Table1 ),
[Invoiced] = "Yes"
&& [Inventory] IN InventoryList
),
VALUES ( Table1[Inventory] )
)
Regards,
Xiaoxin Sheng
hi Xiaoxin,
Thank you for your response and the additional code.
I have tried this and it shows up as blank, so I will see what else I can do on my end.
In the meantime I have accepted your response as the solution (please let me know if it is not the case).
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
9 | |
8 | |
8 | |
8 |
User | Count |
---|---|
13 | |
12 | |
11 | |
10 | |
9 |