March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
How do I use the GroupBy and Having clause in my dataset? I have the following table:
[ORDER]
CUSTOMER ID NORDER NET AMOUNT
C1 1 100
C1 2 -100
C2 3 400
C4 4 0
C4 5 100
C5 6 100
I want to exclude the CUSTOMER ID C1 because he has the SUM of the NET AMOUNT=0 in another measure that counts thecustomers that have order. The SQL Statement could be this:
Select CUSTOMERS ID, SUM(NET AMOUNT)
FROM ORDER
GROUP BY CUSTOMERS ID
HAVING SUM(NET AMOUNT)<>0;
The measure that I want to filter is:
Hi, I have requirement with having clause and also distinct count and sum function in two different tables.
Can anyone help me how to write the measure for it.
Below is the logic we need to implement as measure.
Count distinct userevents.outletcode having sum(userevents.sessioncount)>0/ count of distinct outlet.outletcode where b2b flag=""x"" and outlet.outletstatuscodd=""2"" and outlet.b2bstartdate<=<date selected>
Kindly help how to implement this logic in dax
Hi @Anonymous
Here are a couple of ways you could write this measure.
The key part of the measure is FILTER( VALUES ( 'ORDER'[CUSTOMER ID] ),...), which is similar to the HAVING clause in your SQL example.
Customers with Nonzero Amount = CALCULATE ( DISTINCTCOUNT ( 'ORDER'[CUSTOMER ID] ); FILTER ( VALUES ( 'ORDER'[CUSTOMER ID] ); CALCULATE ( SUM ( 'ORDER'[NET AMOUNT] ) ) <> 0 ) )
Customers with Nonzero Amount = COUNTROWS ( FILTER ( VALUES ( 'ORDER'[CUSTOMER ID] ); CALCULATE ( SUM ( 'ORDER'[NET AMOUNT] ) ) <> 0 ) )
Regards,
Owen
Hi Owen,
thank you a lot for the answer . I've tried but it still does not work. This is the new measure:
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
91 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
73 | |
68 |