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
amjedashraf
Frequent Visitor

if condition to make category combinations

Hi All,

 

I need help to figure out the dax for the below 

 

I have a table with following fields

 

Trancation ID  Category Combinations

1                      A             One Category

1                      A             Once Category

2                     A              Two Category

2                     b               Two Category

 

Bascially i need and If conditon like if(tranaction ID contains disitinct one category, "One Category" and if (trancation contain 2 disitnat category, " Two Category and so on can anyone please help me on this.

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @amjedashraf ,

 

1. Create a measure:

Measure =
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Category] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Trancation ID] = MAX ( 'Table'[Trancation ID] )
        )
    )
RETURN
    SWITCH ( _count, 1, "One Category", 2, "Two Category" )

 

2.Add a column:

Column =
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Category] ),
        ALLEXCEPT ( 'Table', 'Table'[Trancation ID] )
    )
RETURN
    SWITCH ( _count, 1, "One Category", 2, "Two Category" )

My final output looks like this:

12.7.3.1.PNG

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @amjedashraf ,

 

1. Create a measure:

Measure =
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Category] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Trancation ID] = MAX ( 'Table'[Trancation ID] )
        )
    )
RETURN
    SWITCH ( _count, 1, "One Category", 2, "Two Category" )

 

2.Add a column:

Column =
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Category] ),
        ALLEXCEPT ( 'Table', 'Table'[Trancation ID] )
    )
RETURN
    SWITCH ( _count, 1, "One Category", 2, "Two Category" )

My final output looks like this:

12.7.3.1.PNG

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

ryan_mayu
Super User
Super User

@amjedashraf 

maybe you can try to create one of below column

Column = CALCULATE(DISTINCTCOUNT('Table (2)'[Category]),ALLEXCEPT('Table (2)','Table (2)'[Transaction ID]))&" Category"

Column 2 = 
VAR num=CALCULATE(DISTINCTCOUNT('Table (2)'[Category]),ALLEXCEPT('Table (2)','Table (2)'[Transaction ID]))
return if (num=1,"One Category", if(num=2,"Two Category"))

  1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.