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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Shruthi96
Helper III
Helper III

Dax code for multiple columns cannot be converted to a scalar value

Hi Team, 

I want help in fixing the DAX code, I have table called "KPI-color" and below is the measure which I have used. Let me know if any one from this group can able to fix this. Thanks

 

Shruthi96_0-1649169759092.png

Coummincation =

VAR countrow = if(CALCULATE(COUNTROWS('KPI - color'),'KPI - color'[Tag] >0),0,1)

VAR TOPROWS1 =

  GENERATE (

        VALUES ( 'KPI - color'[Service] ),

 

        VAR mytable =

            CALCULATETABLE ( TOPN ( 1, 'KPI - color' , [Tag], DESC) )

        RETURN

            SUMMARIZE ( mytable, 'KPI - color'[Tag] )

  )

VAR TOPROWS2 =

GENERATE (

        VALUES ( 'KPI - color'[Service] ),

        VAR mytable =

            CALCULATETABLE ('KPI - color')

        RETURN

            SUMMARIZE ( mytable, 'KPI - color'[Tag] )

)

 

VAR TOPROWS = if(countrow,toprows1,TOPROWS2)

 

VAR filteredRowsTable =

    CALCULATETABLE (

        'KPI - color',

        TOPROWS,

        FILTER (

           'KPI - color',

            MAX('KPI - color'[Tag])),'KPI - color'[Status] ="" || 'KPI - color'[Status] = "In Progress")

RETURN

filteredRowsTable

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Shruthi96 ,

 

The problem is here:

Icey_0-1649387656881.png

 

IF function checks a condition, and returns one value when it's TRUE, otherwise it returns a second value.  It can only return a value instead of a table.

 

In your scenario, try this:

 

Coummincation =
VAR countrow =
    IF ( CALCULATE ( COUNTROWS ( 'KPI - color' ), 'KPI - color'[Tag] > 0 ), 0, 1 )
VAR TOPROWS1 =
    GENERATE (
        VALUES ( 'KPI - color'[Service] ),
        VAR mytable =
            CALCULATETABLE ( TOPN ( 1, 'KPI - color', [Tag], DESC ) )
        RETURN
            SUMMARIZE ( mytable, 'KPI - color'[Tag] )
    )
VAR TOPROWS2 =
    GENERATE (
        VALUES ( 'KPI - color'[Service] ),
        VAR mytable =
            CALCULATETABLE ( 'KPI - color' )
        RETURN
            SUMMARIZE ( mytable, 'KPI - color'[Tag] )
    )
VAR filteredRowsTable1 =
    CALCULATETABLE (
        'KPI - color',
        toprows1,
        FILTER (
            'KPI - color',
            'KPI - color'[Status] = ""
                || 'KPI - color'[Status] = "In Progress"
        )
    )
VAR filteredRowsTable2 =
    CALCULATETABLE (
        'KPI - color',
        toprows2,
        FILTER (
            'KPI - color',
            'KPI - color'[Status] = ""
                || 'KPI - color'[Status] = "In Progress"
        )
    )
RETURN
    IF (
        countrow,
        CONCATENATEX ( filteredRowsTable1, [Tag], ", " ),
        CONCATENATEX ( filteredRowsTable2, [Tag], ", " )
    )

 

 

 

Best Regards,

Icey

 

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

7 REPLIES 7
Icey
Community Support
Community Support

Hi @Shruthi96 ,

 

The problem is here:

Icey_0-1649387656881.png

 

IF function checks a condition, and returns one value when it's TRUE, otherwise it returns a second value.  It can only return a value instead of a table.

 

In your scenario, try this:

 

Coummincation =
VAR countrow =
    IF ( CALCULATE ( COUNTROWS ( 'KPI - color' ), 'KPI - color'[Tag] > 0 ), 0, 1 )
VAR TOPROWS1 =
    GENERATE (
        VALUES ( 'KPI - color'[Service] ),
        VAR mytable =
            CALCULATETABLE ( TOPN ( 1, 'KPI - color', [Tag], DESC ) )
        RETURN
            SUMMARIZE ( mytable, 'KPI - color'[Tag] )
    )
VAR TOPROWS2 =
    GENERATE (
        VALUES ( 'KPI - color'[Service] ),
        VAR mytable =
            CALCULATETABLE ( 'KPI - color' )
        RETURN
            SUMMARIZE ( mytable, 'KPI - color'[Tag] )
    )
VAR filteredRowsTable1 =
    CALCULATETABLE (
        'KPI - color',
        toprows1,
        FILTER (
            'KPI - color',
            'KPI - color'[Status] = ""
                || 'KPI - color'[Status] = "In Progress"
        )
    )
VAR filteredRowsTable2 =
    CALCULATETABLE (
        'KPI - color',
        toprows2,
        FILTER (
            'KPI - color',
            'KPI - color'[Status] = ""
                || 'KPI - color'[Status] = "In Progress"
        )
    )
RETURN
    IF (
        countrow,
        CONCATENATEX ( filteredRowsTable1, [Tag], ", " ),
        CONCATENATEX ( filteredRowsTable2, [Tag], ", " )
    )

 

 

 

Best Regards,

Icey

 

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

tamerj1
Super User
Super User

Hi @Shruthi96 
You may try

Coummincation =
VAR countrow =
    IF ( CALCULATE ( COUNTROWS ( 'KPI - color' ), 'KPI - color'[Tag] > 0 ), 0, 1 )
VAR TOPROWS1 =
    GENERATE (
        VALUES ( 'KPI - color'[Service] ),
        VAR mytable =
            CALCULATETABLE ( TOPN ( 1, 'KPI - color', [Tag], DESC ) )
        RETURN
            SUMMARIZE ( mytable, 'KPI - color'[Tag] )
    )
VAR TOPROWS2 =
    GENERATE (
        VALUES ( 'KPI - color'[Service] ),
        VAR mytable =
            CALCULATETABLE ( 'KPI - color' )
        RETURN
            SUMMARIZE ( mytable, 'KPI - color'[Tag] )
    )
VAR TOPROWS =
    IF ( countrow, toprows1, TOPROWS2 )
VAR filteredRowsTable =
    CALCULATETABLE (
        'KPI - color',
        TOPROWS,
        FILTER (
            'KPI - color',
            'KPI - color'[Status] = ""
                || 'KPI - color'[Status] = "In Progress"
        )
    )
RETURN
    MAXX ( filteredRowsTable, 'KPI - color'[Tag] )

@tamerj1 , same error. 

 

Shruthi96_0-1649221725189.png

 

Shruthi96
Helper III
Helper III

There is any alternative way to solve? 

Shruthi96
Helper III
Helper III

Thanks @amitchandak for reply.. but no luck

 

Shruthi96_1-1649170723124.png

 

 

amitchandak
Super User
Super User

@Shruthi96 , You are returning a table, And if you are creating a measure you need to return values like

 

countrows(filteredRowsTable)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@Shruthi96 , I doubt if will work for tables

 

VAR TOPROWS = if(countrow,toprows1,TOPROWS2)

 

 

Also was at the wrong place here - correct this one and check. 

VAR filteredRowsTable =

CALCULATETABLE (

'KPI - color',

TOPROWS,

FILTER (

'KPI - color','KPI - color'[Status] ="" || 'KPI - color'[Status] = "In Progress")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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