Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Case when in dax

I want to convert 

count(distinct(case when invoice_type_id in (1,3,5,9) then sys_invoice_no else null end))
-
count(distinct(case when invoice_type_id in (7,14) and full_return_flag = 1 then sys_invoice_no else null end)) as tickets

 

to a dax measure. Can this be done?

1 ACCEPTED SOLUTION
Gordonlilj
Solution Sage
Solution Sage

Hi,

 

I'm not sure if i've read your code correctly but something like this might work

Tickets = 
CALCULATE( DISTINCTCOUNT( 'Table'[sys_invoice_no] ),
'Table'[invoice_type_id] IN ( {1,3,5,9} ) ) -

CALCULATE( DISTINCTCOUNT( 'Table'[sys_invoice_no] ),
'Table'[invoice_type_id] IN ( {7,14} ),
'Table'[full_return_flag] = 1 )

 

View solution in original post

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could try this DAX and tell me if it works.

tickets =
SWITCH (
    TRUE (),
    'Table'[invoice_type_id] IN { 1, 3, 5, 9 }, DISTINCTCOUNT ( 'Table'[sys_invoice_no] ),
    BLANK ()
)
    - SWITCH (
        TRUE (),
        AND ( 'Table'[invoice_type_id] IN { 7, 14 }, 'Table'[full_return_flag] = 1 ), DISTINCTCOUNT ( 'Table'[sys_invoice_no] ),
        BLANK ()
    )

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Gordonlilj
Solution Sage
Solution Sage

Hi,

 

I'm not sure if i've read your code correctly but something like this might work

Tickets = 
CALCULATE( DISTINCTCOUNT( 'Table'[sys_invoice_no] ),
'Table'[invoice_type_id] IN ( {1,3,5,9} ) ) -

CALCULATE( DISTINCTCOUNT( 'Table'[sys_invoice_no] ),
'Table'[invoice_type_id] IN ( {7,14} ),
'Table'[full_return_flag] = 1 )

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.