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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

subquery in power bi dax

How do i write sub query in dax?

 

Query : 
select YEAR([CloseDate]),MONTH([CloseDate]), sum(days_to_close)/count(distinct id) as 'Number of Days to Close' from
(select [CloseDate], id, days_to_close from [dbo].[test]
where sname='Closed' group by [CloseDate], id, days_to_close) a
group by YEAR([CloseDate]),MONTH([CloseDate])
order by 1,2

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

Hi @Anonymous ,

Sample data:

vluwangmsft_3-1648695807892.png

 

You need to add year ,month on base table:

vluwangmsft_0-1648695702226.png

Then use the below dax to create a new table:

TEST2 = SUMMARIZE(FILTER(test,test[sname]="Closed"),test[YEAR],test[MONTH],"Number of Days to Close",DIVIDE(SUM(test[days_to_close]),DISTINCTCOUNT(test[id])))

Output result:

vluwangmsft_1-1648695756812.png

And in sql:

vluwangmsft_2-1648695775222.png

 

 

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

View solution in original post

1 REPLY 1
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

Sample data:

vluwangmsft_3-1648695807892.png

 

You need to add year ,month on base table:

vluwangmsft_0-1648695702226.png

Then use the below dax to create a new table:

TEST2 = SUMMARIZE(FILTER(test,test[sname]="Closed"),test[YEAR],test[MONTH],"Number of Days to Close",DIVIDE(SUM(test[days_to_close]),DISTINCTCOUNT(test[id])))

Output result:

vluwangmsft_1-1648695756812.png

And in sql:

vluwangmsft_2-1648695775222.png

 

 

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors