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
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
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.