Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a simple raw table. I want to create a Product Dimension table from the Raw Source.
Each Location can overwrite the ProdDescription locally. In most cases, they will use a default name but there will be outliers.
I want to use the Product Description that has the highest summed quantity.
I had thought of building 2 temporary tables from the raw
Table1 = Summarize RawData to ProductCode,ProductDescp,Sum(Qty)
Table2 = Summarize Table1 with a Rank and only show if Rank = 1
Then Relate Table2 back to RawData
I feel like that is going the long way. Is there a better Way?
Final Result Desired:
Product Description for each Product code that sums to have the highest Qty
***** Solution was accepted below but there was a final corrected piece of code:
Here was the final code I used
SummarizedTable3 =
VAR __Table1 = Summarize(RawTable,[ProdCode],[ProdDescp],"Qty",Sum(RawTable[Qty]))
VAR __Table2 = ADDCOLUMNS(__Table1 ,"Rnk", RANKX(all(RawTable[ProdCode], RawTable[ProdDescp]),CALCULATE(SUM(RawTable[Qty]))))
RETURN
filter(__Table2,[Rnk]=1)
Solved! Go to Solution.
@briguin , Try like
filter(ADDCOLUMNS(Summarize(Table,[ProductCode],[ProductDescp],"Qty",Sum(Table[Qty])) ,"Rnk", RANKX(all(Table[ProductCode], Table[ProductDescp]),CALCULATE(COUNT(Table[Qty])))),[Rnk]=1)
@briguin , Try like
filter(ADDCOLUMNS(Summarize(Table,[ProductCode],[ProductDescp],"Qty",Sum(Table[Qty])) ,"Rnk", RANKX(all(Table[ProductCode], Table[ProductDescp]),CALCULATE(COUNT(Table[Qty])))),[Rnk]=1)
@amitchandak
I think that's close enough.
Made a couple of tweaks to your Code.
Broke it out to variables, so I could better understand
SummarizedTable3 =
VAR __Table1 = Summarize(RawTable,[ProdCode],[ProdDescp],"Qty",Sum(RawTable[Qty]))
VAR __Table2 = ADDCOLUMNS(__Table1 ,"Rnk", RANKX(all(RawTable[ProdCode], RawTable[ProdDescp]),CALCULATE(SUM(RawTable[Qty]))))
RETURN
filter(__Table2,[Rnk]=1)
Changed to Sum vs Count. Looks like correct results. Count returned a single row
@briguin OK, admittedly, there were errors made: 🙂
Table (21a) =
VAR __Table = SUMMARIZE('Table (21)',[ProdCode],[ProdDescp],"Qty",SUM('Table (21)'[Qty]))
VAR __Table1 =
ADDCOLUMNS(
__Table,
"Max",COUNTROWS(FILTER(__Table,[Qty]<=EARLIER([Qty]) && [ProdCode]=EARLIER([ProdCode]) && [ProdDescp]=EARLIER([ProdDescp])))
)
RETURN
FILTER(__Table1,[Max]=1)
PBIX is attached.
@briguin - Perhaps:
New Table =
VAR __Table = SUMMARIZE('Table',[ProdCode],[ProdDescp],"Count",COUNT([Qty]))
VAR __Table1 =
ADDCOLUMNS(
__Table,
"Max",COUNTROWS(FILTER(__Table,[Max]<=EARLIER([Count])))
)
RETURN
FILTER(__Table,[Max]=1)
I couldn't quite make the leap with your logic.
It looks like it's was leveraging a row count vs me wanting to do a summation
I was thinking __Table2 would be a rank but seems like I just need to flag the max somehow and filter.
New Table =
VAR __Table1 = SUMMARIZE('RawTable',[ProdCode],[ProdDescp],"TotQty",SUM(RawTable[Qty]))
VAR __Table2 =
RETURN
__Table1
@briguin Flagging max was the part of the code you apparently didn't implement.
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
28 | |
11 | |
11 | |
10 | |
6 |