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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
anwarbham
New Member

TopN ranking working in Dax Query view but not in Visual

Hi i am seeing some strange issue with the TopN function in power Bi

i have a dax formula 

    TOPN(
        10, // <-- This is N. Change to 5 for Top 5, 20 for Top 20, etc.
        VALUES(Fact_Table[EndDate_Time_Value]), -- <-- IMPORTANT: CHANGE THIS to the column you want to rank (e.g., VALUES('Product'[Product Name]))
          CALCULATE(
        SUM(Fact_Table[EndDate_Time_Value]),
        Fact_Table[stage] = "4B",
        Fact_Table[Produktion] = "OFF",
        Fact_Table[_Flag.1] = 1
    )
    )

this works in the Dax Query studio

anwarbham_0-1750319087561.png

but in the visual i get this message

anwarbham_1-1750319152163.png

my table is below

anwarbham_2-1750319878148.png

is this a bug ?

 

2 ACCEPTED SOLUTIONS
FBergamaschi
Helper I
Helper I

Hello,

TOPN returns a table.
A measure cannot be a table of values but a single value. It works in query view as a DAX query returns a table. If you want to have it working in the DAX formula in Power BI you need to create a calculated table and not a measure. If you need a measure then you need to aggregate the values of this table. Hope I was clear, otherwise come back to me. You cann attach the pbix and I shall help but I need to know what you are trying to calculate.

Best

FB

View solution in original post

mark_endicott
Super User
Super User

@anwarbham - You are returning a table in TOPN and that cannot be produced as the output of a measure in a visual. 

 

You will be able to use this DAX to create a Calculated table. Or you could use the TOPN as a Variable (VAR) and then you can RETURN a calculation that aggregates or selects something from this table stored in the variable. 

 

If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

View solution in original post

4 REPLIES 4
FBergamaschi
Helper I
Helper I

Thanks for the kudos, in case it is ok like this can you mark it as a solution? Otherwise here I am Best, FB

mark_endicott
Super User
Super User

@anwarbham - You are returning a table in TOPN and that cannot be produced as the output of a measure in a visual. 

 

You will be able to use this DAX to create a Calculated table. Or you could use the TOPN as a Variable (VAR) and then you can RETURN a calculation that aggregates or selects something from this table stored in the variable. 

 

If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

mdaatifraza5556
Solution Specialist
Solution Specialist

Hi @anwarbham 

This happens because TOPN returns a table 

 

 

If this answers your questions, kindly accept it as solution and give kudos.

FBergamaschi
Helper I
Helper I

Hello,

TOPN returns a table.
A measure cannot be a table of values but a single value. It works in query view as a DAX query returns a table. If you want to have it working in the DAX formula in Power BI you need to create a calculated table and not a measure. If you need a measure then you need to aggregate the values of this table. Hope I was clear, otherwise come back to me. You cann attach the pbix and I shall help but I need to know what you are trying to calculate.

Best

FB

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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