Forum Discussion

Robot777's avatar
Robot777
New Member
2 years ago
Solved

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

 

 

 

  • 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"
    )

1 Reply

  • 123abc's avatar
    123abc
    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"
    )