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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

DAX Function to Countif

Hi,

 

I've looked through a few suggestions for the above and tried to use them, but they didn't work. What am I doing wrong?

 

I got an SQL Query to pull in Orders from our ERP system.

 

Each order can have multiple order lines, therefore the majority of them appear multiple times with only a couple columns (supplied item, qty, price etc) being different.

 

A number of item numbers are flagged as 'Stock' items. I need to find out if the order has any parts that are classified as stock.

 

In Excel, I would use this: =COUNTIF(C2:C10,A2&"_Stock")>0

Column A = Order Number

Column B = Stock or Non-Stock

C = CONCAT(A2,"_",B2)

 

When I replicate this in DAX, it totals up ALL orders that end with "_Stock". I can't get it to work. See pic

(Last column on the pic is just Concat(OrderNumber,"_Stock"))

 

Image 4.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Nvm. Solved it with a simple vlookup

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Nvm. Solved it with a simple vlookup

jsh121988
Microsoft Employee
Microsoft Employee

I'm a bit confused as to what you're trying to do. I think you want to know the order numbers that have stock items, and maybe the count.

I think you need to get away from the data view and use a Table/Matrix visual on a report page. You're basically overloading your table by trying to calculate parent values on child rows.

 

Create a CalcColumn:

HasStockItem = IF([ITM_Stock Profile (groups)] = "Stock", 1, 0)
// Returns 1 if the row is Stock, or 0 if not.

 

Then add a Table visual to a report page with Order Number and SUM of HasStockItem. On the visual filters, set SUM of HasStockItem to greater than 0 if you don't want to see orders that are not Stock. Or add a slicer to the page with HasStockItem, and select 1.

 

In excel terms, create a calulated column, then use a pivot table, then filter.

 

Hope this helps!

 

Anonymous
Not applicable

Hi,

 

Unfortunately this is only a small part of filter I will apply to the orders. I have a few more criteria to filter orders off by and I need this as a Calc column (not measure).

 

Some orders have 200+ parts on them and I need to include them as long as 1 part is a Stock item.

What I provided above is a calculated column, but it only operates on each row with now awareness of the table.

 

You could try creating a calculated table with Disctinct OrderId that creates aggreated columns. I think for that you can make use of SUMMARIZE().

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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