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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

SQL to DAX group by

Hi, could you please help me to rewrite this code in dax?

 

select
sum(dates) from
(select
filter,
count(date) as dates
from db
group by filter) tmp

 

Please!!!! Thanks a lot in advance!

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please Try

count = CALCULATE(COUNT('Table'[date]),ALLEXCEPT('Table','Table'[filter]))

 1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

10 REPLIES 10
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please Try

count = CALCULATE(COUNT('Table'[date]),ALLEXCEPT('Table','Table'[filter]))

 1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

Thank you! I made this work...I think so...But it should be measure, not column.

Thanks a lot!!!I'm still testing, but I hope, that it is working.

Anonymous
Not applicable

@v-jayw-msftUnfortuntelly, it's not working, I need to have 9 in each raw.

a9
b9
c9

Hi @Anonymous ,

 

Please modify the formula as below.

count = CALCULATE(COUNT('Table'[date]),ALLSELECTED('Table'[filter]))

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

@v-jayw-msftno:( no it's just showing 1 in all columns...

a1
b1
c1

Hi @Anonymous ,

 

Ok...how about this.

count = CALCULATE(COUNT('Table'[date]),ALL('Table'))

2.PNG 

If it still wrong, better to share some sample data to us.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Hi @Anonymous ,

 

it should look something like this.

Measure =
SUMX ( 
		GROUPBY ( db, db[filter], "dates", COUNT ( db[date] ) )
	, [dates] )

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support. 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

@mwegener  Unfortunatelly, I'm getting this error 

 

Function 'GROUPBY' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup().

Anonymous
Not applicable

@mwegener  I'm trying to achive this

 filtercolumn 1column 2%
 filter 1115=column1/column2'
 filter 2215=column1/column2'
 filter 3315=column1/column2'
 filter 4415=column1/column2'
 filter 5515=column1/column2'
total 15  

Thanks a lot in advance!

Anonymous
Not applicable

I'm getting this error...

Function 'GROUPBY' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup().

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.