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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Count in SQL to DAX

I am able to get a count in SQL. Trying to do the same with DAX measure is not resulting in the correct output. How would you translate the following: 

SELECT store_num, COUNT(emp_id)-1 AS alert_count
FROM store_loc
GROUP BY store_num
HAVING COUNT(emp_id) > 1;

Any advice on translating the above into a measure will be greatly appreciated. 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

If you want to use measure and matrix, you can create this measure:

alert_count =
COUNT ( store_loc[emp_id] ) - 1

Put it in Matrix, and create another measure like this, set its value as 1 and put it in the visual filter:

visual control =
IF ( [alert_count] > 1, 1, 0 )

matrix.png

If you do not want to use this filter measure, you can filter it directly by [alert_count]:
filter.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Based on your description, I have created this simple sample in sql server and run the sql statement to get the initial expected output:

sample tablesample tablesql resultsql result

To get the same result in power bi, you can create this calculated table by DAX:

Table =
FILTER (
    SUMMARIZE (
        'store_loc',
        store_loc[store_num],
        "alert_count", COUNT ( store_loc[emp_id] ) - 1
    ),
    [alert_count] > 1
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-yingjl Thank you for your support. This is what I am looking for but is this possible to execute just as a measure and not as a calculated table? My ultimate goal is to create a matrix table that will be dynamic. Please let me know if I am to vague and I can try to elaborate with more detail. 

Hi @Anonymous ,

If you want to use measure and matrix, you can create this measure:

alert_count =
COUNT ( store_loc[emp_id] ) - 1

Put it in Matrix, and create another measure like this, set its value as 1 and put it in the visual filter:

visual control =
IF ( [alert_count] > 1, 1, 0 )

matrix.png

If you do not want to use this filter measure, you can filter it directly by [alert_count]:
filter.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

Share some data, describe the question and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , you might want to try creating a calculated table this way,

 

Summary = 
SUMMARIZECOLUMNS (
    store_loc[store_num],
    FILTER (
        DISTINCT ( store_loc[store_num] ),
        CALCULATE ( COUNTROWS ( store_loc ) ) > 1
    ),
    "alert_count", COUNTROWS ( store_loc ) - 1
)

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

parry2k
Super User
Super User

@Anonymous add following measure and then use it in visual left filter

 

Count = COUNTROWS ( Table ) - 1

 

add a table visual, put store number and this new measure and in visual left filter choose where count > 1

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.