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
Robot777
New Member

Potential double invoices code calculated column

Hello,

I've made a calculated column for checking if each rows invoice is potentially double invoice or a unique invoice. It should return duplicate if its double and unique if its a new invoice.

Only when I set this code in DAX in a calcuated column it gives me the error that you cant use countrows and filter in a calculated column?

Does anybody know why this code won't work and what the solution is?  

 

Thanks in advance.

 

 

Column = 
VAR varCurrentValue1 = 'EZK TRX_019_Overzicht_facturen_2023_DEV'[Zakenpartner_naam]
VAR varCurrentValue2 = 'EZK TRX_019_Overzicht_facturen_2023_DEV'[Datum_factuur]
VAR varCurrentValue3 = 'EZK TRX_019_Overzicht_facturen_2023_DEV'[Factuur_nr]
VAR varCurrentValue4 = 'EZK TRX_019_Overzicht_facturen_2023_DEV'[Bedrag_factuur_EV]
VAR varInstances = 
    COUNTROWS(
        FILTER(
            'EZK TRX_019_Overzicht_facturen_2023_DEV',
            'EZK TRX_019_Overzicht_facturen_2023_DEV'[Zakenpartner_naam] = varCurrentValue1 &&
            'EZK TRX_019_Overzicht_facturen_2023_DEV'[Datum_factuur] = varCurrentValue2 &&
            'EZK TRX_019_Overzicht_facturen_2023_DEV'[Factuur_nr] = varCurrentValue3 &&
            'EZK TRX_019_Overzicht_facturen_2023_DEV'[Bedrag_factuur_EV] = varCurrentValue4

        )
    )
var Result = 
    IF(
        varInstances > 1,
        "Duplicate",
        "Unique"
    )
RETURN
    Result

 

 

 

1 ACCEPTED SOLUTION
123abc
Community Champion
Community Champion

The error you're encountering in your DAX calculated column is likely due to the use of the COUNTROWS and FILTER functions, which are not supported in calculated columns. These functions are used for row-level calculations in DAX, and calculated columns are computed at the time of data refresh, so they don't have access to row-level context.

 

Plz try this:

Potential Double Invoices =
VAR varCurrentValue1 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Zakenpartner_naam])
VAR varCurrentValue2 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Datum_factuur])
VAR varCurrentValue3 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Factuur_nr])
VAR varCurrentValue4 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Bedrag_factuur_EV])
VAR varInstances =
COUNTROWS(
FILTER(
'EZK TRX_019_Overzicht_facturen_2023_DEV',
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Zakenpartner_naam] = varCurrentValue1 &&
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Datum_factuur] = varCurrentValue2 &&
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Factuur_nr] = varCurrentValue3 &&
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Bedrag_factuur_EV] = varCurrentValue4
)
)
RETURN
IF(
varInstances > 1,
"Duplicate",
"Unique"
)

View solution in original post

1 REPLY 1
123abc
Community Champion
Community Champion

The error you're encountering in your DAX calculated column is likely due to the use of the COUNTROWS and FILTER functions, which are not supported in calculated columns. These functions are used for row-level calculations in DAX, and calculated columns are computed at the time of data refresh, so they don't have access to row-level context.

 

Plz try this:

Potential Double Invoices =
VAR varCurrentValue1 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Zakenpartner_naam])
VAR varCurrentValue2 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Datum_factuur])
VAR varCurrentValue3 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Factuur_nr])
VAR varCurrentValue4 = SELECTEDVALUE('EZK TRX_019_Overzicht_facturen_2023_DEV'[Bedrag_factuur_EV])
VAR varInstances =
COUNTROWS(
FILTER(
'EZK TRX_019_Overzicht_facturen_2023_DEV',
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Zakenpartner_naam] = varCurrentValue1 &&
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Datum_factuur] = varCurrentValue2 &&
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Factuur_nr] = varCurrentValue3 &&
'EZK TRX_019_Overzicht_facturen_2023_DEV'[Bedrag_factuur_EV] = varCurrentValue4
)
)
RETURN
IF(
varInstances > 1,
"Duplicate",
"Unique"
)

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!

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.