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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jimmyhua
Helper I
Helper I

Conditionally Select A Table give me error message

I created two tables one is for All divisions/ entire organization and one for divisions when one division is selected.  I have a variable called DivisionFilter using HASONEVALUE to detect if a division is selected.  if nothing is selected, I want to use the All division table to do a Top 10, otherwise I will use the division table to show divisional Top 10. 

When I use if statement below, I got a error message saying "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value".  

 

How do I fix it.  Thanks.

 

IF(
DivisionFilter,
FILTER(RankedDivision, [RankByBL] <= 10), // Top 10 within each division if filtered
TOPN(10, RankedAll, [Backlog], DESC) // Top 10 for the entire organization if not filtered
)

2 ACCEPTED SOLUTIONS
Irwan
Super User
Super User

hello @jimmyhua 

 

that happens because both FILTER() and TOPN() will give table (multiple value) as return value where your result needs to be a scalar (one value).

 

i believe FILTER() and TOPN() need another function to return as scalar.

here is a simple examples in form of measure.

Filter =
IF(
    ISFILTERED('Table'[Column2]),
    CALCULATE(
        MAX('Table'[Column1]),
        FILTER(
            'Table',
            'Table'[Index]>=1&&'Table'[Index]<=10
        )
    ),
    SELECTEDVALUE('Table'[Column1])
)

- unselect (return all value)

Irwan_0-1731201449689.png

- selected (return value with index 1 to 10)

Irwan_1-1731201474788.png

 

Hope this will help.
Thank you.

View solution in original post

Sahir_Maharaj
Super User
Super User

Hello @jimmyhua,

 

Can you please try this approach:

Top10Table = 
IF(
    HASONEVALUE(DivisionTable[Division]), 
    FILTER(RankedDivision, [RankByBL] <= 10), // Top 10 for selected division
    TOPN(10, RankedAll, [Backlog], DESC) // Top 10 for the entire organization
)

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

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" ๐Ÿ™‚

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
โžค Lets connect on LinkedIn: Join my network of 15K+ professionals
โžค Join my free newsletter: Data Driven: From 0 to 100
โžค Website: https://sahirmaharaj.com
โžค About: https://sahirmaharaj.com/about.html
โžค Email: sahir@sahirmaharaj.com
โžค Want me to build your Power BI solution? Lets chat about how I can assist!
โžค Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
โžค Explore my latest project (350K+ views): Wordlit.net
โžค 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

6 REPLIES 6
Irwan
Super User
Super User

hello @jimmyhua 

 

that happens because both FILTER() and TOPN() will give table (multiple value) as return value where your result needs to be a scalar (one value).

 

i believe FILTER() and TOPN() need another function to return as scalar.

here is a simple examples in form of measure.

Filter =
IF(
    ISFILTERED('Table'[Column2]),
    CALCULATE(
        MAX('Table'[Column1]),
        FILTER(
            'Table',
            'Table'[Index]>=1&&'Table'[Index]<=10
        )
    ),
    SELECTEDVALUE('Table'[Column1])
)

- unselect (return all value)

Irwan_0-1731201449689.png

- selected (return value with index 1 to 10)

Irwan_1-1731201474788.png

 

Hope this will help.
Thank you.

Thank you.  This one works.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

Jihwan_Kim_1-1731216885100.png

 

 

Jihwan_Kim_0-1731216860373.png

 

 

expected result measure: =
VAR _t =
    ADDCOLUMNS (
        SUMMARIZE (
            ALLSELECTED ( billing_fact ),
            division_dimension[division],
            billing_fact[billing]
        ),
        "@amount", CALCULATE ( SUM ( billing_fact[amount] ) )
    )
RETURN
    CALCULATE (
        SUM ( billing_fact[amount] ),
        KEEPFILTERS ( TOPN ( 10, _t, [@amount], DESC ) )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you very mcuh.  it works for me.

Anonymous
Not applicable

Hi @jimmyhua 

 

Do the methods solve your problem? If so, could you please mark helpful answers as solutions? This will help more users who are facing the same or similar difficulties. Thank you!

 

If there are still problems, please feel free to let me know.

 

Best Regards,
Yulia Xu

Sahir_Maharaj
Super User
Super User

Hello @jimmyhua,

 

Can you please try this approach:

Top10Table = 
IF(
    HASONEVALUE(DivisionTable[Division]), 
    FILTER(RankedDivision, [RankByBL] <= 10), // Top 10 for selected division
    TOPN(10, RankedAll, [Backlog], DESC) // Top 10 for the entire organization
)

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

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" ๐Ÿ™‚

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
โžค Lets connect on LinkedIn: Join my network of 15K+ professionals
โžค Join my free newsletter: Data Driven: From 0 to 100
โžค Website: https://sahirmaharaj.com
โžค About: https://sahirmaharaj.com/about.html
โžค Email: sahir@sahirmaharaj.com
โžค Want me to build your Power BI solution? Lets chat about how I can assist!
โžค Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
โžค Explore my latest project (350K+ views): Wordlit.net
โžค 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Users online (25)