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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Spartanos
Helper II
Helper II

Multiple countifs DAX

Hi, 

 

I want to make a multiple countifs statement in DAX.

 

The dataframe looks like this:

 

Routing-port TEX  invoice (text format)   countifs result

XXXX-1            2      TEXT123                    1

XXXX-1            1      TEXT123

XXXX-1            2      TEXT124                    1

 

The count should be that each routing port, TEX should be 2 and invoice should be unqiue. Hence, the countifs formula in Excel looks like this:=COUNTIFS(T:T;[@[Routing port/port]];CY:CY;[@[Invoice Numbers]]). I manually filtered TEX= 2.

 

I made this formula, but that doesn´t work.

 

Weight_factor =
CALCULATE(
COUNT([Routing port/port]),
FILTER(
'source data',
'source data'[Invoice Numbers],
'source data'[TEX]=2,
)
)

 

 

1 ACCEPTED SOLUTION

Hi, @Spartanos 

 

Is your Routing-port the same value, or a different one? SELECTEDVALUE is placed in Measure. Whether your Routing-port is the same value or a different value, there is a solution.

Routing-port is the same value:

Column:

Count 1 =
IF (
    [TEX] = 2,
    CALCULATE (
        COUNT ( 'Table'[Routing-port] ),
        FILTER ( 'Table', [TEX] = 2 && [invoice] = EARLIER ( 'Table'[invoice] ) )
    ),
    BLANK ()
)

vzhangti_0-1649753288226.png

Measure:

Measure =
IF (
    SELECTEDVALUE ( 'Table'[TEX] ) = 2,
    CALCULATE (
        COUNT ( 'Table'[Routing-port] ),
        FILTER ( 'Table', [TEX] = 2 && [invoice] = SELECTEDVALUE ( 'Table'[invoice] ) )
    ),
    BLANK ()
)

vzhangti_1-1649753386183.png

 

Routing-port is a different value.

Column:

Count 2 =
CALCULATE (
    COUNT ( 'Table 2'[Routing-port] ),
    FILTER (
        'Table 2',
        [TEX] = 2
            && [invoice] = EARLIER ( 'Table 2'[invoice] )
            && [Routing-port] = EARLIER ( 'Table 2'[Routing-port] )
    )
)

vzhangti_2-1649753482796.png

Measure:

Measure2 =
CALCULATE (
    COUNT ( 'Table 2'[Routing-port] ),
    FILTER (
        ALL ( 'Table 2' ),
        [TEX] = 2
            && [invoice] = SELECTEDVALUE ( 'Table 2'[invoice] )
            && [Routing-port] = SELECTEDVALUE ( 'Table 2'[Routing-port] )
    )
)

vzhangti_3-1649753586941.png

I hope you can get the results you want from it.

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

5 REPLIES 5
Whitewater100
Solution Sage
Solution Sage

Hi:

Can you try this? Table name = Data

Result =
CALCULATE(DISTINCTCOUNT(Data[invoice(text format)]),
Data[TEX] = 2)

Whitewater100_0-1649429625054.png

 

Hi,

Many thanks, this works. Is it also possible to make add the routing port as unique value in the formula as well?

Hi:

Yes:

Result =
var port = Data[Routing Port]
return
CALCULATE(DISTINCTCOUNT(Data[invoice(text format)]),
Data[TEX] = 2 &&
Data[Routing Port] = port)
 
Can you mark as solution if this works for you? Thanks

Hi,

Am I correct that I have to put  SELECTEDVALUE in this line of code:

var port = Selectedvalue(Data[Routing Port])

 
So the DAX engines knows that we are looking for muliple routing ports?

Hi, @Spartanos 

 

Is your Routing-port the same value, or a different one? SELECTEDVALUE is placed in Measure. Whether your Routing-port is the same value or a different value, there is a solution.

Routing-port is the same value:

Column:

Count 1 =
IF (
    [TEX] = 2,
    CALCULATE (
        COUNT ( 'Table'[Routing-port] ),
        FILTER ( 'Table', [TEX] = 2 && [invoice] = EARLIER ( 'Table'[invoice] ) )
    ),
    BLANK ()
)

vzhangti_0-1649753288226.png

Measure:

Measure =
IF (
    SELECTEDVALUE ( 'Table'[TEX] ) = 2,
    CALCULATE (
        COUNT ( 'Table'[Routing-port] ),
        FILTER ( 'Table', [TEX] = 2 && [invoice] = SELECTEDVALUE ( 'Table'[invoice] ) )
    ),
    BLANK ()
)

vzhangti_1-1649753386183.png

 

Routing-port is a different value.

Column:

Count 2 =
CALCULATE (
    COUNT ( 'Table 2'[Routing-port] ),
    FILTER (
        'Table 2',
        [TEX] = 2
            && [invoice] = EARLIER ( 'Table 2'[invoice] )
            && [Routing-port] = EARLIER ( 'Table 2'[Routing-port] )
    )
)

vzhangti_2-1649753482796.png

Measure:

Measure2 =
CALCULATE (
    COUNT ( 'Table 2'[Routing-port] ),
    FILTER (
        ALL ( 'Table 2' ),
        [TEX] = 2
            && [invoice] = SELECTEDVALUE ( 'Table 2'[invoice] )
            && [Routing-port] = SELECTEDVALUE ( 'Table 2'[Routing-port] )
    )
)

vzhangti_3-1649753586941.png

I hope you can get the results you want from it.

 

Best Regards,

Community Support Team _Charlotte

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.