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
Deborah1982
New Member

DAX formula where should I insert this?

Hi,

 

I have created in a previous report an extra column, with a formula, if I now check the formula it's: 

"Company", each if Text.Contains([SO nr], "BMB") then "BMB" else if Text.Contains([SO nr], "HER") then "HERENTALS" else if Text.Contains([SO nr], "HZ") then "HEUSDEN-ZOLDER" else if Text.Contains([SO nr], "EBAY") then "EBAY" else if Text.StartsWith([SO nr], "SO") then "WEBSITE SALES" else "to be defined")

 

However if I add column in my new report, it gives an error, to not know why?

Is there a difference between formula in the column area, and query area?

 

Regards

Deborah

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Deborah1982,

 

To add an extra column using DAX code in Report View mode, you could try below formula. Suppose the table name is 'Table1' and the new column is named as 'Company'.

Company =
IF (
    NOT ( ISERROR ( SEARCH ( "BMB", Table1[SO nr] ) ) ),
    "BMB",
    IF (
        NOT ( ISERROR ( SEARCH ( "HER", Table1[SO nr] ) ) ),
        "HERENTALS",
        IF (
            NOT ( ISERROR ( SEARCH ( "HZ", Table1[SO nr] ) ) ),
            "HEUSDEN-ZOLDER",
            IF (
                NOT ( ISERROR ( SEARCH ( "EBAY", Table1[SO nr] ) ) ),
                "EBAY",
                IF (
                    NOT ( ISERROR ( SEARCH ( "SO", Table1[SO nr] ) ) ),
                    "WEBSITE SALES",
                    "to be defined"
                )
            )
        )
    )
)

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @Deborah1982,

 

To add an extra column using DAX code in Report View mode, you could try below formula. Suppose the table name is 'Table1' and the new column is named as 'Company'.

Company =
IF (
    NOT ( ISERROR ( SEARCH ( "BMB", Table1[SO nr] ) ) ),
    "BMB",
    IF (
        NOT ( ISERROR ( SEARCH ( "HER", Table1[SO nr] ) ) ),
        "HERENTALS",
        IF (
            NOT ( ISERROR ( SEARCH ( "HZ", Table1[SO nr] ) ) ),
            "HEUSDEN-ZOLDER",
            IF (
                NOT ( ISERROR ( SEARCH ( "EBAY", Table1[SO nr] ) ) ),
                "EBAY",
                IF (
                    NOT ( ISERROR ( SEARCH ( "SO", Table1[SO nr] ) ) ),
                    "WEBSITE SALES",
                    "to be defined"
                )
            )
        )
    )
)

Best regards,
Yuliana Gu

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

Hey,

 

there is a big difference between the formula that is (I would better say: can be) used in the column area or the query area.

 

To be absolutely sure that we are talking about the same:

The query area is the area where you get data from your source files / systems.

Within this area your Point/Click transformations are translated into a script/programming language called "M". The formula you are using in your post makes use of this language.

 

The column area, as you call it, allows you to add additional columns to existing tables (created through the query area), using the query language DAX.

 

Both languages are totally different, syntax and functions, because both have to solve some completely different tasks.

 

Unfortunately it's possible to add columns using M (query area - the tool is often called Query Editor, or still Power Query, the name of the Excel Add-in until Excel 2013), and it's also possible to add columns using DAX - the question you have to answer, where to go.

The answer, as always, it depends.

 

Here are links to the official DAX functions that come to my mind looking at your statement

Personally, I tend to create columns using M, as long as the value can be derived for each row separately.

 

Hope this helps somehow

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.