cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
BENGAB Frequent Visitor
Frequent Visitor

DAX equivalent of NOT EXISTS

Hi, I need a solution for a DAX measurement based on this SQL:

 

I need to know how I can sort out how many V_KUNDELISTE_AKTIV_GES.kundenr that have V_KUNDELISTE_AKTIV_GES.NAERINGSKODENAMN = 'Hytter og fritidshus' and not

V_KUNDELISTE_AKTIV_GES.NAERINGSKODENAMN='Husholdninger'

 

SELECT V_KUNDELISTE_AKTIV_GES.FRA,

       V_KUNDELISTE_AKTIV_GES.STARTER,

       V_KUNDELISTE_AKTIV_GES.MAALEPKTNR,

       V_KUNDELISTE_AKTIV_GES.TIL,

       V_KUNDELISTE_AKTIV_GES.KUNDENAVN,

       V_KUNDELISTE_AKTIV_GES.KRAFTLEV,

       V_KUNDELISTE_AKTIV_GES.VALSTATUS,

       V_KUNDELISTE_AKTIV_GES.KUNDENR,

       V_KUNDELISTE_AKTIV_GES.KONTRAKTNR,

       V_KUNDELISTE_AKTIV_GES.POSTNR,

       V_KUNDELISTE_AKTIV_GES.MAALEPUNKTADRESSE,

       V_KUNDELISTE_AKTIV_GES.POSTSTED_ANLEGG,

       V_KUNDELISTE_AKTIV_GES.KOMMUNE,

       V_KUNDELISTE_AKTIV_GES.FOODSELDATO,

       V_KUNDELISTE_AKTIV_GES.FORETAKSNR,

       V_KUNDELISTE_AKTIV_GES.EPOST,

       V_KUNDELISTE_AKTIV_GES.MOBILTLFNR,

       V_KUNDELISTE_AKTIV_GES.TELEFONNR,

       V_KUNDELISTE_AKTIV_GES.KOMPKODESM,

       V_KUNDELISTE_AKTIV_GES.MAALEPUNKT,

       V_KUNDELISTE_AKTIV_GES.NETTEIER,

       V_KUNDELISTE_AKTIV_GES.AARSFORBRUK,

       V_KUNDELISTE_AKTIV_GES.RESEPTNR,

       V_KUNDELISTE_AKTIV_GES.RESEPTID,

       V_KUNDELISTE_AKTIV_GES.RESEPTNAMN,

       V_KUNDELISTE_AKTIV_GES.NAERINGSKODENAMN,

       V_KUNDELISTE_AKTIV_GES.METODE,

       V_KUNDELISTE_AKTIV_GES.EKSTRA1,

       V_KUNDELISTE_AKTIV_GES.BETTYPENAVN

  FROM BRUKARDATA.V_KUNDELISTE_AKTIV_GES

WHERE (V_KUNDELISTE_AKTIV_GES.NAERINGSKODENAMN = 'Hytter og fritidshus')

and not exists(select * from brukardata. V_KUNDELISTE_AKTIV_GES b

 where b.kundenr= V_KUNDELISTE_AKTIV_GES.kundenr

 and b.NAERINGSKODENAMN='Husholdninger')

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: DAX equivalent of NOT EXISTS

Hi @BENGAB,

 

Maybe you can try to use below formula to get count of specific item.

Result=
VAR temp =
    FILTER (
        ALLSELECTED ( V_KUNDELISTE_AKTIV_GES ),
        [NAERINGSKODENAMN] IN { "Hytter og fritidshus", "Husholdninger" }
    )
RETURN
    COUNTAX (
        FILTER (
            temp,
            [KUNDENR] = MAX ( [KUNDENR] )
                && [NAERINGSKODENAMN] <> "Husholdninger"
        ),
        [NAERINGSKODENAMN]
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: DAX equivalent of NOT EXISTS

HI @BENGAB,

 

For 'exist' filter, you can try to use in keyword. if you want 'not exists' operation, you can combine use NOT function and in keyword.

 

Sample:

Result =
IF (
    NOT ( 'Table 1'[column] IN VALUES ( 'Table 2'[column] ) ),
    'true expression',
    'false expression'
)

 

Reference link:

The IN operator in DAX

 

Notice: current in keyword not supported to compare multi-value with multi-value.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI
BENGAB Frequent Visitor
Frequent Visitor

Re: DAX equivalent of NOT EXISTS

Hi, Thanks for update.

 

What I realy need is a measure that counts  "Hytterkunder" where "Hyttekunder" is not like "Husholdninger" for the same KUNDENR.

In the picture I use to measure:

 

Hyttekunder = CALCULATE(V_KUNDELISTE_AKTIV_GES[TOTALT_aktive];filter(V_KUNDELISTE_AKTIV_GES;[NAERINGSKODENAMN]="Hytter og fritidshus"))

 

Husholdningskunder = CALCULATE(V_KUNDELISTE_AKTIV_GES[TOTALT_aktive];filter(V_KUNDELISTE_AKTIV_GES;[NAERINGSKODENAMN]="Husholdninger"))

 Kunder.JPG

 

 

Community Support Team
Community Support Team

Re: DAX equivalent of NOT EXISTS

Hi @BENGAB,

 

Maybe you can try to use below formula to get count of specific item.

Result=
VAR temp =
    FILTER (
        ALLSELECTED ( V_KUNDELISTE_AKTIV_GES ),
        [NAERINGSKODENAMN] IN { "Hytter og fritidshus", "Husholdninger" }
    )
RETURN
    COUNTAX (
        FILTER (
            temp,
            [KUNDENR] = MAX ( [KUNDENR] )
                && [NAERINGSKODENAMN] <> "Husholdninger"
        ),
        [NAERINGSKODENAMN]
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors