cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BENGAB
Regular 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
Community Support

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
Highlighted
Community Support
Community Support

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
Regular 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
Community Support

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
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors