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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
CL7777
Helper III
Helper III

finding the product in a selected prod group that has the highest revenue or quantity sold

I consider myself an intermediate Dax user but Im having problems figuring out this measure. I have a table that has the following (sample) data:

 

year       part num     prod group     revenue    qty sold

2020       xx                   X                       5              2

2020       xx                   X                       17            4

2020       xx2                 X                       50            2

2020       xx2                 X                       59            3

2020       yy                   Y                       15            1

2020       yy                   Y                       50            4

2020       yy3                 Y                       5              5

2020       yy3                 Y                       65            9

2019       xx                   X                       75            6

2019       xx2                 X                       5              2

2019       xx                   X                       5              2

 

I want to select a product group and a year from slicers, and have measures that will show the part number with the greatest total revenue and greatest total quantity sold for that product group and year, along with the value of the total revenue and quantity. In the above data, if we select product group X and 2020 as the year in the slicers, I want the measure to show that product xx had the most quantity sold at 6 and product xx2 had the most revenue generated at 109. 

 

any help I could get would be much appreciated.

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@CL7777,

 

Try these measures. The ADDCOLUMNS function allows you to calculate the total quantity or revenue at the part level, and TOPN filters for the largest amount.

 

Total Quantity Sold = SUM (Table1[qty sold] )
Total Revenue = SUM ( Table1[revenue] )
Most Quantity Sold = 
VAR vTable =
    ADDCOLUMNS ( VALUES ( Table1[part num] ), "@Amount", [Total Quantity Sold] )
VAR vTopRow =
    TOPN ( 1, vTable, [@Amount], DESC )
VAR vPart =
    MAXX ( vTopRow, Table1[part num] )
VAR vAmount =
    MAXX ( vTopRow, [@Amount] )
VAR vResult = vPart & " - " & vAmount
RETURN
    vResult
Most Revenue Generated = 
VAR vTable =
    ADDCOLUMNS ( VALUES ( Table1[part num] ), "@Amount", [Total Revenue] )
VAR vTopRow =
    TOPN ( 1, vTable, [@Amount], DESC )
VAR vPart =
    MAXX ( vTopRow, Table1[part num] )
VAR vAmount =
    MAXX ( vTopRow, [@Amount] )
VAR vResult = vPart & " - " & vAmount
RETURN
    vResult

 

DataInsights_0-1651764525428.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@CL7777,

 

Try these measures. The ADDCOLUMNS function allows you to calculate the total quantity or revenue at the part level, and TOPN filters for the largest amount.

 

Total Quantity Sold = SUM (Table1[qty sold] )
Total Revenue = SUM ( Table1[revenue] )
Most Quantity Sold = 
VAR vTable =
    ADDCOLUMNS ( VALUES ( Table1[part num] ), "@Amount", [Total Quantity Sold] )
VAR vTopRow =
    TOPN ( 1, vTable, [@Amount], DESC )
VAR vPart =
    MAXX ( vTopRow, Table1[part num] )
VAR vAmount =
    MAXX ( vTopRow, [@Amount] )
VAR vResult = vPart & " - " & vAmount
RETURN
    vResult
Most Revenue Generated = 
VAR vTable =
    ADDCOLUMNS ( VALUES ( Table1[part num] ), "@Amount", [Total Revenue] )
VAR vTopRow =
    TOPN ( 1, vTable, [@Amount], DESC )
VAR vPart =
    MAXX ( vTopRow, Table1[part num] )
VAR vAmount =
    MAXX ( vTopRow, [@Amount] )
VAR vResult = vPart & " - " & vAmount
RETURN
    vResult

 

DataInsights_0-1651764525428.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




thank you SO much, that is really elegant and works perfectly. I will accept as a solution

@CL7777,

 

Thanks, glad to hear that!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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