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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
JanCronje16
Regular Visitor

Using DAX to Create a New Column Based on Groups Within Table

Hello,

 

The left 7 colums are part of a larger table that I must use to get the desiredd result in the require result colum for every row in my table.

 

I need to ignore any blank fields and if the remaing fields all contain the same datareturn that value in the results column. If the remaining fields do not contain the same data the result should be "Mixed".

 

JanCronje16_0-1736739940520.png

Any help will be appriciated.

 

Thanks

Jan

 

3 ACCEPTED SOLUTIONS
danextian
Super User
Super User

Hi @JanCronje16 

 

Try this:

 

Output =
// Define a variable `_TBL` to create a virtual table with specified columns
VAR _TBL = {
    'Table'[Column1],
    'Table'[Column2],
    'Table'[Column3],
    'Table'[Column4],
    'Table'[Column5]
} // Calculate the count of unique non-blank values in `_TBL`
VAR UniqueCount =
    COUNTROWS (
        // Count the number of rows in the resulting table
        DISTINCT (
            // Extract unique values from the filtered table
            FILTER (
                // Filter out blank values from `_TBL`
                _TBL,
                NOT ( ISBLANK ( [Value] ) ) // Keep rows where [Value] is not blank
            )
        )
    ) // Return the result based on the count of unique values
RETURN
    IF (
        UniqueCount > 1,
        // If there is more than 1 unique non-blank value
        "Mixed",
        // Return "Mixed"
        MAXX ( _TBL, [Value] ) // Otherwise, return the maximum value in `_TBL`
    )

 

danextian_0-1736745582609.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

shafiz_p
Super User
Super User

Hi @JanCronje16 , Try this:

Result = 
VAR NonBlankValues = 
    UNION(
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column1])) && 'Table'[Column1] = EARLIER('Table'[Column1])), "Value", 'Table'[Column1]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column2])) && 'Table'[Column2] = EARLIER('Table'[Column2])), "Value", 'Table'[Column2]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column3])) && 'Table'[Column3] = EARLIER('Table'[Column3])), "Value", 'Table'[Column3]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column4])) && 'Table'[Column4] = EARLIER('Table'[Column4])), "Value", 'Table'[Column4]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column5])) && 'Table'[Column5] = EARLIER('Table'[Column5])), "Value", 'Table'[Column5]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column6])) && 'Table'[Column6] = EARLIER('Table'[Column6])), "Value", 'Table'[Column6]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column7])) && 'Table'[Column7] = EARLIER('Table'[Column7])), "Value", 'Table'[Column7])
    )
VAR DistinctNonBlankValues = 
    FILTER(
        DISTINCT(NonBlankValues),
        [Value] <> BLANK()
    )
VAR FirstValue = MAXX(DistinctNonBlankValues, [Value])
VAR AllSame = 
    COUNTROWS(
        FILTER(
            DistinctNonBlankValues,
            [Value] <> FirstValue
        )
    ) = 0

RETURN
    IF(
        COUNTROWS(DistinctNonBlankValues) = 0,
        BLANK(),
        IF(
            AllSame,
            FirstValue,
            "Mixed"
        )
    )

 

Change column names accordingly.

 

Outputs:

shafiz_p_0-1736748683044.png

 



Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

View solution in original post

Thanks, works great.

View solution in original post

3 REPLIES 3
shafiz_p
Super User
Super User

Hi @JanCronje16 , Try this:

Result = 
VAR NonBlankValues = 
    UNION(
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column1])) && 'Table'[Column1] = EARLIER('Table'[Column1])), "Value", 'Table'[Column1]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column2])) && 'Table'[Column2] = EARLIER('Table'[Column2])), "Value", 'Table'[Column2]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column3])) && 'Table'[Column3] = EARLIER('Table'[Column3])), "Value", 'Table'[Column3]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column4])) && 'Table'[Column4] = EARLIER('Table'[Column4])), "Value", 'Table'[Column4]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column5])) && 'Table'[Column5] = EARLIER('Table'[Column5])), "Value", 'Table'[Column5]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column6])) && 'Table'[Column6] = EARLIER('Table'[Column6])), "Value", 'Table'[Column6]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column7])) && 'Table'[Column7] = EARLIER('Table'[Column7])), "Value", 'Table'[Column7])
    )
VAR DistinctNonBlankValues = 
    FILTER(
        DISTINCT(NonBlankValues),
        [Value] <> BLANK()
    )
VAR FirstValue = MAXX(DistinctNonBlankValues, [Value])
VAR AllSame = 
    COUNTROWS(
        FILTER(
            DistinctNonBlankValues,
            [Value] <> FirstValue
        )
    ) = 0

RETURN
    IF(
        COUNTROWS(DistinctNonBlankValues) = 0,
        BLANK(),
        IF(
            AllSame,
            FirstValue,
            "Mixed"
        )
    )

 

Change column names accordingly.

 

Outputs:

shafiz_p_0-1736748683044.png

 



Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

danextian
Super User
Super User

Hi @JanCronje16 

 

Try this:

 

Output =
// Define a variable `_TBL` to create a virtual table with specified columns
VAR _TBL = {
    'Table'[Column1],
    'Table'[Column2],
    'Table'[Column3],
    'Table'[Column4],
    'Table'[Column5]
} // Calculate the count of unique non-blank values in `_TBL`
VAR UniqueCount =
    COUNTROWS (
        // Count the number of rows in the resulting table
        DISTINCT (
            // Extract unique values from the filtered table
            FILTER (
                // Filter out blank values from `_TBL`
                _TBL,
                NOT ( ISBLANK ( [Value] ) ) // Keep rows where [Value] is not blank
            )
        )
    ) // Return the result based on the count of unique values
RETURN
    IF (
        UniqueCount > 1,
        // If there is more than 1 unique non-blank value
        "Mixed",
        // Return "Mixed"
        MAXX ( _TBL, [Value] ) // Otherwise, return the maximum value in `_TBL`
    )

 

danextian_0-1736745582609.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks, works great.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.