cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
fhdalsafi
Frequent Visitor

TopN measure on multiple columns

Hello,

 

I am having a problem when trying to use TopN function.

 

I have this measure :

 

 

Class Hour =

Var _TESTTEST =
SUMMARIZE(
Data,
'Time Data'[Hour],
"TRXx",
CALCULATE([Trx Count],Data[PaymentType] in {"DB","PA"})
)
Var _Filter =
FILTER(
_TESTTEST,
[TRXx] <> 0
)

Var _TopNtest =
TOPN(
1,
_Filter,
[TRXx],
DESC
)

Var _Test =
SUMMARIZE(
Data,
Data[Bin],
Data[FullAccountNumber],
"PeakHour1",
_TopNtest
)
Return
COUNTROWS(_Test)
 
 
For more context, we use bin and fullaccountnumber columns to identify users, so my end goal is to get the hour for each user with highest transaction count.
  • the COUNTROWS function at the end is just to check if the measure works.
  • The Trx Count is just a measure we have to calculate the total transactions.
 
But when I test this measure on a Card visual for example I should get the number of rows that appear in the table I made. But I get an error indicating that the TopN function refers to multiple columns and it cannot be converted to a scalar value.
 
The problem was solved when I made a calculated table and added calculated column to it.
But is there a way that I can do it all in a measure and not use any type of calculated columns or tables?
 
If anything was unclear feel free to ask. Any help is appreciated.
 
Thanks,
2 REPLIES 2
Ailsa-msft
Community Support
Community Support

Hi @fhdalsafi 

TOPN can return results in batches, returning all the first N rows of records that meet the conditions from a table. Its role is equivalent to a filter not a measure or column to calculate a value .

You can learn more through the link below .

https://docs.microsoft.com/en-us/dax/topn-function-dax

 

Best Regards

Community Support Team _ Ailsa Tao

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

amitchandak
Super User
Super User

@fhdalsafi , TOPN returns table that act as filter, Not meausre

 

 

Usages example

calculate([Measure], TOPN( 1,allselected(Table[Column]),[Measure],DESC), values(Table[column])))

 

 

refer if needed

TOPN: https://www.youtube.com/watch?v=QIVEFp-QiOk&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42



New Power BI Features
Datamarts: https://youtu.be/8tskWsJTEpg
Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin !! Proud to be a Super User!
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
!! Subscribe to my youtube Channel !!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

Top Solution Authors
Top Kudoed Authors