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
afrutos
Resolver I
Resolver I

Conditional

 

Hello everyone, I have a question that I can't solve.
In this table I have a column with IdAuthor, and another that is Author Category.
I need to calculate something like this:
If the IdAuthor is Director, Writer and Screenwriter, I need to put "Director and Screenwriter".
If the IdAuthor is Director then Director
However when I apply my formula with SWITCH clause it doesn't get it for when the IdAuthor is Director, Writer and Writer at the same time.
This is my formula

Can you help me? Thanks

afrutos_1-1640188597923.png

 

 

afrutos_0-1640188517933.png

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

Hi @afrutos ,

You can create a calculated column as below, please find the details in the attachment.

Category = 
VAR _category =
    CONCATENATEX (
        FILTER (
            ALL ( 'Authors' ),
            'Authors'[IdAuthor] = EARLIER ( 'Authors'[IdAuthor] )
        ),
        [CategoryAuthor],
        ",",
        'Authors'[CategoryAuthor]
    )
RETURN 
    IF (
        _category = "Director,Screenwriter,Writer ",
        "Director and Screenwriter",
        'Authors'[CategoryAuthor]
    )

yingyinr_0-1640592339077.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-yiruan-msft
Community Support
Community Support

Hi @afrutos ,

You can create a calculated column as below, please find the details in the attachment.

Category = 
VAR _category =
    CONCATENATEX (
        FILTER (
            ALL ( 'Authors' ),
            'Authors'[IdAuthor] = EARLIER ( 'Authors'[IdAuthor] )
        ),
        [CategoryAuthor],
        ",",
        'Authors'[CategoryAuthor]
    )
RETURN 
    IF (
        _category = "Director,Screenwriter,Writer ",
        "Director and Screenwriter",
        'Authors'[CategoryAuthor]
    )

yingyinr_0-1640592339077.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, thank you how did you create the colum "column"?
I need to do this step before

Hi @afrutos ,

Please right-click or select the ellipsis ... next to the table Author in the Fields pane, and select New column from the menu just as below screenshot. You can find more details in the following official documentation.

Tutorial: Create calculated columns in Power BI Desktop

yingyinr_0-1640942558270.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Yes I know how to create a new Column, but my question is what did you do in that Calculated Column.
I mean, you showed me the column Category, 
Could you please showed me the Column column?

Hi @afrutos ,

You can just ignore that calculated column. I created that calculated column to show the unique category that each author belongs to, and then each category is concatenate with a ",".

Column = 
CONCATENATEX (
    FILTER ( 'Authors', 'Authors'[IdAuthor] = EARLIER ( 'Authors'[IdAuthor] ) ),
    'Authors'[CategoryAuthor],
    ",",
    'Authors'[CategoryAuthor]
)

yingyinr_0-1640943930579.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ryan_mayu
Super User
Super User

@afrutos 

the Dax you highlighted does not work. You can try this

Column = 
VAR _d=maxx(FILTER('Table','Table'[IdAutor]=EARLIER('Table'[IdAutor])&&'Table'[CategoriaAtor]="Director"),'Table'[CategoriaAtor])
VAR _g=maxx(FILTER('Table','Table'[IdAutor]=EARLIER('Table'[IdAutor])&&'Table'[CategoriaAtor]="Guionista"),'Table'[CategoriaAtor])
VAR _a=maxx(FILTER('Table','Table'[IdAutor]=EARLIER('Table'[IdAutor])&&'Table'[CategoriaAtor]="Argumentista"),'Table'[CategoriaAtor])
return if(_a<>""&&_g<>""&&_d<>"","Director and Screenwriter")

1.PNG





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

Proud to be a Super User!




amitchandak
Super User
Super User

@afrutos , a new column like

 

New column =
var _1 = countx(filter(Table, [IdAuthor] =earlier([IdAuthor]) && [CategoryAuthor] in {"Director","Writer","Screenwriter"} ) ,[IdAuthor])+0
var _2 = countx(filter(Table, [IdAuthor] =earlier([IdAuthor]) && [CategoryAuthor] in {"Director"} ) ,[IdAuthor])+0
return
switch(true(),
_1=3, "Director and Screenwriter",
_2 =1 , "Director",
[CategoryAuthor]
)

Hi, i'm sorry but it's still not working
Because for exaple for the first one I should have "Director and Screenwriter"

afrutos_1-1640190554316.png

 

 

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.