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
Anonymous
Not applicable

Using TOPN not giving expected result

Hi Experts
First I need to mention that this is through a live connection. All have a correct connection.
After reading several posts, I thought my measure was ready for the task, but no. There are two takeaways i want to use the measure for:

  1. Getting the actual value for what ever "TOPN"-n i use.
  2. Hold the values of "Postal Code" in new VAR for alternative measuer.

My Measure:

#Top 20 PostalCodes SalesNet = 
VAR _Exclude =
FILTER(
KEEPFILTERS(VALUES('Customer'[Customer Postal Code])),
'Customer'[Customer Postal Code] <> "n/a"
)

VAR _SalesPerCode =
SUMMARIZECOLUMNS(
Customer[Customer Postal Code],
_Exclude,
"Sales Net",[Sales Net]
)

VAR _TOP20 =
TOPN(20,_SalesPerCode,0)

VAR _Core =
SUMMARIZECOLUMNS(
Customer[Customer Postal Code],
_Exclude,
_TOP20,
"Sales_Net", [Sales Net]
)

RETURN

SUMX(_Core, [Sales_Net])

For the 1 point, I'm stuck on understanding why the this gives me the following error:

Krib_0-1639658435388.png

For the 2 point im just plain stuck on how to solve this. When looking at this in DaxStudio, i get a table of the top sales net per postal code:

Krib_1-1639658534632.png

I am convinced that I should be able to hold the "Postal code" to be used further in a variable.
Grateful for all help!

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

As @smpa01 mentioned, while SUMMARIZECOLUMNS is great for DAX queries but isn't useful inside measures.

 

I don't think you need it here though. Try this:

#Top 20 PostalCodes SalesNet =
VAR _Exclude =
    FILTER (
        KEEPFILTERS ( VALUES ( 'Customer'[Customer Postal Code] ) ),
        'Customer'[Customer Postal Code] <> "n/a"
    )
VAR _SalesPerCode = ADDCOLUMNS ( _Exclude, "@SalesNet", [Sales Net] )
VAR _TOP20 = TOPN ( 20, _SalesPerCode, [@SalesNet] )
RETURN
    SUMX ( _TOP20, [@SalesNet] )

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

As @smpa01 mentioned, while SUMMARIZECOLUMNS is great for DAX queries but isn't useful inside measures.

 

I don't think you need it here though. Try this:

#Top 20 PostalCodes SalesNet =
VAR _Exclude =
    FILTER (
        KEEPFILTERS ( VALUES ( 'Customer'[Customer Postal Code] ) ),
        'Customer'[Customer Postal Code] <> "n/a"
    )
VAR _SalesPerCode = ADDCOLUMNS ( _Exclude, "@SalesNet", [Sales Net] )
VAR _TOP20 = TOPN ( 20, _SalesPerCode, [@SalesNet] )
RETURN
    SUMX ( _TOP20, [@SalesNet] )
Anonymous
Not applicable

Thx to both. Had missunderstood "SUMMARIZECOLUMNS" a bit outside queries 😀
Your edit gives the exact total as i was looking for, Thank you.

smpa01
Super User
Super User

@Anonymous  SUMMARIZECOLUMNS can't be utilized in a measure. It only works in DAX table expression.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.