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! Learn more

Reply
Anonymous
Not applicable

DAX help needed

Hi Power Users,

 

I'm still learning powerbi. I need help in getting below sql query write in power bi using dax. 

 

select sum(Monthcount), sum(Monthcount)/12 from (select indexid, count(distinct MonthID) as MonthCount, Count(Distinct indexId) as Indexid_count, count(distinct MonthID)/6 as ABC from Table-1
Innerjoin Table-2 on Table-1. MonthID= Table-2.MonthID

Where monthyear between '202001' and '202010'
group by indexid

 

I need this query to write using DAX. 

 

Thanks

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Would you please try something like:

 

sum(Monthcount)/12 =
VAR a =
    SUMMARIZE (
        FILTER (
            NATURALINNERJOIN ( Table - 2, Table - 1 ),
            'Table-2'[monthyear] >= 202001
                && 'Table-2'[monthyear] <= 202010
        ),
        'Table-2'[indexid],
        "MonthCount", DISTINCTCOUNT ( 'Table-2'[MonthID] ),
        "ABC", DISTINCTCOUNT ( 'Table-2'[MonthID] ) / 6
    )
RETURN
    SUMX ( a, [MonthCount] ) / 12

sum(Monthcount) =  VAR a =
    SUMMARIZE (
        FILTER (
            NATURALINNERJOIN ( Table - 2, Table - 1 ),
            'Table-2'[monthyear] >= 202001
                && 'Table-2'[monthyear] <= 202010
        ),
        'Table-2'[indexid],
        "MonthCount", DISTINCTCOUNT ( 'Table-2'[MonthID] ),
        "ABC", DISTINCTCOUNT ( 'Table-2'[MonthID] ) / 6
    )
RETURN
    SUMX ( a, [MonthCount] ) 

 

If you need accurate dax formula, please show us some sample data by onedrive for business.

 

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

 

Best Regards,

Dedmon Dai

amitchandak
Super User
Super User

@Anonymous , You can have measures like this

 

sumx(values('Table-1'[indexid]), distinctcount('Table-1'[indexid]))
sumx(values('Table-1'[indexid]), distinctcount('Table-1'[MonthID]))
sumx(values('Table-1'[indexid]), distinctcount('Table-1'[MonthID]))/12

 

Both Tables should join on MonthID in power BI and where you can take filter in the slicer

 

You can refer my Dax vs SQL series, if that can help https://www.youtube.com/watch?v=WlvQ_SGy4iA&list=PLPaNVDMhUXGZNyKU0PgG2g3P0c6CPjMnj

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors