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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
GermanTersoglio
New Member

SO COUNT DAX MEASURE

Hello everyone!
I am having the following situation:
I have a FACT table called "SalesLines" which is connected to DIM "Invoiceheader"

SalesLines has multiple lines per Sales Order
InvoiceHeader as a DIM has just one Sales Order per line.

I need a dax measure to know the count of Sales Orders. 
If i do it over the FACT, I get a huge number because when a Sales Order has 4 lines is counting as 4. If I do it over the DIM table, the visual has low performance and takes 2 min to display.

The closest that i have been is here:

- VAR Factkey = MAX(InvoiceLines[InvoiceKey])
 
return

 COUNTXFILTER(SalesLines, RELATED('Invoice Header'[InvoiceKey]) = Factkey),RELATED('Invoice Header'[SalesId]))
 
But I get the grand total as 1 and not the sum. 

Also i have tried simpler things like:
-  COUNTX(SalesLines, RELATED('Invoice Header'[SalesId]))
 
But this returns the count of each line obiously 

Any help is appreciated 
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @GermanTersoglio 
If the column exists in the fact table the

= DISTINCTCOUNT ( 'SalesLines'[SalesId] )

If not then

=
COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
            SalesLines,
            "@SalesID", RELATED ( 'Invoice Header'[SalesId] )
        )
    )
)

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @GermanTersoglio 
If the column exists in the fact table the

= DISTINCTCOUNT ( 'SalesLines'[SalesId] )

If not then

=
COUNTROWS (
    DISTINCT (
        SELECTCOLUMNS (
            SalesLines,
            "@SalesID", RELATED ( 'Invoice Header'[SalesId] )
        )
    )
)

Hi Tamerj,
I was facing my measure in the wrong way. 
You solution works perfectly. I really appreciate your help.

Thanks for sharing your knowledge 🙂

FreemanZ
Super User
Super User

hi @GermanTersoglio 

Seems you are plotting with InvoiceLines[InvoiceKey] and the two tables are joined on this column, try like
measure =
COUNTROWS(RELATEDTABLE(SalesLines))
 
Or tell us more about your case.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.