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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
didi42
Frequent Visitor

TOPN across several measures

 

Hello,

 

I would need your help on one issue I am able to solve in m language but I would like to do in DAX : 

  • I have a simple data set of sales of product per store and per dates, as well as text comment for each product sale

Capture1.JPG

 

  • This set is linked to a calendar table created with CALENDAR() function
  • I have measures to return the monthly variation of each product

 

 

Previousmonth variation product2 = SUM(Sheet1[Product 2])-calculate(sum(Sheet1[Product 2]),PREVIOUSMONTH('Calendar'[Date].[Date]))

 

 

Capture2.JPG

 

I am able to display the TOPN variation of each product individually by applying TOPN filter on my Table, however, I would like to get the TOPN for all the products altogether. For example, for February, I would like to get for TOP 5 variations :

Capture3.JPG

I found a way to do it in m language, but  guess it would be less time processing and more evolutive by doing it in DAX.

For information, the way I can do it in m is:

  • Add a new column which return the date of the previous month
  • Join the table with itself with the 2 dates columns, I then get on 1 row the data of current month and previous month
  • Add new columns to get variations for each product
  • Use List.Zip to get the columns I need as shown in the previous example table
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @didi42 ;

You could try to create a table.

New table = 
var _a=SUMMARIZE('Table',[Store],[Explanation],"Variation",[Product 1],"Product","Product1")
var _b=SUMMARIZE('Table',[Store],[Explanation],"Variation",[Product2],"Product","Product2")
var _c=SUMMARIZE('Table',[Store],[Explanation],"Variation",[Product3],"Product","Product3")
return TOPN(5, union(_a,_b,_c),[Variation],DESC)

The final output is shown below:

vyalanwumsft_0-1645583274212.png


Best Regards,
Community Support Team_ Yalan Wu
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

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @didi42 ;

You could try to create a table.

New table = 
var _a=SUMMARIZE('Table',[Store],[Explanation],"Variation",[Product 1],"Product","Product1")
var _b=SUMMARIZE('Table',[Store],[Explanation],"Variation",[Product2],"Product","Product2")
var _c=SUMMARIZE('Table',[Store],[Explanation],"Variation",[Product3],"Product","Product3")
return TOPN(5, union(_a,_b,_c),[Variation],DESC)

The final output is shown below:

vyalanwumsft_0-1645583274212.png


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PaulDBrown
Community Champion
Community Champion

Can you share some actual sample data to work on?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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