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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Walaa_86
New Member

Urgent- How to create a calculated column based on conditions in two other columns in DAX

Hi, 

I'm trying to add a calculated column based on conditions in other two columns in the same table to to have three age groups

 

Age groups = Calculate(IF(filter('Table', 'Table'[Year group] = "N"  || able', 'Table'[Year group]able', 'Table'[Year group]="E" && FILTER(Table', 'Table'[Age] < 5)), "Nursery", IF(filter(able', 'Table'[Year group] = "12" || 'Table'[Year group]= "13" && FILTER(Table', 'Table'[Age] > 15)), "Other year groups", "5-15 years")))

The code above gives me  this error:

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value. 

 

Could you please hel me fixx the code?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Walaa_86 

 

You can try using only the IF function.

Age groups =
IF (
    [Year group] = "N",
    "Nursery",
    IF (
        [Year group] = "E"
            && [Age] < 5,
        "Nursery",
        IF (
            [Year group] = "12"
                || [Year group] = "13"
                && [Age] > 5,
            "Other year groups",
            "5-15 years"
        )
    )
)

vzhangti_0-1638180094028.png

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Walaa_86 

 

You can try using only the IF function.

Age groups =
IF (
    [Year group] = "N",
    "Nursery",
    IF (
        [Year group] = "E"
            && [Age] < 5,
        "Nursery",
        IF (
            [Year group] = "12"
                || [Year group] = "13"
                && [Age] > 5,
            "Other year groups",
            "5-15 years"
        )
    )
)

vzhangti_0-1638180094028.png

 

Best Regards,

Community Support Team _Charlotte

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

Walaa_86
New Member

This is how I want my Age group column to look like:

Walaa_86_2-1637758572499.png

 

Walaa_86
New Member

Walaa_86_1-1637758294280.png

 

This is how my table looks like. I need to separate the age grous so that I can have Age group as a filter and while I'm filtering for the "nursery" it only shows me year N or E in the year group filter.

Cbutler
Helper III
Helper III

can you share an example of your underlying table data? 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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